From 3e4c18770957b55e2f80da32c3a32caa908f1386 Mon Sep 17 00:00:00 2001 From: "Stone, Avi (as206k)" Date: Wed, 23 May 2018 11:21:11 +0300 Subject: Upgrade dt-be-main Update sources for dcae-dt-be-main to latest version Change-Id: I3d58a2dc32611c0ca90f1c97e1294a17d5748623 Issue-ID: SDC-1359 Signed-off-by: Stone, Avi (as206k) --- .../composition/controller/BaseController.java | 21 +- .../controller/BlueprintController.java | 253 +------ .../controller/CompositionController.java | 582 +++++++-------- .../controller/LifecycleController.java | 46 +- .../controller/RuleEditorController.java | 392 ++-------- .../composition/controller/ServicesController.java | 189 +---- .../composition/controller/VfcmtController.java | 73 +- .../dcae/composition/impl/BaseBusinessLogic.java | 175 ++++- .../composition/impl/BlueprintBusinessLogic.java | 98 +++ .../composition/impl/CompositionBusinessLogic.java | 169 +++++ .../composition/impl/ReferenceBusinessLogic.java | 21 +- .../composition/impl/RuleEditorBusinessLogic.java | 389 ++++++++++ .../composition/impl/ServiceBusinessLogic.java | 194 +++++ .../dcae/composition/impl/VfcmtBusinessLogic.java | 77 +- .../org/onap/sdc/dcae/filter/LoggingFilter.java | 291 ++++---- .../rule/editor/enums/RuleEditorElementType.java | 32 +- .../dcae/rule/editor/impl/RulesBusinessLogic.java | 16 +- .../rule/editor/translators/ActionTranslator.java | 15 + .../editor/translators/ClearActionTranslator.java | 30 + .../translators/ConditionGroupTranslator.java | 6 +- .../editor/translators/ConditionTranslator.java | 2 +- .../editor/translators/CopyActionTranslator.java | 25 +- .../translators/DateFormatterTranslator.java | 15 +- .../translators/FieldConditionTranslator.java | 2 +- .../editor/translators/IRuleElementTranslator.java | 16 +- .../editor/translators/LogEventTranslator.java | 28 + .../rule/editor/translators/LogTextTranslator.java | 33 + .../editor/translators/MapActionTranslator.java | 14 +- .../editor/translators/MappingRulesTranslator.java | 11 +- .../editor/translators/RegexActionTranslator.java | 17 +- .../translators/ReplaceActionTranslator.java | 33 + .../rule/editor/translators/RuleTranslator.java | 11 +- .../rule/editor/validators/ActionValidator.java | 40 - .../editor/validators/ClearActionValidator.java | 27 + .../editor/validators/ConcatActionValidator.java | 6 +- .../editor/validators/CopyActionValidator.java | 40 + .../editor/validators/DateFormatterValidator.java | 2 +- .../editor/validators/IRuleElementValidator.java | 4 + .../rule/editor/validators/LogEventValidator.java | 28 + .../rule/editor/validators/LogTextValidator.java | 28 + .../rule/editor/validators/MapActionValidator.java | 4 +- .../editor/validators/ReplaceActionValidator.java | 37 + .../dcae/rule/editor/validators/RuleValidator.java | 6 +- .../WEB-INF/config/dcae-be/application.properties | 20 +- .../impl/BlueprintBusinessLogicTest.java | 69 ++ .../impl/CompositionBusinessLogicTest.java | 218 ++++++ .../impl/ReferenceBusinessLogicTest.java | 9 +- .../impl/RuleEditorBusinessLogicTest.java | 217 ++++++ .../composition/impl/ServiceBusinessLogicTest.java | 173 +++++ .../composition/impl/VfcmtBusinessLogicTest.java | 73 +- .../onap/sdc/dcae/filter/LoggingFilterTest.java | 119 +++ .../rule/editor/impl/RulesBusinessLogicTest.java | 30 +- .../onap/sdc/dcae/services/GetServicesTest.java | 143 ---- .../java/org/onap/sdc/dcae/catalog/Catalog.java | 631 ++++++---------- .../onap/sdc/dcae/catalog/asdc/ASDCCatalog.java | 235 +++--- .../org/onap/sdc/dcae/catalog/ASDCCatalogTest.java | 14 +- dcaedt_catalog/asdc/pom.xml | 5 + .../java/org/onap/sdc/dcae/catalog/asdc/ASDC.java | 359 ++++----- .../org/onap/sdc/dcae/catalog/asdc/ASDCUtils.java | 820 +++++++++++---------- .../sdc/dcae/catalog/asdc/ASDCUtilsController.java | 48 +- .../onap/sdc/dcae/catalog/asdc/Blueprinter.java | 67 +- .../org/onap/sdc/dcae/catalog/asdc/Cloudify.java | 249 ------- .../java/org/onap/sdc/dcae/client/ISdcClient.java | 41 +- .../org/onap/sdc/dcae/client/SdcRestClient.java | 98 ++- .../java/org/onap/sdc/dcae/enums/AssetType.java | 29 +- .../org/onap/sdc/dcae/errormng/BaseException.java | 98 ++- .../org/onap/sdc/dcae/errormng/OkResponseInfo.java | 2 +- .../onap/sdc/dcae/errormng/PolicyException.java | 3 - .../org/onap/sdc/dcae/errormng/RequestError.java | 24 +- .../onap/sdc/dcae/errormng/ServiceException.java | 5 - .../org/onap/sdc/dcae/utils/NormalizersTest.java | 47 ++ .../dcae/utils/SDCResponseErrorHandlerTest.java | 93 +++ .../org/onap/sdc/dcae/utils/NormalizersTest.java | 51 -- .../org/onap/sdc/dcae/catalog/commons/Futures.java | 16 +- .../org/onap/sdc/dcae/catalog/commons/Proxies.java | 4 - .../org/onap/sdc/dcae/catalog/commons/Proxy.java | 60 +- .../sdc/dcae/catalog/commons/ProxyBuilder.java | 30 +- .../onap/sdc/dcae/catalog/commons/Recycler.java | 20 +- dcaedt_catalog/service/Dockerfile | 19 + .../sdc/dcae/catalog/engine/CatalogController.java | 427 +---------- .../main/java/json/templateInfo/NodeToDelete.java | 30 + .../main/java/json/templateInfo/TemplateInfo.java | 20 + .../src/main/java/tools/DeployTemplate.java | 58 +- dcaedt_tools/src/main/java/tools/ItemAndAlias.java | 20 + dcaedt_tools/src/main/java/tools/LoggerError.java | 5 + dcaedt_tools/src/main/java/tools/Main.java | 6 +- dcaedt_tools/src/main/java/tools/NodeData.java | 12 +- .../src/main/java/tools/TemplateContainer.java | 136 +++- .../src/main/java/utilities/DcaeRestClient.java | 7 + .../src/main/java/utilities/IDcaeRestClient.java | 2 + dcaedt_tools/src/main/resources/conf/config.json | 252 +++++-- dcaedt_tools/src/test/java/BaseTest.java | 14 +- dcaedt_tools/src/test/java/DeployTemplateTest.java | 2 + .../src/test/java/TemplateContainerTest.java | 32 +- dcaedt_validator/Dockerfile | 28 + .../java/org/onap/sdc/dcae/checker/Catalog.java | 722 +++++++++--------- .../java/org/onap/sdc/dcae/checker/Checker.java | 89 +-- .../org/onap/sdc/dcae/checker/CommonLocator.java | 245 +++--- .../java/org/onap/sdc/dcae/checker/Construct.java | 8 +- .../main/java/org/onap/sdc/dcae/checker/Data.java | 234 +++--- .../kwalify/src/main/java/kwalify/Defaultable.java | 4 +- .../src/main/java/kwalify/DefaultableHashMap.java | 9 +- .../kwalify/src/main/java/kwalify/Messages.java | 20 +- .../src/main/java/kwalify/MetaValidator.java | 525 ++++++------- .../src/main/java/kwalify/PlainYamlParser.java | 114 ++- .../kwalify/src/main/java/kwalify/Rule.java | 135 ++-- .../kwalify/src/main/java/kwalify/Validator.java | 1 + .../kwalify/src/main/java/kwalify/YamlParser.java | 2 +- .../cookbooks/Deploy-DCAE/files/default/traststore | Bin 0 -> 4255 bytes .../cookbooks/Deploy-DCAE/files/default/truststore | Bin 4255 -> 0 bytes .../templates/default/dcae-error-configuration.erb | 6 + 111 files changed, 5741 insertions(+), 5061 deletions(-) create mode 100644 dcaedt_be/src/main/java/org/onap/sdc/dcae/composition/impl/BlueprintBusinessLogic.java create mode 100644 dcaedt_be/src/main/java/org/onap/sdc/dcae/composition/impl/CompositionBusinessLogic.java create mode 100644 dcaedt_be/src/main/java/org/onap/sdc/dcae/composition/impl/RuleEditorBusinessLogic.java create mode 100644 dcaedt_be/src/main/java/org/onap/sdc/dcae/composition/impl/ServiceBusinessLogic.java create mode 100644 dcaedt_be/src/main/java/org/onap/sdc/dcae/rule/editor/translators/ActionTranslator.java create mode 100644 dcaedt_be/src/main/java/org/onap/sdc/dcae/rule/editor/translators/ClearActionTranslator.java create mode 100644 dcaedt_be/src/main/java/org/onap/sdc/dcae/rule/editor/translators/LogEventTranslator.java create mode 100644 dcaedt_be/src/main/java/org/onap/sdc/dcae/rule/editor/translators/LogTextTranslator.java create mode 100644 dcaedt_be/src/main/java/org/onap/sdc/dcae/rule/editor/translators/ReplaceActionTranslator.java delete mode 100644 dcaedt_be/src/main/java/org/onap/sdc/dcae/rule/editor/validators/ActionValidator.java create mode 100644 dcaedt_be/src/main/java/org/onap/sdc/dcae/rule/editor/validators/ClearActionValidator.java create mode 100644 dcaedt_be/src/main/java/org/onap/sdc/dcae/rule/editor/validators/CopyActionValidator.java create mode 100644 dcaedt_be/src/main/java/org/onap/sdc/dcae/rule/editor/validators/LogEventValidator.java create mode 100644 dcaedt_be/src/main/java/org/onap/sdc/dcae/rule/editor/validators/LogTextValidator.java create mode 100644 dcaedt_be/src/main/java/org/onap/sdc/dcae/rule/editor/validators/ReplaceActionValidator.java create mode 100644 dcaedt_be/src/test/java/org/onap/sdc/dcae/composition/impl/BlueprintBusinessLogicTest.java create mode 100644 dcaedt_be/src/test/java/org/onap/sdc/dcae/composition/impl/CompositionBusinessLogicTest.java create mode 100644 dcaedt_be/src/test/java/org/onap/sdc/dcae/composition/impl/RuleEditorBusinessLogicTest.java create mode 100644 dcaedt_be/src/test/java/org/onap/sdc/dcae/composition/impl/ServiceBusinessLogicTest.java create mode 100644 dcaedt_be/src/test/java/org/onap/sdc/dcae/filter/LoggingFilterTest.java delete mode 100644 dcaedt_be/src/test/java/org/onap/sdc/dcae/services/GetServicesTest.java delete mode 100644 dcaedt_catalog/asdc/src/main/java/org/onap/sdc/dcae/catalog/asdc/Cloudify.java create mode 100644 dcaedt_catalog/asdc/src/test/java/org/onap/sdc/dcae/utils/NormalizersTest.java create mode 100644 dcaedt_catalog/asdc/src/test/java/org/onap/sdc/dcae/utils/SDCResponseErrorHandlerTest.java delete mode 100644 dcaedt_catalog/asdc/src/test/org/onap/sdc/dcae/utils/NormalizersTest.java create mode 100644 dcaedt_catalog/service/Dockerfile create mode 100644 dcaedt_tools/src/main/java/json/templateInfo/NodeToDelete.java create mode 100644 dcaedt_tools/src/main/java/tools/ItemAndAlias.java create mode 100644 dcaedt_validator/Dockerfile create mode 100644 docker/docker_be/chef-solo/cookbooks/Deploy-DCAE/files/default/traststore delete mode 100644 docker/docker_be/chef-solo/cookbooks/Deploy-DCAE/files/default/truststore diff --git a/dcaedt_be/src/main/java/org/onap/sdc/dcae/composition/controller/BaseController.java b/dcaedt_be/src/main/java/org/onap/sdc/dcae/composition/controller/BaseController.java index 8b590ca..818a30d 100644 --- a/dcaedt_be/src/main/java/org/onap/sdc/dcae/composition/controller/BaseController.java +++ b/dcaedt_be/src/main/java/org/onap/sdc/dcae/composition/controller/BaseController.java @@ -42,12 +42,12 @@ public abstract class BaseController { return request.getAttribute("requestId").toString(); } - Asset checkout(String userId, String uuid, AssetType assetType, String requestId) throws Exception { - return baseBusinessLogic.getSdcRestClient().changeAssetLifecycleState(userId, uuid, LifecycleOperationType.CHECKOUT.name(), null, assetType, requestId); + ResourceDetailed checkoutVfcmt(String userId, String uuid, String requestId) { + return baseBusinessLogic.getSdcRestClient().changeResourceLifecycleState(userId, uuid, LifecycleOperationType.CHECKOUT.name(), null, requestId); } - Asset checkin(String userId, String uuid, AssetType assetType, String requestId) throws Exception { - return baseBusinessLogic.getSdcRestClient().changeAssetLifecycleState(userId, uuid, LifecycleOperationType.CHECKIN.name(), "checking in " + assetType.name() + uuid, assetType, requestId); + ResourceDetailed checkinVfcmt(String userId, String uuid, String requestId) { + return baseBusinessLogic.getSdcRestClient().changeResourceLifecycleState(userId, uuid, LifecycleOperationType.CHECKIN.name(), "checking in vfcmt" + uuid, requestId); } @@ -55,7 +55,7 @@ public abstract class BaseController { return DcaeBeConstants.LifecycleStateEnum.NOT_CERTIFIED_CHECKOUT != DcaeBeConstants.LifecycleStateEnum.findState(lifecycleState); } - void checkUserIfResourceCheckedOut(String userId, Asset asset) throws DcaeException { + void checkUserIfResourceCheckedOut(String userId, Asset asset) { if (DcaeBeConstants.LifecycleStateEnum.NOT_CERTIFIED_CHECKOUT == DcaeBeConstants.LifecycleStateEnum.findState(asset.getLifecycleState())) { String lastUpdaterUserId = asset.getLastUpdaterUserId(); if (lastUpdaterUserId != null && !lastUpdaterUserId.equals(userId)) { @@ -67,7 +67,7 @@ public abstract class BaseController { } void checkVfcmtType(ResourceDetailed vfcmt) { - if (!"VFCMT".equals(vfcmt.getResourceType()) || !"Template".equals(vfcmt.getCategory())) { + if (AssetType.VFCMT != getValidAssetTypeOrNull(vfcmt.getResourceType()) || !"Template".equals(vfcmt.getCategory())) { ResponseFormat responseFormat = ErrConfMgr.INSTANCE.getResponseFormat(ActionStatus.RESOURCE_NOT_VFCMT_ERROR, null, vfcmt.getUuid()); throw new DcaeException(HttpStatus.BAD_REQUEST, responseFormat.getRequestError()); } @@ -77,4 +77,13 @@ public abstract class BaseController { errLogger.log(LogLevel.ERROR, this.getClass().getName(), e.getMessage()); return ErrConfMgr.INSTANCE.handleException(e, apiType, variables); } + + AssetType getValidAssetTypeOrNull(String type) { + try { + return AssetType.getAssetTypeByName(type); + } catch (IllegalArgumentException e) { + debugLogger.log(LogLevel.ERROR, this.getClass().getName(), "invalid asset type: {}. Error: {}", type, e); + return null; + } + } } diff --git a/dcaedt_be/src/main/java/org/onap/sdc/dcae/composition/controller/BlueprintController.java b/dcaedt_be/src/main/java/org/onap/sdc/dcae/composition/controller/BlueprintController.java index a12c6b8..5f4cee7 100644 --- a/dcaedt_be/src/main/java/org/onap/sdc/dcae/composition/controller/BlueprintController.java +++ b/dcaedt_be/src/main/java/org/onap/sdc/dcae/composition/controller/BlueprintController.java @@ -1,239 +1,54 @@ package org.onap.sdc.dcae.composition.controller; -import org.apache.commons.lang.StringUtils; -import org.onap.sdc.common.onaplog.Enums.LogLevel; -import org.onap.sdc.dcae.composition.restmodels.MessageResponse; -import org.onap.sdc.dcae.catalog.asdc.ASDC; -import org.onap.sdc.dcae.catalog.asdc.ASDCUtils; -import org.onap.sdc.dcae.catalog.asdc.Blueprinter; -import org.onap.sdc.dcae.composition.restmodels.sdc.*; -import org.onap.sdc.dcae.utils.Normalizers; -import org.onap.sdc.dcae.composition.util.DcaeBeConstants; -import org.onap.sdc.dcae.enums.ArtifactType; +import org.onap.sdc.dcae.composition.impl.BlueprintBusinessLogic; import org.onap.sdc.dcae.enums.AssetType; -import org.onap.sdc.dcae.enums.LifecycleOperationType; -import org.onap.sdc.dcae.errormng.ActionStatus; -import org.onap.sdc.dcae.errormng.ErrConfMgr; -import org.onap.sdc.dcae.errormng.ErrConfMgr.ApiType; -import org.onap.sdc.dcae.utils.SdcRestClientUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.autoconfigure.EnableAutoConfiguration; -import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; -import org.springframework.util.Base64Utils; -import org.springframework.util.CollectionUtils; import org.springframework.web.bind.annotation.*; import javax.annotation.PostConstruct; -import java.io.StringReader; -import java.net.URI; @RestController @EnableAutoConfiguration @CrossOrigin -public class BlueprintController extends BaseController{ - - @Autowired - private Blueprinter blueprinter; - - @Autowired - private ASDC asdc; - - private static final String CREATE_DESC = "creating new artifact blueprint on the service vfi"; - private static final String UPDATE_DESC = "updating artifact blueprint on the service vfi"; - +public class BlueprintController extends BaseController { + @Autowired + private BlueprintBusinessLogic blueprintBusinessLogic; @PostConstruct public void init(){ - URI sdcUri = URI.create(systemProperties.getProperties().getProperty(DcaeBeConstants.Config.URI)); - asdc.setUri(sdcUri); - debugLogger.log(LogLevel.DEBUG, this.getClass().getName(), "SDC uri: {}", sdcUri); - } - - /*** - * VFCMT - Resource, blueprint - as an artifact as an service. - * @param userId - * @param vfcmtUuid - * @param serviceUuid - * @param serviceInstanceName - * @param monitoringFlowType - * @return ResponseEntity - */ - @RequestMapping(value = "/createBluePrint/{VFCMTUuid}/{serviceUuid}/{instanceName}/{monitoringFlowType}", method = RequestMethod.POST) - public ResponseEntity createBluePrint(@RequestHeader("USER_ID") String userId, - @PathVariable("VFCMTUuid") String vfcmtUuid, - @PathVariable("serviceUuid") String serviceUuid, - @PathVariable("instanceName") String serviceInstanceName, - @PathVariable("monitoringFlowType") String monitoringFlowType, - @ModelAttribute("requestId") String requestId) { - try { - - ResourceDetailed vfcmt = baseBusinessLogic.getSdcRestClient().getResource(vfcmtUuid, requestId); - debugLogger.log(LogLevel.DEBUG, this.getClass().getName(), vfcmt.toString()); - checkVfcmtType(vfcmt); - Artifact cdumpArtifactData = findCdumpArtifactData(vfcmt); - if (null != cdumpArtifactData) { - debugLogger.log(LogLevel.DEBUG, this.getClass().getName(), "Found the cdump (composition.yml) on top of VFCMT {}", vfcmtUuid); - String cdump = baseBusinessLogic.getSdcRestClient().getResourceArtifact(vfcmtUuid, cdumpArtifactData.getArtifactUUID(), requestId); - debugLogger.log(LogLevel.DEBUG, this.getClass().getName(), "---------------------------------------------------------------CDUMP: -----------------------------------------------------------------------------"); - debugLogger.log(LogLevel.DEBUG, this.getClass().getName(), cdump); - debugLogger.log(LogLevel.DEBUG, this.getClass().getName(), "---------------------------------------------------------------------------------------------------------------------------------------------------"); - ASDCUtils utils = new ASDCUtils(asdc, blueprinter); - - debugLogger.log(LogLevel.DEBUG, this.getClass().getName(), "Going to use python procedure to create a blueprint...."); - String resultBlueprintCreation; - try{ - resultBlueprintCreation = utils.buildBlueprintViaToscaLab(new StringReader(cdump)).waitForResult().waitForResult(); - }catch (Exception e){ - return ErrConfMgr.INSTANCE.buildErrorResponse(ActionStatus.GENERATE_BLUEPRINT_ERROR, e.getMessage(), vfcmt.getName()); - } - if (StringUtils.isEmpty(resultBlueprintCreation)) { - return ErrConfMgr.INSTANCE.buildErrorResponse(ActionStatus.GENERATE_BLUEPRINT_ERROR, "", vfcmt.getName()); - } - - // 1806 US374595 flowType in cdump - String flowTypeFromCdump = StringUtils.substringBetween(cdump,"\"flowType\":\"","\""); - if(StringUtils.isNotBlank(flowTypeFromCdump)) { - monitoringFlowType = flowTypeFromCdump; - } - // saving to serviceVfInstance - Artifact savedBluePrint = saveBluePrint(userId, serviceUuid, serviceInstanceName, resultBlueprintCreation, monitoringFlowType, vfcmt.getName(), requestId); - if(savedBluePrint!=null){ - MessageResponse response = new MessageResponse(); - response.setSuccessResponse("Blueprint build complete \n. Blueprint="+savedBluePrint.getArtifactName()); - //1806 US374593 - certify VFCMT after BP generation - certifyVfcmt(vfcmt, requestId); - return new ResponseEntity<>(response, HttpStatus.OK); - } - else{ - return ErrConfMgr.INSTANCE.buildErrorResponse(ActionStatus.SUBMIT_BLUEPRINT_ERROR); - } - - }else{ - return ErrConfMgr.INSTANCE.buildErrorResponse(ActionStatus.MISSING_TOSCA_FILE, "", vfcmt.getName()); - } - } catch (Exception e) { - return handleException(e, ApiType.SUBMIT_BLUEPRINT); - } - } - - - /********************* private function ********************/ - - /** - * @param userId - * @param serviceUuid - * @param resourceInstanceName - * @param bluePrint - * @param monitoringFlowType - * @param vfcmtName - * @param requestId - * @return - * @throws Exception - */ - private Artifact saveBluePrint(String userId, String serviceUuid, String resourceInstanceName, String bluePrint, String monitoringFlowType, String vfcmtName, String requestId) throws Exception { - - debugLogger.log(LogLevel.DEBUG, this.getClass().getName(), "BLUEPRINT:\n{}", bluePrint); - try { - ServiceDetailed service = baseBusinessLogic.getSdcRestClient().getService(serviceUuid, requestId); - //Validations - checkUserIfResourceCheckedOut(userId, service); - ResourceInstance vfi = findVfiOnService(service, resourceInstanceName); - if(null == vfi){ - debugLogger.log(LogLevel.DEBUG, this.getClass().getName(), "VF instance {} not found on service {}", resourceInstanceName, serviceUuid); - return null; - } - - debugLogger.log(LogLevel.DEBUG, this.getClass().getName(), service.toString()); - - String normalizedArtifactLabel = Normalizers.normalizeArtifactLabel("blueprint-" + monitoringFlowType); - Artifact blueprintArtifact = CollectionUtils.isEmpty(vfi.getArtifacts()) ? null : vfi.getArtifacts().stream() - .filter(p -> normalizedArtifactLabel.equals(Normalizers.normalizeArtifactLabel(p.getArtifactLabel()))) - .findAny() - .orElse(null); - - boolean isNeed2Checkout = isNeedToCheckOut(service.getLifecycleState()); - if (isNeed2Checkout) { - Asset result = checkout(userId, serviceUuid, AssetType.SERVICE, requestId); - if (result != null) { - serviceUuid = result.getUuid(); - debugLogger.log(LogLevel.DEBUG, this.getClass().getName(), "New service after checkout is: {}", serviceUuid); - } - } - //update mode - if (null != blueprintArtifact) { - debugLogger.log(LogLevel.DEBUG, this.getClass().getName(), "Found that service {} already consist of {} ----> updateMode", serviceUuid, normalizedArtifactLabel); - blueprintArtifact.setDescription(UPDATE_DESC); - blueprintArtifact.setPayloadData(Base64Utils.encodeToString(bluePrint.getBytes())); - blueprintArtifact = baseBusinessLogic.getSdcRestClient().updateVfInstanceArtifact(userId, serviceUuid, Normalizers.normalizeComponentInstanceName(resourceInstanceName), blueprintArtifact, requestId); - //create mode - } else { - debugLogger.log(LogLevel.DEBUG, this.getClass().getName(), "Service {} does not consist {} ----> createMode", serviceUuid, normalizedArtifactLabel); - blueprintArtifact = SdcRestClientUtils.generateDeploymentArtifact(CREATE_DESC, generateBlueprintFileName(monitoringFlowType, vfcmtName), ArtifactType.DCAE_INVENTORY_BLUEPRINT.name(), normalizedArtifactLabel, bluePrint.getBytes()); - blueprintArtifact = baseBusinessLogic.getSdcRestClient().createVfInstanceArtifact(userId, serviceUuid, Normalizers.normalizeComponentInstanceName(resourceInstanceName), blueprintArtifact, requestId); - } - - //No need to check the service in in 1806 -// Asset blueprintAsJson = checkin(user_id, serviceUuid, AssetType.SERVICE); -// debugLogger.log(LogLevel.DEBUG, this.getClass().getName(), "service result after check-in: {}", blueprintAsJson.toString()); - - return blueprintArtifact; - - } catch (Exception e) { - errLogger.log(LogLevel.ERROR, this.getClass().getName(), "Error occurred while trying to save blueprint {}", e.toString()); - throw e; - } - } - - /** - * - * @param monitoringFlowType - * @param vfcmtName - * @return - */ - private String generateBlueprintFileName(String monitoringFlowType, String vfcmtName) { - StringBuffer sb = new StringBuffer(); - sb.append(monitoringFlowType); - sb.append("."); - sb.append(Normalizers.normalizeComponentName(vfcmtName)); - sb.append("."); - sb.append(DcaeBeConstants.Composition.fileNames.EVENT_PROC_BP_YAML); - return sb.toString(); - } - - private ResourceInstance findVfiOnService(ServiceDetailed service, String vfiName) { - return null == service ? null : CollectionUtils.isEmpty(service.getResources()) ? null : service.getResources().stream().filter(p -> vfiName.equals(p.getResourceInstanceName())).findAny().orElse(null); - } - - private Artifact findCdumpArtifactData(ResourceDetailed vfcmt) { - return null == vfcmt ? null : CollectionUtils.isEmpty(vfcmt.getArtifacts()) ? null : vfcmt.getArtifacts().stream() - .filter(p -> DcaeBeConstants.Composition.fileNames.COMPOSITION_YML.equals(p.getArtifactName())).findAny().orElse(null); - } - - private void certifyVfcmt(ResourceDetailed vfcmt, String requestId){ - String state = vfcmt.getLifecycleState(); - if(null == state) { - debugLogger.log(LogLevel.ERROR, this.getClass().getName(), "Couldn't read Vfcmt lifecycle state"); - return; - } - DcaeBeConstants.LifecycleStateEnum lifeCycleState = DcaeBeConstants.LifecycleStateEnum.findState(state); - if(null == lifeCycleState) { - debugLogger.log(LogLevel.ERROR, this.getClass().getName(), "Undefined lifecycle state: {}", state); - return; - } - try{ - switch (lifeCycleState){ - case NOT_CERTIFIED_CHECKOUT: - baseBusinessLogic.getSdcRestClient().changeResourceLifecycleState(vfcmt.getLastUpdaterUserId(), vfcmt.getUuid(), LifecycleOperationType.CHECKIN.name(), "check in VFCMT after blueprint successful submission", requestId); - case NOT_CERTIFIED_CHECKIN: - baseBusinessLogic.getSdcRestClient().changeResourceLifecycleState(vfcmt.getLastUpdaterUserId(), vfcmt.getUuid(), LifecycleOperationType.CERTIFY.name(), "certify VFCMT after blueprint successful submission", requestId); - } - } - catch (Exception e){ - //informative only. no message to user (TBA) - debugLogger.log(LogLevel.ERROR, this.getClass().getName(), "Error occurred during vfcmt lifecycle operation: {}", e.toString()); - } } + /*** + * VFCMT - Resource, blueprint - as an artifact as an service. + * @param context + * @param userId + * @param vfcmtUuid + * @param serviceUuid + * @param instanceName + * @param requestId + * @return ResponseEntity + */ + @RequestMapping(value = "{context}/createBluePrint/{VFCMTUuid}/{serviceUuid}/{instanceName}", method = RequestMethod.POST) + public ResponseEntity createBlueprint(@RequestHeader("USER_ID") String userId, + @PathVariable String context, + @PathVariable("VFCMTUuid") String vfcmtUuid, + @PathVariable("serviceUuid") String serviceUuid, + @PathVariable("instanceName") String instanceName, + @ModelAttribute("requestId") String requestId) { + return blueprintBusinessLogic.generateAndSaveBlueprint(userId, context, vfcmtUuid, serviceUuid, instanceName, "", requestId); + } + + @Deprecated + @RequestMapping(value = "/createBluePrint/{VFCMTUuid}/{serviceUuid}/{instanceName}/{monitoringFlowType}", method = RequestMethod.POST) + public ResponseEntity createBluePrintWithFlowType(@RequestHeader("USER_ID") String userId, + @PathVariable("VFCMTUuid") String vfcmtUuid, + @PathVariable("serviceUuid") String serviceUuid, + @PathVariable("instanceName") String serviceInstanceName, + @PathVariable("monitoringFlowType") String monitoringFlowType, + @ModelAttribute("requestId") String requestId) { + return blueprintBusinessLogic.generateAndSaveBlueprint(userId, AssetType.SERVICE.name(), vfcmtUuid, serviceUuid, serviceInstanceName, monitoringFlowType, requestId); + } } diff --git a/dcaedt_be/src/main/java/org/onap/sdc/dcae/composition/controller/CompositionController.java b/dcaedt_be/src/main/java/org/onap/sdc/dcae/composition/controller/CompositionController.java index 5cba14f..3261ddc 100644 --- a/dcaedt_be/src/main/java/org/onap/sdc/dcae/composition/controller/CompositionController.java +++ b/dcaedt_be/src/main/java/org/onap/sdc/dcae/composition/controller/CompositionController.java @@ -3,7 +3,9 @@ package org.onap.sdc.dcae.composition.controller; import org.json.JSONArray; import org.json.JSONException; import org.onap.sdc.common.onaplog.Enums.LogLevel; +import org.onap.sdc.dcae.composition.impl.CompositionBusinessLogic; import org.onap.sdc.dcae.composition.restmodels.MessageResponse; +import org.onap.sdc.dcae.composition.restmodels.ReferenceUUID; import org.onap.sdc.dcae.composition.restmodels.sdc.Artifact; import org.onap.sdc.dcae.composition.restmodels.sdc.Asset; import org.onap.sdc.dcae.composition.restmodels.sdc.ResourceDetailed; @@ -11,17 +13,14 @@ import org.onap.sdc.dcae.catalog.Catalog; import org.onap.sdc.dcae.catalog.Catalog.*; import org.onap.sdc.dcae.catalog.engine.*; import org.onap.sdc.dcae.composition.util.DcaeBeConstants; -import org.onap.sdc.dcae.enums.ArtifactType; import org.onap.sdc.dcae.enums.LifecycleOperationType; import org.onap.sdc.dcae.errormng.ActionStatus; import org.onap.sdc.dcae.errormng.ErrConfMgr; import org.onap.sdc.dcae.errormng.ErrConfMgr.ApiType; -import org.onap.sdc.dcae.utils.SdcRestClientUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.autoconfigure.EnableAutoConfiguration; import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; -import org.springframework.util.Base64Utils; import org.springframework.util.CollectionUtils; import org.springframework.web.bind.annotation.*; import org.springframework.web.context.request.async.DeferredResult; @@ -37,302 +36,281 @@ import java.util.stream.Collectors; @RestController @EnableAutoConfiguration @CrossOrigin -public class CompositionController extends BaseController{ - - @Autowired - private CatalogController catalogController; - - @PostConstruct - public void init() { - catalogController.setDefaultCatalog(URI.create(systemProperties.getProperties().getProperty(DcaeBeConstants.Config.ASDC_CATALOG_URL))); - } - - @RequestMapping(value = { "/utils/clone/{assetType}/{sourceId}/{targetId}" }, method = {RequestMethod.GET }, produces = { "application/json" }) - public ResponseEntity clone(@RequestHeader("USER_ID") String userId, @PathVariable("assetType") String theAssetType, @PathVariable("sourceId") String theSourceId, @PathVariable("targetId") String theTargetId, - @ModelAttribute("requestId") String requestId) { - MessageResponse response = new MessageResponse(); - - try { - // fetch the source and assert it is a vfcmt containing clone worthy artifacts (composition + rules) - ResourceDetailed sourceVfcmt = baseBusinessLogic.getSdcRestClient().getResource(theSourceId, requestId); - checkVfcmtType(sourceVfcmt); - List artifactsToClone = CollectionUtils.isEmpty(sourceVfcmt.getArtifacts()) ? null : sourceVfcmt.getArtifacts().stream() - .filter(p -> DcaeBeConstants.Composition.fileNames.COMPOSITION_YML.equals(p.getArtifactName()) || p.getArtifactName().endsWith(DcaeBeConstants.Composition.fileNames.MAPPING_RULE_POSTFIX)) - .collect(Collectors.toList()); - if(CollectionUtils.isEmpty(artifactsToClone)) { - response.setSuccessResponse("Nothing to clone"); - return new ResponseEntity<>(response ,HttpStatus.NO_CONTENT); - } - - // fetch the target - ResourceDetailed vfcmt = baseBusinessLogic.getSdcRestClient().getResource(theTargetId, requestId); - debugLogger.log(LogLevel.DEBUG, this.getClass().getName(), vfcmt.toString()); - checkVfcmtType(vfcmt); - checkUserIfResourceCheckedOut(userId, vfcmt); - boolean isTargetNeed2Checkout = isNeedToCheckOut(vfcmt.getLifecycleState()); - if (isTargetNeed2Checkout) { - ResourceDetailed targetVfcmt = baseBusinessLogic.getSdcRestClient().changeResourceLifecycleState(userId, theTargetId, LifecycleOperationType.CHECKOUT.name(), "checking out VFCMT before clone", requestId); - if(null == targetVfcmt){ - return ErrConfMgr.INSTANCE.buildErrorResponse(ActionStatus.GENERAL_ERROR); - } - theTargetId = targetVfcmt.getUuid(); - debugLogger.log(LogLevel.DEBUG, this.getClass().getName(), "New targetVfcmt (for artifact clone) after checkout is: {}", theTargetId); - } - - Map currentArtifacts = CollectionUtils.isEmpty(vfcmt.getArtifacts()) ? new HashMap<>() : vfcmt.getArtifacts().stream() - .collect(Collectors.toMap(Artifact::getArtifactName, Function.identity())); - - //TODO target VFCMT rule artifacts should be removed - for(Artifact artifactToClone : artifactsToClone) { - String payload = baseBusinessLogic.getSdcRestClient().getResourceArtifact(theSourceId, artifactToClone.getArtifactUUID(), requestId); - baseBusinessLogic.cloneArtifactToTarget(userId, theTargetId, payload, artifactToClone, currentArtifacts.get(artifactToClone.getArtifactName()), requestId); - } - - baseBusinessLogic.getSdcRestClient().changeResourceLifecycleState(userId, theTargetId, LifecycleOperationType.CHECKIN.name(), "check in VFCMT after clone", requestId); - debugLogger.log(LogLevel.DEBUG, this.getClass().getName(), "Cloning {} from {} has finished successfully", theSourceId, theTargetId); - response.setSuccessResponse("Clone VFCMT complete"); - return new ResponseEntity<>(response, HttpStatus.OK); - } catch (Exception e) { - return handleException(e, ApiType.CLONE_VFCMT); - } - } - - @RequestMapping(value = "/elements", method = { RequestMethod.POST, RequestMethod.GET }, produces = "application/json") - public DeferredResult items(@RequestBody(required = false) ItemsRequest theRequest) { - - final ItemsRequest request = (theRequest == null) ? ItemsRequest.EMPTY_REQUEST : theRequest; - - Catalog catalog = catalogController.getCatalog(request.getCatalog()); - DeferredResult result = new DeferredResult(request.getTimeout()); - - catalog.rootsByLabel(request.getStartingLabel()) - .setHandler(catalogController.new CatalogHandler(request, result) { - public CatalogResponse handleData(Folders theFolders) { - JSONArray ja = new JSONArray(); - if (theFolders != null) { - for (Folder folder : theFolders) { - ja.put(catalogController.patchData(catalog, folder.data())); - } - } - CatalogResponse response = new CatalogResponse(this.request); - try { - response.data().put("elements", ja); - } catch (JSONException e) { - errLogger.log(LogLevel.ERROR, this.getClass().getName(), "JSONException putting json elements to response {}", e); - } - return response; - } - }); - return result; - } - - @RequestMapping(value = "/{theItemId}/elements", method = { RequestMethod.POST, RequestMethod.GET }, produces = "application/json") - public DeferredResult items(@RequestBody(required = false) ItemsRequest theRequest, @PathVariable String theItemId) { - - final ItemsRequest request = (theRequest == null) ? ItemsRequest.EMPTY_REQUEST : theRequest; - - Catalog catalog = catalogController.getCatalog(request.getCatalog()); - DeferredResult result = new DeferredResult(request.getTimeout()); - - catalog - // .fetchFolderByItemId(theItemId) - .folder(theItemId).withParts().withPartAnnotations().withItems().withItemAnnotations().withItemModels() - .execute().setHandler(catalogController.new CatalogHandler(request, result) { - public CatalogResponse handleData(Folder theFolder) { - CatalogResponse response = new CatalogResponse(this.request); - if (theFolder == null) { - return response; - } - - try { - Elements folders = theFolder.elements("parts", Folders.class); - if (folders != null) { - for (Object folder : folders) { - catalogController.patchData(catalog, ((Element) folder).data()); - // lots of ephemere proxies created here .. - Elements annotations = ((Element) folder).elements("annotations", - Annotations.class); - if (annotations != null) { - for (Object a : annotations) { - catalogController.patchData(catalog, ((Annotation) a).data()); - } - } - } - } - Elements items = theFolder.elements("items", Items.class); - if (items != null) { - for (Object i : items) { - catalogController.patchData(catalog, ((Element) i).data()); - // lots of ephemere proxies created here .. - Elements annotations = ((Element) i).elements("annotations", Annotations.class); - if (annotations != null) { - for (Object a : annotations) { - catalogController.patchData(catalog, ((Annotation) a).data()); - } - } - } - } - } catch (Exception x) { - errLogger.log(LogLevel.ERROR, this.getClass().getName(), "Exception processing catalog {}", x); - return new CatalogError(this.request, "", x); - } - - try { - response.data().put("element", theFolder.data()); - } catch (JSONException e) { - errLogger.log(LogLevel.ERROR, this.getClass().getName(), "JSONException putting element to response {}", e); - } - return response; - } - }); - - return result; - } - - @RequestMapping(value = "/{theItemId}/model", method = { RequestMethod.POST,RequestMethod.GET }, produces = "application/json") - public DeferredResult model(@RequestBody(required = false) ElementRequest theRequest, - @PathVariable String theItemId) { - final ElementRequest request = (theRequest == null) ? ElementRequest.EMPTY_REQUEST : theRequest; - - Catalog catalog = catalogController.getCatalog(request.getCatalog()); - DeferredResult result = new DeferredResult<>(request.getTimeout()); - - catalog - .item(theItemId).withModels().execute() - .setHandler(catalogController.new CatalogHandler(request, result) { - public CatalogResponse handleData(Item theItem) { - if (theItem == null) { - return new CatalogError(this.request, "No such item"); - } - Templates models = null; - try { - models = (Templates) theItem.elements("models", Templates.class); - if (models == null || models.isEmpty()) { - return new CatalogError(this.request, "Item has no models"); - } - if (models.size() > 1) { - return new CatalogError(this.request, "Item has more than one model !?"); - } - catalog.template(models.get(0).id()).withInputs().withOutputs().withNodes() - .withNodeProperties().withNodePropertiesAssignments().withNodeRequirements() - .withNodeCapabilities().withNodeCapabilityProperties() - .withNodeCapabilityPropertyAssignments().withPolicies().withPolicyProperties() - .withPolicyPropertiesAssignments().execute().setHandler( - catalogController.new CatalogHandler