summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--bpmn/MSOCoreBPMN/src/main/java/org/onap/so/bpmn/core/domain/ServiceDecomposition.java25
-rw-r--r--bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/buildingblock/SniroHomingV2.java77
2 files changed, 45 insertions, 57 deletions
diff --git a/bpmn/MSOCoreBPMN/src/main/java/org/onap/so/bpmn/core/domain/ServiceDecomposition.java b/bpmn/MSOCoreBPMN/src/main/java/org/onap/so/bpmn/core/domain/ServiceDecomposition.java
index b3439d58e3..3632d187c9 100644
--- a/bpmn/MSOCoreBPMN/src/main/java/org/onap/so/bpmn/core/domain/ServiceDecomposition.java
+++ b/bpmn/MSOCoreBPMN/src/main/java/org/onap/so/bpmn/core/domain/ServiceDecomposition.java
@@ -4,6 +4,8 @@
* ================================================================================
* Copyright (C) 2017 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
@@ -24,7 +26,6 @@ package org.onap.so.bpmn.core.domain;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.Collections;
-import java.util.Iterator;
import java.util.List;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonProperty;
@@ -32,6 +33,8 @@ import com.fasterxml.jackson.annotation.JsonRootName;
import org.json.JSONObject;
import org.onap.so.bpmn.core.json.DecomposeJsonUtil;
import org.onap.so.bpmn.core.json.JsonDecomposingException;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
@@ -41,10 +44,10 @@ import org.onap.so.bpmn.core.json.JsonDecomposingException;
* resource's decompositon
*/
@JsonRootName(value = "serviceResources")
-// @JsonTypeInfo(include=As.WRAPPER_OBJECT, use=Id.NAME)
public class ServiceDecomposition extends JsonWrapper implements Serializable {
private static final long serialVersionUID = 1L;
+ private static final Logger logger = LoggerFactory.getLogger(ServiceDecomposition.class);
@JsonProperty("modelInfo")
private ModelInfo modelInfo;
@@ -315,8 +318,6 @@ public class ServiceDecomposition extends JsonWrapper implements Serializable {
public String getVnfResource(String resourceObjectId) {
for (Resource resource : getServiceResources()) {
- // resource.getModelInfo().getModelInvariantId();
-
if ("extracted information".equals(resourceObjectId)) {
return resource.toJsonString();
}
@@ -457,11 +458,11 @@ public class ServiceDecomposition extends JsonWrapper implements Serializable {
boolean result = false;
for (Resource resource : (Iterable<Resource>) resources) {
- System.out.println("resource found");
+ logger.debug("resource found");
if (resource.resourceType == newResource.resourceType) {
- System.out.println("resource type matches");
+ logger.debug("resource type matches");
if (resource.getResourceId().equalsIgnoreCase(newResource.getResourceId())) {
- System.out.println("resource id matches");
+ logger.debug("resource id matches");
// returns TRUE if replacement is a success
result = Collections.replaceAll(resources, resource, newResource);
}
@@ -491,14 +492,12 @@ public class ServiceDecomposition extends JsonWrapper implements Serializable {
public boolean deleteResource(Resource resource) {
List serviceResourceList = getResourceList(resource);
for (Resource item : (Iterable<Resource>) serviceResourceList) {
- if (item.resourceType == resource.resourceType) {
- if (item.getResourceId().equalsIgnoreCase(resource.getResourceId())) {
- // returns TRUE if replacement is a success
- return serviceResourceList.remove(resource);
- }
+ if (item.resourceType == resource.resourceType
+ && item.getResourceId().equalsIgnoreCase(resource.getResourceId())) {
+ // returns TRUE if replacement is a success
+ return serviceResourceList.remove(resource);
}
}
-
return false;
}
diff --git a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/buildingblock/SniroHomingV2.java b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/buildingblock/SniroHomingV2.java
index 2b9729f7c7..7c1ddc9923 100644
--- a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/buildingblock/SniroHomingV2.java
+++ b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/buildingblock/SniroHomingV2.java
@@ -90,19 +90,17 @@ public class SniroHomingV2 {
private SniroClient client;
@Autowired
private ExceptionBuilder exceptionUtil;
- private static final String MODEL_NAME = "modelName";
private static final String MODEL_INVARIANT_ID = "modelInvariantId";
private static final String MODEL_VERSION_ID = "modelVersionId";
- private static final String MODEL_VERSION = "modelVersion";
private static final String SERVICE_RESOURCE_ID = "serviceResourceId";
- private static final String RESOURCE_MODULE_NAME = "resourceModuleName";
- private static final String RESOURCE_MODEL_INFO = "resourceModelInfo";
private static final String IDENTIFIER_TYPE = "identifierType";
private static final String SOLUTIONS = "solutions";
private static final String RESOURCE_MISSING_DATA = "Resource does not contain: ";
private static final String SERVICE_MISSING_DATA = "Service Instance does not contain: ";
private static final String UNPROCESSABLE = "422";
private static final int INTERNAL = 500;
+ private static final String EXCEPTION_OCCURRED = "Exception occurred";
+ private static final String VNF_HOST_NAME = "vnfHostName";
/**
* Generates the request payload then sends to sniro manager to perform homing and licensing for the provided
@@ -147,7 +145,7 @@ public class SniroHomingV2 {
licenseInfo.setDemands(licenseDemands);
request.setLicenseInformation(licenseInfo);
- if (placementDemands.size() > 0 || licenseDemands.size() > 0) {
+ if (!placementDemands.isEmpty() || !licenseDemands.isEmpty()) {
client.postDemands(request);
} else {
logger.debug(SERVICE_MISSING_DATA + "resources eligible for homing or licensing");
@@ -161,13 +159,13 @@ public class SniroHomingV2 {
logger.trace("Completed Sniro Homing Call Sniro");
} catch (BpmnError e) {
- logger.error("Exception occurred", e);
+ logger.error(EXCEPTION_OCCURRED, e);
exceptionUtil.buildAndThrowWorkflowException(execution, Integer.parseInt(e.getErrorCode()), e.getMessage());
} catch (BadResponseException e) {
- logger.error("Exception occurred", e);
+ logger.error(EXCEPTION_OCCURRED, e);
exceptionUtil.buildAndThrowWorkflowException(execution, 400, e.getMessage());
} catch (Exception e) {
- logger.error("Exception occurred", e);
+ logger.error(EXCEPTION_OCCURRED, e);
exceptionUtil.buildAndThrowWorkflowException(execution, INTERNAL,
"Internal Error - occurred while preparing sniro request: " + e.getMessage());
}
@@ -213,13 +211,13 @@ public class SniroHomingV2 {
logger.trace("Completed Sniro Homing Process Solution");
} catch (BpmnError e) {
- logger.error("Exception occurred", e);
+ logger.error(EXCEPTION_OCCURRED, e);
exceptionUtil.buildAndThrowWorkflowException(execution, Integer.parseInt(e.getErrorCode()), e.getMessage());
} catch (BadResponseException e) {
- logger.error("Exception occurred", e);
+ logger.error(EXCEPTION_OCCURRED, e);
exceptionUtil.buildAndThrowWorkflowException(execution, 400, e.getMessage());
} catch (Exception e) {
- logger.error("Exception occurred", e);
+ logger.error(EXCEPTION_OCCURRED, e);
exceptionUtil.buildAndThrowWorkflowException(execution, INTERNAL,
"Internal Error - occurred while processing sniro asynchronous response: " + e.getMessage());
}
@@ -230,7 +228,7 @@ public class SniroHomingV2 {
*
* @throws Exception
*/
- private RequestInfo buildRequestInfo(String requestId, String timeout) throws Exception {
+ private RequestInfo buildRequestInfo(String requestId, String timeout) {
logger.trace("Building request information");
RequestInfo requestInfo = new RequestInfo();
if (requestId != null) {
@@ -305,7 +303,7 @@ public class SniroHomingV2 {
*/
private List<Demand> buildPlacementDemands(ServiceInstance serviceInstance) {
logger.trace("Building placement information demands");
- List<Demand> placementDemands = new ArrayList<Demand>();
+ List<Demand> placementDemands = new ArrayList<>();
List<AllottedResource> allottedResourceList = serviceInstance.getAllottedResources();
if (!allottedResourceList.isEmpty()) {
@@ -355,7 +353,7 @@ public class SniroHomingV2 {
*/
private List<Demand> buildLicenseDemands(ServiceInstance serviceInstance) {
logger.trace("Building license information");
- List<Demand> licenseDemands = new ArrayList<Demand>();
+ List<Demand> licenseDemands = new ArrayList<>();
List<GenericVnf> vnfList = serviceInstance.getVnfs();
if (!vnfList.isEmpty()) {
logger.debug("Adding vnfs to license demands list");
@@ -413,42 +411,33 @@ public class SniroHomingV2 {
List<Candidate> required = candidates.getRequiredCandidates();
List<Candidate> excluded = candidates.getExcludedCandidates();
List<Candidate> existing = candidates.getExistingCandidates();
- if (!required.isEmpty()) {
- List<org.onap.so.client.sniro.beans.Candidate> cans =
- new ArrayList<org.onap.so.client.sniro.beans.Candidate>();
- for (Candidate c : required) {
- org.onap.so.client.sniro.beans.Candidate can = new org.onap.so.client.sniro.beans.Candidate();
- can.setIdentifierType(c.getIdentifierType());
- can.setIdentifiers(c.getIdentifiers());
- can.setCloudOwner(c.getCloudOwner());
- cans.add(can);
- }
- demand.setRequiredCandidates(cans);
+
+ List<org.onap.so.client.sniro.beans.Candidate> candidateList = getCandidates(required);
+ if (!candidateList.isEmpty()) {
+ demand.setRequiredCandidates(candidateList);
}
- if (!excluded.isEmpty()) {
- List<org.onap.so.client.sniro.beans.Candidate> cans =
- new ArrayList<org.onap.so.client.sniro.beans.Candidate>();
- for (Candidate c : excluded) {
- org.onap.so.client.sniro.beans.Candidate can = new org.onap.so.client.sniro.beans.Candidate();
- can.setIdentifierType(c.getIdentifierType());
- can.setIdentifiers(c.getIdentifiers());
- can.setCloudOwner(c.getCloudOwner());
- cans.add(can);
- }
- demand.setExcludedCandidates(cans);
+ candidateList = getCandidates(excluded);
+ if (!candidateList.isEmpty()) {
+ demand.setExcludedCandidates(candidateList);
}
- if (!existing.isEmpty()) {
- List<org.onap.so.client.sniro.beans.Candidate> cans =
- new ArrayList<org.onap.so.client.sniro.beans.Candidate>();
- for (Candidate c : existing) {
+ candidateList = getCandidates(existing);
+ if (!candidateList.isEmpty()) {
+ demand.setExistingCandidates(candidateList);
+ }
+ }
+
+ private List<org.onap.so.client.sniro.beans.Candidate> getCandidates(List<Candidate> candidates) {
+ List<org.onap.so.client.sniro.beans.Candidate> candidateList = new ArrayList<>();
+ if (!candidates.isEmpty()) {
+ for (Candidate c : candidates) {
org.onap.so.client.sniro.beans.Candidate can = new org.onap.so.client.sniro.beans.Candidate();
can.setIdentifierType(c.getIdentifierType());
can.setIdentifiers(c.getIdentifiers());
can.setCloudOwner(c.getCloudOwner());
- cans.add(can);
+ candidateList.add(can);
}
- demand.setExistingCandidates(cans);
}
+ return candidateList;
}
/**
@@ -562,7 +551,7 @@ public class SniroHomingV2 {
si.setServiceInstanceId(identifierValue);
si.setOrchestrationStatus(OrchestrationStatus.CREATED);
cloud.setLcpCloudRegionId(assignmentsMap.get("cloudRegionId"));
- if (assignmentsMap.containsKey("vnfHostName") && !assignmentsMap.get("vnfHostName").isEmpty()) {
+ if (assignmentsMap.containsKey(VNF_HOST_NAME) && !assignmentsMap.get(VNF_HOST_NAME).isEmpty()) {
logger.debug("Resources has been homed to a vnf");
GenericVnf vnf = setVnf(assignmentsMap);
vnf.setCloudRegion(cloud);
@@ -612,7 +601,7 @@ public class SniroHomingV2 {
private GenericVnf setVnf(Map<String, String> assignmentsMap) {
GenericVnf vnf = new GenericVnf();
vnf.setOrchestrationStatus(OrchestrationStatus.CREATED);
- vnf.setVnfName(assignmentsMap.get("vnfHostName"));
+ vnf.setVnfName(assignmentsMap.get(VNF_HOST_NAME));
vnf.setVnfId(assignmentsMap.get("vnfId"));
return vnf;
}