From db8e8d530dd37d395ac060f0900330ed67b068d8 Mon Sep 17 00:00:00 2001 From: "Determe, Sebastien (sd378r)" Date: Thu, 22 Mar 2018 09:17:35 +0100 Subject: Add properties to model Add properties to model created in db + Auto start configuration for spring Issue-ID: CLAMP-81 Change-Id: I6598872c6b47963e97c63730a4b6499e2b1a2de2 Signed-off-by: Determe, Sebastien (sd378r) --- .../config/sdc/SdcControllersConfiguration.java | 2 - .../spring/CldsSdcControllerConfiguration.java | 92 ++++++++++++++++++++++ .../clds/sdc/controller/SdcSingleController.java | 12 ++- .../controller/installer/CsarInstallerImpl.java | 35 +++++--- src/main/resources/application.properties | 2 +- 5 files changed, 126 insertions(+), 17 deletions(-) create mode 100644 src/main/java/org/onap/clamp/clds/config/spring/CldsSdcControllerConfiguration.java (limited to 'src/main') diff --git a/src/main/java/org/onap/clamp/clds/config/sdc/SdcControllersConfiguration.java b/src/main/java/org/onap/clamp/clds/config/sdc/SdcControllersConfiguration.java index f1a961840..f5c658cf8 100644 --- a/src/main/java/org/onap/clamp/clds/config/sdc/SdcControllersConfiguration.java +++ b/src/main/java/org/onap/clamp/clds/config/sdc/SdcControllersConfiguration.java @@ -39,14 +39,12 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Value; import org.springframework.context.ApplicationContext; import org.springframework.core.io.Resource; -import org.springframework.stereotype.Component; /** * This class maps the SDC config JSON file. This JSON can have multiple * sdc-controller config. So the json is loaded in a static way and the instance * must specify the controller name that it represents. */ -@Component public class SdcControllersConfiguration { private static final EELFLogger logger = EELFManager.getInstance().getLogger(SdcControllersConfiguration.class); diff --git a/src/main/java/org/onap/clamp/clds/config/spring/CldsSdcControllerConfiguration.java b/src/main/java/org/onap/clamp/clds/config/spring/CldsSdcControllerConfiguration.java new file mode 100644 index 000000000..cdba29ae1 --- /dev/null +++ b/src/main/java/org/onap/clamp/clds/config/spring/CldsSdcControllerConfiguration.java @@ -0,0 +1,92 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP CLAMP + * ================================================================================ + * Copyright (C) 2017-2018 AT&T Intellectual Property. All rights + * reserved. + * ================================================================================ + * 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. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END============================================ + * =================================================================== + * ECOMP is a trademark and service mark of AT&T Intellectual Property. + */ + +package org.onap.clamp.clds.config.spring; + +import com.att.eelf.configuration.EELFLogger; +import com.att.eelf.configuration.EELFManager; + +import java.util.ArrayList; +import java.util.List; + +import javax.annotation.PostConstruct; +import javax.annotation.PreDestroy; + +import org.onap.clamp.clds.config.sdc.SdcControllersConfiguration; +import org.onap.clamp.clds.config.sdc.SdcSingleControllerConfiguration; +import org.onap.clamp.clds.exception.sdc.controller.SdcControllerException; +import org.onap.clamp.clds.sdc.controller.SdcSingleController; +import org.onap.clamp.clds.sdc.controller.installer.CsarInstaller; +import org.onap.clamp.clds.sdc.controller.installer.CsarInstallerImpl; +import org.springframework.beans.factory.annotation.Qualifier; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import org.springframework.context.annotation.Profile; + +@Configuration +@Profile("clamp-sdc-controller") +public class CldsSdcControllerConfiguration { + + private static final EELFLogger logger = EELFManager.getInstance().getLogger(CldsSdcControllerConfiguration.class); + private List sdcControllersList = new ArrayList<>(); + + @PostConstruct + public void loadSdcControllers( + @Qualifier("sdcControllersConfiguration") SdcControllersConfiguration sdcControllersConfig) { + sdcControllersConfig.getAllDefinedControllers().forEach((k, v) -> { + SdcSingleController sdcController = getSdcSingleController(v); + try { + sdcController.initSdc(); + } catch (SdcControllerException e) { + logger.error("Exception caught during initialization of sdc controller", e); + } + sdcControllersList.add(getSdcSingleController(v)); + }); + } + + @PreDestroy + public void killSdcControllers() { + sdcControllersList.forEach(e -> { + try { + e.closeSdc(); + } catch (SdcControllerException e1) { + logger.error("Exception caught during initialization of sdc controller", e); + } + }); + } + + @Bean(name = "csarInstaller") + public CsarInstaller getCsarInstaller() { + return new CsarInstallerImpl(); + } + + @Bean(name = "sdcSingleController") + public SdcSingleController getSdcSingleController(SdcSingleControllerConfiguration sdcControllerConfig) { + return new SdcSingleController(sdcControllerConfig, true); + } + + @Bean(name = "sdcControllersConfiguration") + public SdcControllersConfiguration getSdcControllersConfiguration() { + return new SdcControllersConfiguration(); + } +} \ No newline at end of file diff --git a/src/main/java/org/onap/clamp/clds/sdc/controller/SdcSingleController.java b/src/main/java/org/onap/clamp/clds/sdc/controller/SdcSingleController.java index 3c877254e..387548ffc 100644 --- a/src/main/java/org/onap/clamp/clds/sdc/controller/SdcSingleController.java +++ b/src/main/java/org/onap/clamp/clds/sdc/controller/SdcSingleController.java @@ -50,13 +50,16 @@ import org.openecomp.sdc.tosca.parser.exceptions.SdcToscaParserException; import org.openecomp.sdc.utils.DistributionActionResultEnum; import org.openecomp.sdc.utils.DistributionStatusEnum; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.stereotype.Component; -@Component +/** + * This class handles one sdc controller defined in the config. It's + * instantiated by Spring config. + */ public class SdcSingleController { private static final EELFLogger logger = EELFManager.getInstance().getLogger(SdcSingleController.class); protected boolean isAsdcClientAutoManaged = false; + @Autowired protected CsarInstaller resourceInstaller; @Autowired protected ClampProperties refProp; @@ -126,6 +129,11 @@ public class SdcSingleController { protected SdcSingleControllerConfiguration sdcConfig; private IDistributionClient distributionClient; + public SdcSingleController(SdcSingleControllerConfiguration sdcSingleConfig, boolean isClientAutoManaged) { + this.isAsdcClientAutoManaged = isClientAutoManaged; + sdcConfig = sdcSingleConfig; + } + /** * This method initializes the SDC Controller and the SDC Client. * diff --git a/src/main/java/org/onap/clamp/clds/sdc/controller/installer/CsarInstallerImpl.java b/src/main/java/org/onap/clamp/clds/sdc/controller/installer/CsarInstallerImpl.java index 3a6bef8d8..cb100725b 100644 --- a/src/main/java/org/onap/clamp/clds/sdc/controller/installer/CsarInstallerImpl.java +++ b/src/main/java/org/onap/clamp/clds/sdc/controller/installer/CsarInstallerImpl.java @@ -48,16 +48,19 @@ import org.onap.clamp.clds.service.CldsTemplateService; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Value; import org.springframework.context.ApplicationContext; -import org.springframework.stereotype.Component; import org.yaml.snakeyaml.Yaml; -@Component +/** + * This class will be instantiated by spring config, and used by Sdc Controller. + * There is no state kept by the bean. It's used to deploy the csar/notification + * received from SDC in DB. + */ public class CsarInstallerImpl implements CsarInstaller { private static final EELFLogger logger = EELFManager.getInstance().getLogger(CsarInstallerImpl.class); private Map bpmnMapping = new HashMap<>(); public static final String TEMPLATE_NAME_PREFIX = "DCAE-Designer-ClosedLoopTemplate-"; - public static final String MODEL_NAME_PREFIX = "DCAE-Designer-ClosedLoopInstance-"; + public static final String MODEL_NAME_PREFIX = "ClosedLoop-"; /** * The file name that will be loaded by Spring. */ @@ -83,16 +86,14 @@ public class CsarInstallerImpl implements CsarInstaller { @Override public boolean isCsarAlreadyDeployed(CsarHandler csar) throws SdcArtifactInstallerException { - return false; + return (CldsModel.retrieve(cldsDao, csar.getSdcCsarHelper().getServiceMetadata().getValue("name"), + false) != null) ? true : false; } @Override public void installTheCsar(CsarHandler csar) throws SdcArtifactInstallerException { try { String serviceTypeId = queryDcaeToGetServiceTypeId(csar); - String policyName = searchForPolicyName(csar); - if (policyName.contains("*")) { - } createFakeCldsModel(csar, createFakeCldsTemplate(csar, this.searchForRightMapping(csar)), serviceTypeId); } catch (IOException e) { throw new SdcArtifactInstallerException("Exception caught during the Csar installation in database", e); @@ -161,7 +162,7 @@ public class CsarInstallerImpl implements CsarInstaller { template.setBpmnId("Sdc-Generated"); template.setBpmnText( IOUtils.toString(appContext.getResource(configFiles.getBpmnXmlFilePath()).getInputStream())); - template.setPropText(csar.getDcaeBlueprint()); + template.setPropText("{\"global\":[{\"name\":\"service\",\"value\":[\"" + csar.getDcaeBlueprint() + "\"]}]}"); template.setImageText( IOUtils.toString(appContext.getResource(configFiles.getSvgXmlFilePath()).getInputStream())); template.setName(TEMPLATE_NAME_PREFIX + csar.getSdcCsarHelper().getServiceMetadata().getValue("name")); @@ -169,15 +170,25 @@ public class CsarInstallerImpl implements CsarInstaller { return template; } - private CldsModel createFakeCldsModel(CsarHandler csar, CldsTemplate cldsTemplate, String serviceTypeId) { + private CldsModel createFakeCldsModel(CsarHandler csar, CldsTemplate cldsTemplate, String serviceTypeId) + throws SdcArtifactInstallerException { CldsModel cldsModel = new CldsModel(); - cldsModel.setControlNamePrefix(MODEL_NAME_PREFIX); + String policyName = searchForPolicyName(csar); + if (policyName.contains("*")) { + // It's a filter must add a specific prefix + cldsModel.setControlNamePrefix(policyName); + } else { + cldsModel.setControlNamePrefix(MODEL_NAME_PREFIX); + } cldsModel.setName(csar.getSdcCsarHelper().getServiceMetadata().getValue("name")); cldsModel.setBlueprintText(csar.getDcaeBlueprint()); cldsModel.setTemplateName(cldsTemplate.getName()); cldsModel.setTemplateId(cldsTemplate.getId()); - cldsModel.setDocText(cldsTemplate.getPropText()); - cldsModel.setPropText("{}"); + // cldsModel.setDocText(cldsTemplate.getPropText()); + cldsModel.setPropText("{\"global\":[{\"name\":\"service\",\"value\":[\"" + + csar.getSdcNotification().getServiceInvariantUUID() + "\"]},{\"name\":\"vf\",\"value\":[\"" + + csar.getBlueprintInvariantResourceUuid() + + "\"]},{\"name\":\"actionSet\",\"value\":[\"vnfRecipe\"]},{\"name\":\"location\",\"value\":[\"DC1\"]}]}"); cldsModel.setBpmnText(cldsTemplate.getBpmnText()); cldsModel.setTypeId(serviceTypeId); cldsModel.save(cldsDao, null); diff --git a/src/main/resources/application.properties b/src/main/resources/application.properties index 17f85817f..5f6a0d659 100644 --- a/src/main/resources/application.properties +++ b/src/main/resources/application.properties @@ -62,7 +62,7 @@ server.port=8080 server.contextPath=/ #Modified engine-rest applicationpath -spring.profiles.active=clamp-default,clamp-spring-authentication +spring.profiles.active=clamp-default,clamp-spring-authentication,clamp-sdc-controller #The max number of active threads in this pool server.tomcat.max-threads=200 -- cgit 1.2.3-korg