aboutsummaryrefslogtreecommitdiffstats
path: root/src/main/java/org
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/java/org')
-rw-r--r--src/main/java/org/onap/clamp/clds/config/spring/CldsSdcControllerConfiguration.java6
-rw-r--r--src/main/java/org/onap/clamp/clds/sdc/controller/installer/BlueprintParser.java138
-rw-r--r--src/main/java/org/onap/clamp/clds/sdc/controller/installer/ChainGenerator.java82
-rw-r--r--src/main/java/org/onap/clamp/clds/sdc/controller/installer/CsarInstallerImpl.java56
-rw-r--r--src/main/java/org/onap/clamp/clds/sdc/controller/installer/MicroService.java68
5 files changed, 329 insertions, 21 deletions
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
index 1fb86c0ce..3f1403f1e 100644
--- a/src/main/java/org/onap/clamp/clds/config/spring/CldsSdcControllerConfiguration.java
+++ b/src/main/java/org/onap/clamp/clds/config/spring/CldsSdcControllerConfiguration.java
@@ -17,6 +17,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
* ============LICENSE_END============================================
+ * * Modifications copyright (c) 2019 Nokia
* ===================================================================
*
*/
@@ -92,11 +93,6 @@ public class CldsSdcControllerConfiguration {
});
}
- @Bean(name = "csarInstaller")
- public CsarInstaller getCsarInstaller() {
- return new CsarInstallerImpl();
- }
-
@Bean(name = "sdcControllersConfiguration")
public SdcControllersConfiguration getSdcControllersConfiguration() {
return new SdcControllersConfiguration();
diff --git a/src/main/java/org/onap/clamp/clds/sdc/controller/installer/BlueprintParser.java b/src/main/java/org/onap/clamp/clds/sdc/controller/installer/BlueprintParser.java
new file mode 100644
index 000000000..16aee2772
--- /dev/null
+++ b/src/main/java/org/onap/clamp/clds/sdc/controller/installer/BlueprintParser.java
@@ -0,0 +1,138 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * ONAP CLAMP
+ * ================================================================================
+ * Copyright (C) 2019 Nokia 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============================================
+ * ===================================================================
+ *
+ */
+package org.onap.clamp.clds.sdc.controller.installer;
+
+import com.google.gson.Gson;
+import com.google.gson.JsonArray;
+import com.google.gson.JsonElement;
+import com.google.gson.JsonObject;
+import java.util.Collections;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Map.Entry;
+import java.util.Set;
+import org.json.JSONObject;
+import org.springframework.stereotype.Component;
+import org.yaml.snakeyaml.Yaml;
+
+@Component
+public class BlueprintParser {
+
+ static final String TCA = "TCA";
+ static final String HOLMES = "Holmes";
+ private static final String TCA_POLICY = "tca_policy";
+ private static final String HOLMES_PREFIX = "holmes";
+ private static final String NODE_TEMPLATES = "node_templates";
+ private static final String DCAE_NODES = "dcae.nodes.";
+ private static final String TYPE = "type";
+ private static final String PROPERTIES = "properties";
+ private static final String NAME = "name";
+ private static final String RELATIONSHIPS = "relationships";
+ private static final String CLAMP_NODE_RELATIONSHIPS_GETS_INPUT_FROM = "clamp_node.relationships.gets_input_from";
+ private static final String TARGET = "target";
+
+ BlueprintParser() {}
+
+ Set<MicroService> getMicroServices(String blueprintString) {
+ Set <MicroService> microServices = new HashSet<>();
+ JsonObject jsonObject = BlueprintParser.convertToJson(blueprintString);
+ JsonObject results = jsonObject.get(NODE_TEMPLATES).getAsJsonObject();
+
+ for (Entry<String, JsonElement> entry : results.entrySet()) {
+ JsonObject nodeTemplate = entry.getValue().getAsJsonObject();
+ if (nodeTemplate.get(TYPE).getAsString().contains(DCAE_NODES)) {
+ MicroService microService = getNodeRepresentation(entry);
+ microServices.add(microService);
+ }
+ }
+ microServices.removeIf(ms -> TCA_POLICY.equals(ms.getName()));
+ return microServices;
+ }
+
+ List<MicroService> fallbackToOneMicroService(String blueprintString) {
+ JsonObject jsonObject = BlueprintParser.convertToJson(blueprintString);
+ JsonObject results = jsonObject.get(NODE_TEMPLATES).getAsJsonObject();
+ String theBiggestMicroServiceContent = "";
+ String theBiggestMicroServiceKey = "";
+ for (Entry<String, JsonElement> entry : results.entrySet()) {
+ String msAsString = entry.getValue().toString();
+ int len =msAsString.length();
+ if(len > theBiggestMicroServiceContent.length()) {
+ theBiggestMicroServiceContent = msAsString;
+ theBiggestMicroServiceKey = entry.getKey();
+ }
+ }
+ String msName = theBiggestMicroServiceKey.toLowerCase().contains(HOLMES_PREFIX) ? HOLMES : TCA;
+ return Collections.singletonList(new MicroService(msName, ""));
+ }
+
+ String getName(Entry<String, JsonElement> entry) {
+ String microServiceYamlName = entry.getKey();
+ JsonObject ob = entry.getValue().getAsJsonObject();
+ if (ob.has(PROPERTIES)) {
+ JsonObject properties = ob.get(PROPERTIES).getAsJsonObject();
+ if (properties.has(NAME)) {
+ return properties.get(NAME).getAsString();
+ }
+ }
+ return microServiceYamlName;
+ }
+
+ String getInput(Entry<String, JsonElement> entry) {
+ JsonObject ob = entry.getValue().getAsJsonObject();
+ if (ob.has(RELATIONSHIPS)) {
+ JsonArray relationships = ob.getAsJsonArray(RELATIONSHIPS);
+ for (JsonElement element : relationships) {
+ String target = getTarget(element.getAsJsonObject());
+ if(!target.isEmpty()) {
+ return target;
+ }
+ }
+ }
+ return "";
+ }
+
+ MicroService getNodeRepresentation(Entry<String, JsonElement> entry) {
+ String name = getName(entry);
+ String getInputFrom = getInput(entry);
+ return new MicroService(name, getInputFrom);
+ }
+
+ private String getTarget(JsonObject elementObject) {
+ if (elementObject.has(TYPE) &&
+ elementObject.has(TARGET) &&
+ elementObject.get(TYPE).getAsString().equals(CLAMP_NODE_RELATIONSHIPS_GETS_INPUT_FROM)) {
+ return elementObject.get(TARGET).getAsString();
+ }
+ return "";
+ }
+
+ private static JsonObject convertToJson(String yamlString) {
+ Yaml yaml = new Yaml();
+ Map<String, Object> map = yaml.load(yamlString);
+
+ JSONObject jsonObject = new JSONObject(map);
+ return new Gson().fromJson(jsonObject.toString(), JsonObject.class);
+ }
+}
diff --git a/src/main/java/org/onap/clamp/clds/sdc/controller/installer/ChainGenerator.java b/src/main/java/org/onap/clamp/clds/sdc/controller/installer/ChainGenerator.java
new file mode 100644
index 000000000..b05b80f00
--- /dev/null
+++ b/src/main/java/org/onap/clamp/clds/sdc/controller/installer/ChainGenerator.java
@@ -0,0 +1,82 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * ONAP CLAMP
+ * ================================================================================
+ * Copyright (C) 2019 Nokia 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============================================
+ * ===================================================================
+ *
+ */
+package org.onap.clamp.clds.sdc.controller.installer;
+
+import java.util.LinkedList;
+import java.util.List;
+import java.util.Set;
+import java.util.stream.Collectors;
+import org.springframework.stereotype.Component;
+
+@Component
+public class ChainGenerator {
+
+ ChainGenerator() {}
+
+ List<MicroService> getChainOfMicroServices(Set<MicroService> input) {
+ LinkedList<MicroService> returnList = new LinkedList<>();
+ if(preValidate(input)) {
+ LinkedList<MicroService> theList = new LinkedList<>();
+ for (MicroService ms : input) {
+ insertNodeTemplateIntoChain(ms, theList);
+ }
+ if(postValidate(theList)) {
+ returnList = theList;
+ }
+ }
+ return returnList;
+ }
+
+ private boolean preValidate(Set<MicroService> input) {
+ List<MicroService> noInputs =
+ input.stream().filter(ms -> "".equals(ms.getInputFrom())).collect(Collectors.toList());
+ return noInputs.size() == 1;
+ }
+
+ private boolean postValidate(LinkedList<MicroService> microServices) {
+ for (int i = 1; i < microServices.size() - 1; i++) {
+ MicroService prev = microServices.get(i-1);
+ MicroService current = microServices.get(i);
+ if(!current.getInputFrom().equals(prev.getName())) {
+ return false;
+ }
+ }
+ return true;
+ }
+
+ private void insertNodeTemplateIntoChain(MicroService microServicetoInsert,
+ LinkedList<MicroService> chainOfMicroServices) {
+ int insertIndex = 0;
+ for (int i = 0; i < chainOfMicroServices.size(); i++) {
+ MicroService current = chainOfMicroServices.get(i);
+ if (microServicetoInsert.getName().equals(current.getInputFrom())) {
+ insertIndex = i;
+ break;
+ } else if (current.getName().equals(microServicetoInsert.getInputFrom())) {
+ insertIndex = i + 1;
+ break;
+ }
+ }
+ chainOfMicroServices.add(insertIndex, microServicetoInsert);
+ }
+}
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 6841b87b0..df4e13ab0 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
@@ -17,6 +17,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
* ============LICENSE_END============================================
+ * Modifications copyright (c) 2019 Nokia
* ===================================================================
*
*/
@@ -35,6 +36,7 @@ import java.util.Map;
import java.util.Map.Entry;
import java.util.Optional;
+import java.util.Set;
import javax.annotation.PostConstruct;
import javax.xml.transform.TransformerException;
@@ -57,6 +59,7 @@ import org.onap.clamp.clds.util.JsonUtils;
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.springframework.transaction.annotation.Transactional;
import org.yaml.snakeyaml.Yaml;
@@ -65,6 +68,7 @@ import org.yaml.snakeyaml.Yaml;
* There is no state kept by the bean. It's used to deploy the csar/notification
* received from SDC in DB.
*/
+@Component
public class CsarInstallerImpl implements CsarInstaller {
private static final EELFLogger logger = EELFManager.getInstance().getLogger(CsarInstallerImpl.class);
@@ -79,19 +83,31 @@ public class CsarInstallerImpl implements CsarInstaller {
*/
@Value("${clamp.config.sdc.blueprint.parser.mapping:'classpath:/clds/blueprint-parser-mapping.json'}")
protected String blueprintMappingFile;
- @Autowired
protected ApplicationContext appContext;
- @Autowired
private CldsDao cldsDao;
- @Autowired
CldsTemplateService cldsTemplateService;
- @Autowired
CldsService cldsService;
- @Autowired
DcaeInventoryServices dcaeInventoryService;
- @Autowired
private XslTransformer cldsBpmnTransformer;
+ @Autowired
+ public CsarInstallerImpl(ApplicationContext appContext,
+ CldsDao cldsDao, CldsTemplateService cldsTemplateService, CldsService cldsService,
+ DcaeInventoryServices dcaeInventoryService, XslTransformer cldsBpmnTransformer) {
+ this.appContext = appContext;
+ this.cldsDao = cldsDao;
+ this.cldsTemplateService = cldsTemplateService;
+ this.cldsService = cldsService;
+ this.dcaeInventoryService = dcaeInventoryService;
+ this.cldsBpmnTransformer = cldsBpmnTransformer;
+ }
+
+ @Autowired
+ private BlueprintParser blueprintParser;
+
+ @Autowired
+ private ChainGenerator chainGenerator;
+
@PostConstruct
public void loadConfiguration() throws IOException {
BlueprintParserMappingConfiguration
@@ -147,16 +163,7 @@ public class CsarInstallerImpl implements CsarInstaller {
}
}
- private void createPolicyModel(CsarHandler csar) throws PolicyModelException {
- try{
- Optional<String> policyModelYaml = csar.getPolicyModelYaml();
- // save policy model into the database
- } catch (IOException e) {
- throw new PolicyModelException("TransformerException when decoding the YamlText", e);
- }
- }
-
- private BlueprintParserFilesConfiguration searchForRightMapping(BlueprintArtifact blueprintArtifact)
+ BlueprintParserFilesConfiguration searchForRightMapping(BlueprintArtifact blueprintArtifact)
throws SdcArtifactInstallerException {
List<BlueprintParserFilesConfiguration> listConfig = new ArrayList<>();
Yaml yaml = new Yaml();
@@ -195,6 +202,15 @@ public class CsarInstallerImpl implements CsarInstaller {
return node.toString();
}
+ private void createPolicyModel(CsarHandler csar) throws PolicyModelException {
+ try{
+ Optional<String> policyModelYaml = csar.getPolicyModelYaml();
+ // save policy model into the database
+ } catch (IOException e) {
+ throw new PolicyModelException("TransformerException when decoding the YamlText", e);
+ }
+ }
+
private static String searchForPolicyScopePrefix(BlueprintArtifact blueprintArtifact)
throws SdcArtifactInstallerException {
String policyName = null;
@@ -242,6 +258,14 @@ public class CsarInstallerImpl implements CsarInstaller {
private CldsTemplate createFakeCldsTemplate(CsarHandler csar, BlueprintArtifact blueprintArtifact,
BlueprintParserFilesConfiguration configFiles) throws IOException, SdcArtifactInstallerException {
+
+ Set<MicroService> microServicesFromBlueprint = blueprintParser.getMicroServices(blueprintArtifact.getDcaeBlueprint()) ;
+ List<MicroService> microServicesChain = chainGenerator.getChainOfMicroServices(microServicesFromBlueprint);
+ if(microServicesChain.isEmpty()) {
+ microServicesChain = blueprintParser.fallbackToOneMicroService(blueprintArtifact.getDcaeBlueprint());
+ }
+ //place where SVG text will be generated
+
CldsTemplate template = new CldsTemplate();
template.setBpmnId("Sdc-Generated");
template
diff --git a/src/main/java/org/onap/clamp/clds/sdc/controller/installer/MicroService.java b/src/main/java/org/onap/clamp/clds/sdc/controller/installer/MicroService.java
new file mode 100644
index 000000000..287ac9a90
--- /dev/null
+++ b/src/main/java/org/onap/clamp/clds/sdc/controller/installer/MicroService.java
@@ -0,0 +1,68 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * ONAP CLAMP
+ * ================================================================================
+ * Copyright (C) 2019 Nokia 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============================================
+ * ===================================================================
+ *
+ */
+package org.onap.clamp.clds.sdc.controller.installer;
+
+import java.util.Objects;
+
+public class MicroService {
+ private final String name;
+ private final String inputFrom;
+
+ public MicroService(String name, String inputFrom) {
+ this.name = name;
+ this.inputFrom = inputFrom;
+ }
+ public String getName() {
+ return name;
+ }
+
+ public String getInputFrom() {
+ return inputFrom;
+ }
+
+ @Override
+ public String toString() {
+ return "MicroService{" +
+ "name='" + name + '\'' +
+ ", inputFrom='" + inputFrom + '\'' +
+ '}';
+ }
+
+ @Override
+ public boolean equals(Object o) {
+ if (this == o) {
+ return true;
+ }
+ if (o == null || getClass() != o.getClass()) {
+ return false;
+ }
+ MicroService that = (MicroService) o;
+ return name.equals(that.name) &&
+ inputFrom.equals(that.inputFrom);
+ }
+
+ @Override
+ public int hashCode() {
+ return Objects.hash(name, inputFrom);
+ }
+}