diff options
Diffstat (limited to 'dcaedt_tools/src/main')
-rw-r--r-- | dcaedt_tools/src/main/java/tools/DeployTemplate.java | 115 | ||||
-rw-r--r-- | dcaedt_tools/src/main/java/utilities/DcaeRestClient.java | 2 |
2 files changed, 60 insertions, 57 deletions
diff --git a/dcaedt_tools/src/main/java/tools/DeployTemplate.java b/dcaedt_tools/src/main/java/tools/DeployTemplate.java index 4b222e6..f6512b6 100644 --- a/dcaedt_tools/src/main/java/tools/DeployTemplate.java +++ b/dcaedt_tools/src/main/java/tools/DeployTemplate.java @@ -3,13 +3,14 @@ * SDC * ================================================================================ * Copyright (C) 2019 AT&T Intellectual Property. All rights reserved. + * Modifications Copyright (c) 2019 Samsung * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at - * + * * http://www.apache.org/licenses/LICENSE-2.0 - * + * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. @@ -19,23 +20,25 @@ */ package tools; -import com.google.gson.JsonObject; -import json.templateInfo.TemplateInfo; -import org.onap.sdc.dcae.composition.restmodels.CreateVFCMTRequest; -import org.onap.sdc.dcae.composition.restmodels.sdc.ResourceDetailed; -import org.onap.sdc.dcae.composition.util.DcaeBeConstants; -import org.springframework.web.client.HttpServerErrorException; -import utilities.IDcaeRestClient; -import utilities.IReport; import java.util.ArrayList; import java.util.List; import java.util.Map; import java.util.concurrent.atomic.AtomicInteger; +import org.onap.sdc.dcae.composition.restmodels.CreateVFCMTRequest; +import org.onap.sdc.dcae.composition.restmodels.sdc.ResourceDetailed; +import org.onap.sdc.dcae.composition.util.DcaeBeConstants; + +import com.google.gson.JsonObject; + +import json.templateInfo.TemplateInfo; +import utilities.IDcaeRestClient; +import utilities.IReport; public class DeployTemplate { private static final String FAILED_UPDATE_VFCMT = "Failed update vfcmt: "; + private static final String FAILED_CREATE_VFCMT = "Failed create vfcmt: "; private static final String FAILED = "failed"; private final IReport report; private final IDcaeRestClient dcaeRestClient; @@ -49,25 +52,19 @@ public class DeployTemplate { } public void deploy(Map<TemplateInfo, JsonObject> templateInfoToJsonObjectMap) { - ArrayList<ResourceDetailed> vfcmtList = new ArrayList<>(); - List<ResourceDetailed> regularVfcmtList = dcaeRestClient.getAllVfcmts(); - if (regularVfcmtList != null) { - vfcmtList.addAll(regularVfcmtList); - } - List<ResourceDetailed> baseVfcmtList = dcaeRestClient.getAllBaseVfcmts(); - if (baseVfcmtList != null) { - vfcmtList.addAll(baseVfcmtList); - } + ArrayList<ResourceDetailed> vfcmtList = getVfcmtList(); List<TemplateInfo> updatedTemplateInfos = new ArrayList<>(); - vfcmtList.forEach(vfcmt -> - templateInfoToJsonObjectMap.keySet().stream().filter(templateInfo -> templateInfo.getName().equalsIgnoreCase(vfcmt.getName())).forEach(templateInfo -> { - update(vfcmt, templateInfo, templateInfoToJsonObjectMap.get(templateInfo)); - updatedTemplateInfos.add(templateInfo); - })); + vfcmtList.forEach(vfcmt -> templateInfoToJsonObjectMap.keySet().stream() + .filter(templateInfo -> templateInfo.getName().equalsIgnoreCase(vfcmt.getName())) + .forEach(templateInfo -> { + update(vfcmt, templateInfo, templateInfoToJsonObjectMap.get(templateInfo)); + updatedTemplateInfos.add(templateInfo); + })); templateInfoToJsonObjectMap.keySet().stream() - .filter(templateInfo -> !updatedTemplateInfos.contains(templateInfo)) - .forEach(templateInfo -> createNew(templateInfo, templateInfoToJsonObjectMap.get(templateInfo))); + .filter(templateInfo -> !updatedTemplateInfos.contains(templateInfo)) + .forEach(templateInfo -> createNew(templateInfo, + templateInfoToJsonObjectMap.get(templateInfo))); verify(templateInfoToJsonObjectMap); } @@ -75,26 +72,18 @@ public class DeployTemplate { private void verify(Map<TemplateInfo, JsonObject> templateInfoToJsonObjectMap) { AtomicInteger foundCount = new AtomicInteger(); debugLogger.log("Starting verify deployment"); - ArrayList<ResourceDetailed> vfcmtList = new ArrayList<>(); - List<ResourceDetailed> regularVfcmtList = dcaeRestClient.getAllVfcmts(); - if (regularVfcmtList != null) { - vfcmtList.addAll(regularVfcmtList); - } - List<ResourceDetailed> baseVfcmtList = dcaeRestClient.getAllBaseVfcmts(); - if (baseVfcmtList != null) { - vfcmtList.addAll(baseVfcmtList); - } + ArrayList<ResourceDetailed> vfcmtList = getVfcmtList(); templateInfoToJsonObjectMap.keySet() - .forEach(templateInfo -> vfcmtList.stream() - .filter(vfcmt -> vfcmt.getName().equalsIgnoreCase(templateInfo.getName())) - .forEach(vfcmt -> foundCount.getAndIncrement())); + .forEach(templateInfo -> vfcmtList.stream() + .filter(vfcmt -> vfcmt.getName().equalsIgnoreCase(templateInfo.getName())) + .forEach(vfcmt -> foundCount.getAndIncrement())); if (foundCount.get() == templateInfoToJsonObjectMap.size()) { debugLogger.log("Deployment verify finished successfully"); } else { - errLogger.log("Deployment verify finished successfully"); - String msg = "Deployment verify finished with errors, found only: " + - foundCount.get() + " of " + templateInfoToJsonObjectMap.size() + " vfcmts"; + errLogger.log("Deployment verify finished unsuccessfully"); + String msg = "Deployment verify finished with errors, found only: " + foundCount.get() + + " of " + templateInfoToJsonObjectMap.size() + " vfcmts"; report.addErrorMessage(msg); errLogger.log(msg); } @@ -112,7 +101,7 @@ public class DeployTemplate { saveAndCertify(jsonObject, vfcmt); } catch (Exception e) { - String msg = FAILED_UPDATE_VFCMT + templateInfo.getName() + ", With general message: " + e.getMessage(); + String msg = FAILED_CREATE_VFCMT + templateInfo.getName() + ", With general message: " + e.getMessage(); report.addErrorMessage(msg); errLogger.log(msg + " " + e); report.setStatusCode(2); @@ -120,23 +109,22 @@ public class DeployTemplate { } private void update(ResourceDetailed vfcmt, TemplateInfo templateInfo, JsonObject jsonObject) { - ResourceDetailed checkedoutVfcmt = vfcmt; try { boolean vfcmtIsCheckedOut = isCheckedOut(vfcmt); - if (vfcmtIsCheckedOut && differentUserCannotCheckout(dcaeRestClient.getUserId(), vfcmt)){ + if (vfcmtIsCheckedOut&& differentUserCannotCheckout(dcaeRestClient.getUserId(), vfcmt)) { report.addErrorMessage(FAILED_UPDATE_VFCMT + vfcmt.getName() + ", cannot checkout vfcmt"); return; } if (templateInfo.getUpdateIfExist()) { if (!vfcmtIsCheckedOut) { - checkedoutVfcmt = dcaeRestClient.checkoutVfcmt(vfcmt.getUuid()); + vfcmt = dcaeRestClient.checkoutVfcmt(vfcmt.getUuid()); } - if (checkedoutVfcmt != null) { - checkedoutVfcmt.setSubCategory(templateInfo.getSubCategory()); - checkedoutVfcmt.setCategory(templateInfo.getCategory()); - checkedoutVfcmt.setDescription(templateInfo.getDescription()); - dcaeRestClient.updateResource(checkedoutVfcmt); - saveAndCertify(jsonObject, checkedoutVfcmt); + if (vfcmt != null) { + vfcmt.setSubCategory(templateInfo.getSubCategory()); + vfcmt.setCategory(templateInfo.getCategory()); + vfcmt.setDescription(templateInfo.getDescription()); + dcaeRestClient.updateResource(vfcmt); + saveAndCertify(jsonObject, vfcmt); } } else { report.addNotUpdatedMessage("vfcmt: " + vfcmt.getName() + " found, but didn't update."); @@ -144,13 +132,13 @@ public class DeployTemplate { } catch (Exception e) { String msg = FAILED_UPDATE_VFCMT + vfcmt.getName() + ", With general message: " + e.getMessage(); report.addErrorMessage(msg); - errLogger.log( msg + " " + e); - report.setStatusCode(2); + errLogger.log(msg + " " + e); + report.setStatusCode(2); } } private void saveAndCertify(JsonObject jsonObject, ResourceDetailed checkedoutVfcmt) { - jsonObject.addProperty("cid", checkedoutVfcmt.getUuid()); + jsonObject.addProperty("cid", checkedoutVfcmt.getUuid()); if (saveCompositionAndCertify(checkedoutVfcmt, jsonObject)) { report.addUpdatedMessage("vfcmt: " + checkedoutVfcmt.getName() + " updated successfully"); } else { @@ -178,13 +166,15 @@ public class DeployTemplate { } private boolean isCheckedOut(ResourceDetailed asset) { - return DcaeBeConstants.LifecycleStateEnum.NOT_CERTIFIED_CHECKOUT == DcaeBeConstants.LifecycleStateEnum.findState(asset.getLifecycleState()); + return DcaeBeConstants.LifecycleStateEnum.NOT_CERTIFIED_CHECKOUT == DcaeBeConstants.LifecycleStateEnum + .findState(asset.getLifecycleState()); } private Boolean differentUserCannotCheckout(String userId, ResourceDetailed asset) { String lastUpdaterUserId = asset.getLastUpdaterUserId(); if (lastUpdaterUserId != null && !lastUpdaterUserId.equals(userId)) { - String msg = "User conflicts. Operation not allowed for user "+userId+" on resource checked out by "+lastUpdaterUserId; + String msg = "User conflicts. Operation not allowed for user " + userId + + " on resource checked out by " + lastUpdaterUserId; report.addErrorMessage(msg); errLogger.log(msg); return true; @@ -192,4 +182,17 @@ public class DeployTemplate { return false; } } + + private ArrayList<ResourceDetailed> getVfcmtList() { + ArrayList<ResourceDetailed> vfcmtList = new ArrayList<>(); + List<ResourceDetailed> regularVfcmtList = dcaeRestClient.getAllVfcmts(); + if (regularVfcmtList != null) { + vfcmtList.addAll(regularVfcmtList); + } + List<ResourceDetailed> baseVfcmtList = dcaeRestClient.getAllBaseVfcmts(); + if (baseVfcmtList != null) { + vfcmtList.addAll(baseVfcmtList); + } + return vfcmtList; + } } diff --git a/dcaedt_tools/src/main/java/utilities/DcaeRestClient.java b/dcaedt_tools/src/main/java/utilities/DcaeRestClient.java index 566fb1e..f786671 100644 --- a/dcaedt_tools/src/main/java/utilities/DcaeRestClient.java +++ b/dcaedt_tools/src/main/java/utilities/DcaeRestClient.java @@ -167,7 +167,7 @@ public class DcaeRestClient implements IDcaeRestClient { } private String buildRequestPath(String... args){ - String url = uri + Stream.of(args).collect(Collectors.joining()); + String url = uri + String.join("", args); debugLogger.log("Sending request: " + url); return url; } |