summaryrefslogtreecommitdiffstats
path: root/bpmn/MSOCommonBPMN
diff options
context:
space:
mode:
Diffstat (limited to 'bpmn/MSOCommonBPMN')
-rw-r--r--bpmn/MSOCommonBPMN/pom.xml5
-rw-r--r--bpmn/MSOCommonBPMN/src/main/java/org/openecomp/mso/bpmn/common/resource/ResourceRequestBuilder.java131
-rw-r--r--bpmn/MSOCommonBPMN/src/main/java/org/openecomp/mso/client/policy/RestClient.java11
-rw-r--r--bpmn/MSOCommonBPMN/src/main/java/org/openecomp/mso/client/policy/entities/PolicyServiceType.java2
-rw-r--r--bpmn/MSOCommonBPMN/src/test/java/org/openecomp/mso/bpmn/common/resource/ResourceRequestBuilderTest.java35
-rw-r--r--bpmn/MSOCommonBPMN/src/test/java/org/openecomp/mso/bpmn/mock/MockResource.java2
6 files changed, 176 insertions, 10 deletions
diff --git a/bpmn/MSOCommonBPMN/pom.xml b/bpmn/MSOCommonBPMN/pom.xml
index 71626f52b3..e4e1fd60a6 100644
--- a/bpmn/MSOCommonBPMN/pom.xml
+++ b/bpmn/MSOCommonBPMN/pom.xml
@@ -302,6 +302,11 @@
<version>${spring.version}</version>
</dependency>
<dependency>
+ <groupId>org.openecomp.sdc.sdc-tosca</groupId>
+ <artifactId>sdc-tosca</artifactId>
+ <version>1.1.32</version>
+ </dependency>
+ <dependency>
<groupId>com.github.tomakehurst</groupId>
<artifactId>wiremock</artifactId>
<version>1.56</version>
diff --git a/bpmn/MSOCommonBPMN/src/main/java/org/openecomp/mso/bpmn/common/resource/ResourceRequestBuilder.java b/bpmn/MSOCommonBPMN/src/main/java/org/openecomp/mso/bpmn/common/resource/ResourceRequestBuilder.java
new file mode 100644
index 0000000000..78eb2f662d
--- /dev/null
+++ b/bpmn/MSOCommonBPMN/src/main/java/org/openecomp/mso/bpmn/common/resource/ResourceRequestBuilder.java
@@ -0,0 +1,131 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * ONAP - SO
+ * ================================================================================
+ * Copyright (C) 2017 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=========================================================
+ */
+package org.openecomp.mso.bpmn.common.resource;
+
+import com.google.gson.Gson;
+import com.google.gson.reflect.TypeToken;
+import org.jboss.resteasy.client.jaxrs.ResteasyClient;
+import org.jboss.resteasy.client.jaxrs.ResteasyClientBuilder;
+import org.jboss.resteasy.client.jaxrs.ResteasyWebTarget;
+import org.openecomp.mso.logger.MsoLogger;
+import org.openecomp.sdc.tosca.parser.api.ISdcCsarHelper;
+import org.openecomp.sdc.tosca.parser.exceptions.SdcToscaParserException;
+import org.openecomp.sdc.tosca.parser.impl.SdcToscaParserFactory;
+import org.openecomp.sdc.toscaparser.api.NodeTemplate;
+import org.openecomp.sdc.toscaparser.api.Property;
+import org.openecomp.sdc.toscaparser.api.functions.GetInput;
+import org.openecomp.sdc.toscaparser.api.parameters.Input;
+
+import javax.ws.rs.core.Response;
+import java.io.File;
+import java.util.HashMap;
+import java.util.LinkedHashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Optional;
+
+public class ResourceRequestBuilder {
+
+ public static String CUSTOMIZATION_UUID = "customizationUUID";
+ public static String SERVICE_URL_TOSCA_CSAR = "http://localhost:8080/ecomp/mso/catalog/v3/serviceToscaCsar?serviceModelUuid=";
+
+ private static MsoLogger LOGGER = MsoLogger.getMsoLogger(MsoLogger.Catalog.RA);
+
+ public static Map<String, Object> buildResouceRequest(String serviceUuid,
+ String resourceCustomizationUuid,
+ Map<String, Object> serviceInputs) throws SdcToscaParserException {
+
+ Map<String, Object> resouceRequest = new HashMap<>();
+
+ String csarpath = null;
+ try {
+ csarpath = getCsarFromUuid(serviceUuid);
+ } catch (Exception e) {
+ LOGGER.debug("csar file is not available for service uuid:" + serviceUuid, e);
+ return resouceRequest;
+ }
+
+ SdcToscaParserFactory toscaParser = SdcToscaParserFactory.getInstance();
+ ISdcCsarHelper iSdcCsarHelper = toscaParser.getSdcCsarHelper(csarpath);
+
+ List<Input> serInput = iSdcCsarHelper.getServiceInputs();
+ Optional<NodeTemplate> nodeTemplateOpt = iSdcCsarHelper.getServiceNodeTemplates().stream()
+ .filter(e -> e.getMetaData().getValue(CUSTOMIZATION_UUID).equals(resourceCustomizationUuid))
+ .findFirst();
+
+ if (nodeTemplateOpt.isPresent()) {
+ NodeTemplate nodeTemplate = nodeTemplateOpt.get();
+ LinkedHashMap<String, Property> resourceProperties = nodeTemplate.getProperties();
+
+ for (String key: resourceProperties.keySet()) {
+ Property property = resourceProperties.get(key);
+
+ Object value = getValue(property.getValue(), serviceInputs, serInput);
+ resouceRequest.put(key, value);
+ }
+ }
+ return resouceRequest;
+ }
+
+ private static Object getValue(Object value, Map<String, Object> serviceInputs,
+ List<Input> servInputs) {
+ if (value instanceof Map) {
+ Map<String, Object> valueMap = new HashMap<>();
+
+ Map<String, Object> propertyMap = (Map<String, Object>) value;
+
+ for (String key: propertyMap.keySet()) {
+ valueMap.put(key, getValue(propertyMap.get(key), serviceInputs, servInputs));
+ }
+ return valueMap; // return if the value is nested hashmap
+ } else if (value instanceof GetInput) {
+ String inputName = ((GetInput) value).getInputName();
+
+ if (serviceInputs.get(inputName) != null) {
+ value = serviceInputs.get(inputName);
+ } else {
+ for (Input input: servInputs) {
+ if (input.getName().equals(inputName)) {
+ return input.getDefault(); // return default value
+ }
+ }
+ }
+ }
+ return value; // return property value
+ }
+
+ private static String getCsarFromUuid(String uuid) throws Exception {
+
+ ResteasyClient client = new ResteasyClientBuilder().build();
+ ResteasyWebTarget target = client.target(SERVICE_URL_TOSCA_CSAR + uuid);
+ Response response = target.request().get();
+ String value = response.readEntity(String.class);
+
+ HashMap<String,String> map = new Gson().fromJson(value, new TypeToken<HashMap<String, String>>(){}.getType());
+
+ File csarFile = new File(System.getProperty("mso.config.path") + "ASDC/" + map.get("name"));
+
+ if (!csarFile.exists()) {
+ throw new Exception("csar file does not exist.");
+ }
+
+ return csarFile.getAbsolutePath();
+ }
+}
diff --git a/bpmn/MSOCommonBPMN/src/main/java/org/openecomp/mso/client/policy/RestClient.java b/bpmn/MSOCommonBPMN/src/main/java/org/openecomp/mso/client/policy/RestClient.java
index 74b1c3f802..1436d83a94 100644
--- a/bpmn/MSOCommonBPMN/src/main/java/org/openecomp/mso/client/policy/RestClient.java
+++ b/bpmn/MSOCommonBPMN/src/main/java/org/openecomp/mso/client/policy/RestClient.java
@@ -157,14 +157,9 @@ public abstract class RestClient {
}
client.register(this.getMapper());
Optional<ClientResponseFilter> responseFilter = this.addResponseFilter();
- if (responseFilter.isPresent()) {
- client.register(responseFilter.get());
- }
- if (!path.isPresent()) {
- webTarget = client.target(host.toString());
- } else {
- webTarget = client.target(UriBuilder.fromUri(host + path.get().toString()));
- }
+ responseFilter.ifPresent(clientResponseFilter -> client.register(clientResponseFilter));
+ webTarget = path.<WebTarget>map(uri -> client.target(UriBuilder.fromUri(host + uri.toString())))
+ .orElseGet(() -> client.target(host.toString()));
this.accept = MediaType.APPLICATION_JSON;
this.contentType = MediaType.APPLICATION_JSON;
}
diff --git a/bpmn/MSOCommonBPMN/src/main/java/org/openecomp/mso/client/policy/entities/PolicyServiceType.java b/bpmn/MSOCommonBPMN/src/main/java/org/openecomp/mso/client/policy/entities/PolicyServiceType.java
index b5ab63ce35..01f6738947 100644
--- a/bpmn/MSOCommonBPMN/src/main/java/org/openecomp/mso/client/policy/entities/PolicyServiceType.java
+++ b/bpmn/MSOCommonBPMN/src/main/java/org/openecomp/mso/client/policy/entities/PolicyServiceType.java
@@ -36,7 +36,7 @@ public enum PolicyServiceType {
private final String name;
- private PolicyServiceType(String name) {
+ PolicyServiceType(String name) {
this.name = name;
}
diff --git a/bpmn/MSOCommonBPMN/src/test/java/org/openecomp/mso/bpmn/common/resource/ResourceRequestBuilderTest.java b/bpmn/MSOCommonBPMN/src/test/java/org/openecomp/mso/bpmn/common/resource/ResourceRequestBuilderTest.java
new file mode 100644
index 0000000000..262c12e833
--- /dev/null
+++ b/bpmn/MSOCommonBPMN/src/test/java/org/openecomp/mso/bpmn/common/resource/ResourceRequestBuilderTest.java
@@ -0,0 +1,35 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * ONAP - SO
+ * ================================================================================
+ * Copyright (C) 2017 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=========================================================
+ */
+package org.openecomp.mso.bpmn.common.resource;
+
+import org.junit.Test;
+
+import java.util.HashMap;
+
+public class ResourceRequestBuilderTest {
+
+ @Test
+ public void buildResouceRequestTest() throws Exception {
+
+ ResourceRequestBuilder.buildResouceRequest("aa4535",
+ "a1074969-944f-4ddc-b687-9550b0c8cd57", new HashMap<>());
+ }
+
+} \ No newline at end of file
diff --git a/bpmn/MSOCommonBPMN/src/test/java/org/openecomp/mso/bpmn/mock/MockResource.java b/bpmn/MSOCommonBPMN/src/test/java/org/openecomp/mso/bpmn/mock/MockResource.java
index 74f50ba438..9ead882b07 100644
--- a/bpmn/MSOCommonBPMN/src/test/java/org/openecomp/mso/bpmn/mock/MockResource.java
+++ b/bpmn/MSOCommonBPMN/src/test/java/org/openecomp/mso/bpmn/mock/MockResource.java
@@ -108,7 +108,7 @@ public class MockResource {
@Produces("application/json")
public Response start(@PathParam("portNumber") Integer portNumber) {
if (portNumber == null) portNumber = defaultPort;
- return startMockServer(portNumber.intValue());
+ return startMockServer(portNumber);
}