diff options
Diffstat (limited to 'adapters/mso-adapter-utils/src/main/java')
2 files changed, 93 insertions, 19 deletions
diff --git a/adapters/mso-adapter-utils/src/main/java/org/onap/so/openstack/utils/MsoMulticloudUtils.java b/adapters/mso-adapter-utils/src/main/java/org/onap/so/openstack/utils/MsoMulticloudUtils.java index 2788387bc1..7bf68fff78 100644 --- a/adapters/mso-adapter-utils/src/main/java/org/onap/so/openstack/utils/MsoMulticloudUtils.java +++ b/adapters/mso-adapter-utils/src/main/java/org/onap/so/openstack/utils/MsoMulticloudUtils.java @@ -25,6 +25,7 @@ package org.onap.so.openstack.utils; import com.fasterxml.jackson.databind.JsonNode; import com.fasterxml.jackson.databind.ObjectMapper; import com.woorea.openstack.heat.model.CreateStackParam; +import com.woorea.openstack.heat.model.Stack; import java.net.MalformedURLException; import java.net.URL; import java.util.Arrays; @@ -56,6 +57,7 @@ import org.onap.so.openstack.exceptions.MsoAdapterException; import org.onap.so.openstack.exceptions.MsoCloudSiteNotFound; import org.onap.so.openstack.exceptions.MsoException; import org.onap.so.openstack.exceptions.MsoOpenstackException; +import org.onap.so.openstack.mappers.StackInfoMapper; import org.onap.so.utils.TargetEntity; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -195,7 +197,7 @@ public class MsoMulticloudUtils extends MsoHeatUtils implements VduPlugin { logger.debug(String.format("Multicloud Request is: %s", multicloudRequest.toString())); } - String multicloudEndpoint = getMulticloudEndpoint(cloudSiteId, cloudOwner, null); + String multicloudEndpoint = getMulticloudEndpoint(cloudSiteId, cloudOwner, null, false); RestClient multicloudClient = getMulticloudClient(multicloudEndpoint, tenantId); if (multicloudClient == null) { @@ -222,8 +224,7 @@ public class MsoMulticloudUtils extends MsoHeatUtils implements VduPlugin { timeoutMinutes, backout); if (HeatStatus.CREATED.equals(stackStatus.getStatus())) { - String workloadId = multicloudResponseBody == null ? null : multicloudResponseBody.getWorkloadId(); - multicloudAaiUpdate(cloudSiteId, cloudOwner, tenantId, genericVnfId, vfModuleId, workloadId, + multicloudAaiUpdate(cloudSiteId, cloudOwner, tenantId, genericVnfId, vfModuleId, canonicalName, pollForCompletion, timeoutMinutes); } @@ -268,6 +269,7 @@ public class MsoMulticloudUtils extends MsoHeatUtils implements VduPlugin { } String stackName = null; String stackId = null; + boolean byName = false; int offset = instanceId.indexOf('/'); if (offset > 0 && offset < (instanceId.length() - 1)) { stackName = instanceId.substring(0, offset); @@ -275,12 +277,13 @@ public class MsoMulticloudUtils extends MsoHeatUtils implements VduPlugin { } else { stackName = instanceId; stackId = instanceId; + byName = true; } StackInfo returnInfo = new StackInfo(); returnInfo.setName(stackName); - String multicloudEndpoint = getMulticloudEndpoint(cloudSiteId, cloudOwner, stackId); + String multicloudEndpoint = getMulticloudEndpoint(cloudSiteId, cloudOwner, stackId, byName); RestClient multicloudClient = getMulticloudClient(multicloudEndpoint, tenantId); if (multicloudClient != null) { @@ -289,24 +292,36 @@ public class MsoMulticloudUtils extends MsoHeatUtils implements VduPlugin { logger.debug(String.format("Multicloud GET Response: %s", response.toString())); } - MulticloudQueryResponse multicloudQueryBody = null; + MulticloudQueryResponse responseBody = null; if (response.getStatus() == Response.Status.NOT_FOUND.getStatusCode()) { returnInfo.setStatus(HeatStatus.NOTFOUND); returnInfo.setStatusMessage(response.getStatusInfo().getReasonPhrase()); } else if (response.getStatus() == Response.Status.OK.getStatusCode() && response.hasEntity()) { - multicloudQueryBody = getQueryBody((java.io.InputStream) response.getEntity()); - if (multicloudQueryBody != null) { - returnInfo.setCanonicalName(stackName + "/" + multicloudQueryBody.getWorkloadId()); - returnInfo.setStatus(getHeatStatus(multicloudQueryBody.getWorkloadStatus())); - returnInfo.setStatusMessage(multicloudQueryBody.getWorkloadStatus()); + responseBody = getQueryBody((java.io.InputStream) response.getEntity()); + if (responseBody != null) { if (logger.isDebugEnabled()) { - logger.debug("Multicloud Create Response Body: " + multicloudQueryBody.toString()); + logger.debug("Multicloud Create Response Body: " + responseBody.toString()); + } + Stack workloadStack = getWorkloadStack(responseBody.getWorkloadStatusReason()); + if (workloadStack != null && !responseBody.getWorkloadStatus().equals("GET_FAILED") + && !responseBody.getWorkloadStatus().contains("UPDATE")) { + returnInfo = new StackInfoMapper(workloadStack).map(); + } else { + returnInfo.setCanonicalName(stackName + "/" + responseBody.getWorkloadId()); + returnInfo.setStatus(getHeatStatus(responseBody.getWorkloadStatus())); + returnInfo.setStatusMessage(responseBody.getWorkloadStatus()); } } else { + returnInfo.setName(stackName); + if (!byName) + returnInfo.setCanonicalName(instanceId); returnInfo.setStatus(HeatStatus.FAILED); returnInfo.setStatusMessage(MULTICLOUD_QUERY_BODY_NULL); } } else { + returnInfo.setName(stackName); + if (!byName) + returnInfo.setCanonicalName(instanceId); returnInfo.setStatus(HeatStatus.FAILED); returnInfo.setStatusMessage(response.getStatusInfo().getReasonPhrase()); } @@ -315,6 +330,35 @@ public class MsoMulticloudUtils extends MsoHeatUtils implements VduPlugin { return returnInfo; } + private Stack getWorkloadStack(JsonNode node) { + if (node == null) + return null; + Stack workloadStack = null; + if (node.has("stacks")) { + try { + if (!node.at("/stacks/0").isNull() && node.at("/stacks/0").has("stack_status")) { + workloadStack = JSON_MAPPER.treeToValue(node.at("/stacks/0"), Stack.class); + } else { + workloadStack = new Stack(); + workloadStack.setStackStatus(HeatStatus.NOTFOUND.toString()); + } + } catch (Exception e) { + logger.debug("Multicloud Get Exception mapping /stack/0: {} ", node.toString(), e); + } + } else if (node.has("stack")) { + try { + if (node.at("/stack").has("stack_status")) { + workloadStack = JSON_MAPPER.treeToValue(node.at("/stack"), Stack.class); + } + } catch (Exception e) { + logger.debug("Multicloud Get Exception mapping /stack: {} ", node.toString(), e); + } + } + if (workloadStack != null) + logger.debug("Multicloud getWorkloadStack() returning Stack Object: {} ", workloadStack.toString()); + return workloadStack; + } + public StackInfo deleteStack(String cloudSiteId, String cloudOwner, String tenantId, String instanceId) throws MsoException { if (logger.isDebugEnabled()) { @@ -335,7 +379,7 @@ public class MsoMulticloudUtils extends MsoHeatUtils implements VduPlugin { returnInfo.setName(stackName); Response response = null; - String multicloudEndpoint = getMulticloudEndpoint(cloudSiteId, cloudOwner, stackId); + String multicloudEndpoint = getMulticloudEndpoint(cloudSiteId, cloudOwner, stackId, false); RestClient multicloudClient = getMulticloudClient(multicloudEndpoint, tenantId); if (multicloudClient != null) { @@ -389,12 +433,20 @@ public class MsoMulticloudUtils extends MsoHeatUtils implements VduPlugin { private void multicloudAaiUpdate(String cloudSiteId, String cloudOwner, String tenantId, String genericVnfId, String vfModuleId, String workloadId, boolean pollForCompletion, int timeoutMinutes) { + String stackId = null; + int offset = workloadId.indexOf('/'); + if (offset > 0 && offset < (workloadId.length() - 1)) { + stackId = workloadId.substring(offset + 1); + } else { + stackId = workloadId; + } + MulticloudRequest multicloudRequest = new MulticloudRequest(); multicloudRequest.setGenericVnfId(genericVnfId); multicloudRequest.setVfModuleId(vfModuleId); - String multicloudEndpoint = getMulticloudEndpoint(cloudSiteId, cloudOwner, workloadId); + String multicloudEndpoint = getMulticloudEndpoint(cloudSiteId, cloudOwner, stackId, false); RestClient multicloudClient = getMulticloudClient(multicloudEndpoint, tenantId); if (multicloudClient == null) { @@ -740,7 +792,7 @@ public class MsoMulticloudUtils extends MsoHeatUtils implements VduPlugin { return null; } - private String getMulticloudEndpoint(String cloudSiteId, String cloudOwner, String workloadId) { + private String getMulticloudEndpoint(String cloudSiteId, String cloudOwner, String workloadId, boolean isName) { String msbIp = System.getenv().get(ONAP_IP); if (null == msbIp || msbIp.isEmpty()) { msbIp = environment.getProperty("mso.msb-ip", DEFAULT_MSB_IP); @@ -751,10 +803,16 @@ public class MsoMulticloudUtils extends MsoHeatUtils implements VduPlugin { String endpoint = UriBuilder.fromPath(path).host(msbIp).port(msbPort).scheme("http").build().toString(); if (workloadId != null) { + String middlepart = null; + if (isName) { + middlepart = "?name="; + } else { + middlepart = "/"; + } if (logger.isDebugEnabled()) { - logger.debug(String.format("Multicloud Endpoint is: %s/%s", endpoint, workloadId)); + logger.debug(String.format("Multicloud Endpoint is: %s%s%s", endpoint, middlepart, workloadId)); } - return String.format("%s/%s", endpoint, workloadId); + return String.format("%s%s%s", endpoint, middlepart, workloadId); } else { if (logger.isDebugEnabled()) { logger.debug(String.format("Multicloud Endpoint is: %s", endpoint)); diff --git a/adapters/mso-adapter-utils/src/main/java/org/onap/so/openstack/utils/MulticloudQueryResponse.java b/adapters/mso-adapter-utils/src/main/java/org/onap/so/openstack/utils/MulticloudQueryResponse.java index ca8f041aae..a22937aea3 100644 --- a/adapters/mso-adapter-utils/src/main/java/org/onap/so/openstack/utils/MulticloudQueryResponse.java +++ b/adapters/mso-adapter-utils/src/main/java/org/onap/so/openstack/utils/MulticloudQueryResponse.java @@ -25,10 +25,11 @@ import com.fasterxml.jackson.annotation.JsonCreator; import com.fasterxml.jackson.annotation.JsonInclude; import com.fasterxml.jackson.annotation.JsonProperty; import com.fasterxml.jackson.annotation.JsonPropertyOrder; +import com.fasterxml.jackson.databind.JsonNode; import org.apache.commons.lang.builder.ToStringBuilder; @JsonInclude(JsonInclude.Include.NON_NULL) -@JsonPropertyOrder({"template_type", "workload_id", "workload_status"}) +@JsonPropertyOrder({"template_type", "workload_id", "workload_status", "workload_status_reason"}) public class MulticloudQueryResponse implements Serializable { private final static long serialVersionUID = -5215028275577848311L; @@ -38,13 +39,17 @@ public class MulticloudQueryResponse implements Serializable { private String workloadId; @JsonProperty("workload_status") private String workloadStatus; + @JsonProperty("workload_status_reason") + private JsonNode workloadStatusReason; @JsonCreator public MulticloudQueryResponse(@JsonProperty("template_type") String templateType, - @JsonProperty("workload_id") String workloadId, @JsonProperty("workload_status") String workloadStatus) { + @JsonProperty("workload_id") String workloadId, @JsonProperty("workload_status") String workloadStatus, + @JsonProperty("workload_status_reason") JsonNode workloadStatusReason) { this.templateType = templateType; this.workloadId = workloadId; this.workloadStatus = workloadStatus; + this.workloadStatusReason = workloadStatusReason; } @JsonProperty("template_type") @@ -77,9 +82,20 @@ public class MulticloudQueryResponse implements Serializable { this.workloadStatus = workloadStatus; } + @JsonProperty("workload_status_reason") + public JsonNode getWorkloadStatusReason() { + return workloadStatusReason; + } + + @JsonProperty("workload_status_reason") + public void setWorkloadStatus(JsonNode workloadStatusReason) { + this.workloadStatusReason = workloadStatusReason; + } + @Override public String toString() { return new ToStringBuilder(this).append("templateType", templateType).append("workloadId", workloadId) - .append("workloadStatus", workloadStatus).toString(); + .append("workloadStatus", workloadStatus).append("workloadStatusReason", workloadStatusReason) + .toString(); } } |