diff options
Diffstat (limited to 'adapters/mso-adapter-utils/src/main/java/org')
42 files changed, 2213 insertions, 1348 deletions
diff --git a/adapters/mso-adapter-utils/src/main/java/org/openecomp/mso/cloud/CloudConfig.java b/adapters/mso-adapter-utils/src/main/java/org/openecomp/mso/cloud/CloudConfig.java index 275241f768..2c15391c81 100644 --- a/adapters/mso-adapter-utils/src/main/java/org/openecomp/mso/cloud/CloudConfig.java +++ b/adapters/mso-adapter-utils/src/main/java/org/openecomp/mso/cloud/CloudConfig.java @@ -7,9 +7,9 @@ * 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. @@ -27,18 +27,22 @@ import java.util.HashMap; import java.util.Map; import java.util.Map.Entry; import java.util.Optional; -import org.codehaus.jackson.annotate.JsonProperty; -import org.codehaus.jackson.map.DeserializationConfig; -import org.codehaus.jackson.map.ObjectMapper; -import org.codehaus.jackson.map.annotate.JsonRootName; + import org.openecomp.mso.logger.MsoLogger; import org.openecomp.mso.openstack.exceptions.MsoCloudIdentityNotFound; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonRootName; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.databind.DeserializationFeature; +import com.fasterxml.jackson.databind.JsonMappingException; +import com.fasterxml.jackson.databind.ObjectMapper; + /** * JavaBean JSON class for a CloudConfig. This bean maps a JSON-format cloud * configuration file to Java. The CloudConfig contains information about - * Openstack cloud configurations. It includes: - * - CloudIdentity objects,representing DCP nodes (Openstack Identity Service) + * Openstack cloud configurations. It includes: + * - CloudIdentity objects,representing DCP nodes (Openstack Identity Service) * - CloudSite objects, representing LCP nodes (Openstack Compute & other services) * * Note that this is only used to access Cloud Configurations loaded from a JSON @@ -46,6 +50,7 @@ import org.openecomp.mso.openstack.exceptions.MsoCloudIdentityNotFound; * * This class also contains methods to query cloud sites and/or identity * services by ID. + * */ @JsonRootName("cloud_config") @@ -61,11 +66,13 @@ public class CloudConfig { @JsonProperty("identity_services") private Map<String, CloudIdentity> identityServices = new HashMap<>(); @JsonProperty("cloud_sites") - private Map<String, CloudSite> cloudSites = new HashMap<>(); + private Map <String, CloudSite> cloudSites = new HashMap <String, CloudSite> (); + @JsonProperty("cloudify_managers") + private Map <String, CloudifyManager> cloudifyManagers = new HashMap <String, CloudifyManager> (); public CloudConfig() { - mapper.enable(DeserializationConfig.Feature.UNWRAP_ROOT_VALUE); - mapper.enable(DeserializationConfig.Feature.ACCEPT_SINGLE_VALUE_AS_ARRAY); + mapper.enable(DeserializationFeature.UNWRAP_ROOT_VALUE); + mapper.enable(DeserializationFeature.ACCEPT_SINGLE_VALUE_AS_ARRAY); } /** @@ -82,6 +89,14 @@ public class CloudConfig { return Collections.unmodifiableMap(cloudSites); } + /** + * Get a Map of all CloudifyManagers that have been loaded. + * @return the Map + */ + public synchronized Map <String, CloudifyManager> getCloudifyManagers () { + return cloudifyManagers; + } + /** * Get a specific CloudSites, based on an ID. The ID is first checked * against the regions, and if no match is found there, then against @@ -98,11 +113,10 @@ public class CloudConfig { if (cloudSites.containsKey(id)) { return Optional.ofNullable(cloudSites.get(id)); } - return Optional.ofNullable(getCloudSiteWithClli(id)); + return null; } - - private CloudSite getCloudSiteWithClli(String clli) { + private CloudSite getCloudSiteWithClli(String clli) { Optional <CloudSite> cloudSiteOptional = cloudSites.values().stream().filter(cs -> cs.getClli() != null && clli.equals(cs.getClli()) && (CLOUD_SITE_VERSION.equals(cs.getAic_version()))) .findAny(); @@ -124,7 +138,7 @@ public class CloudConfig { /** * Get a specific CloudIdentity, based on an ID. - * + * * @param id * the ID to match * @return a CloudIdentity, or null of no match found @@ -136,6 +150,18 @@ public class CloudConfig { return null; } + /** + * Get a specific CloudifyManager, based on an ID. + * @param id the ID to match + * @return a CloudifyManager, or null of no match found + */ + public synchronized CloudifyManager getCloudifyManager (String id) { + if (cloudifyManagers.containsKey (id)) { + return cloudifyManagers.get (id); + } + return null; + } + protected synchronized void reloadPropertiesFile() throws IOException, MsoCloudIdentityNotFound { this.loadCloudConfig(this.configFilePath, this.refreshTimerInMinutes); } @@ -156,12 +182,18 @@ public class CloudConfig { this.cloudSites = cloudConfig.cloudSites; this.identityServices = cloudConfig.identityServices; + this.cloudifyManagers = cloudConfig.cloudifyManagers; // Copy Cloud Identity IDs to CloudIdentity objects for (Entry<String, CloudIdentity> entry : cloudConfig.getIdentityServices().entrySet()) { entry.getValue().setId(entry.getKey()); } + // Copy Cloduify IDs to CloudifyManager objects + for (Entry <String, CloudifyManager> entry : cloudConfig.getCloudifyManagers ().entrySet ()) { + entry.getValue ().setId (entry.getKey ()); + } + // Copy Cloud Site IDs to CloudSite objects, and set up internal // pointers to their corresponding identity service. for (Entry<String, CloudSite> entry : cloudConfig.getCloudSites().entrySet()) { @@ -172,9 +204,11 @@ public class CloudConfig { if (cloudIdentity == null) { throw new MsoCloudIdentityNotFound(s.getId()+" Cloud site refers to a non-existing identity service: "+s.getIdentityServiceId()); } + CloudifyManager cloudifyManager = cloudConfig.getCloudifyManager(s.getCloudifyId()); + s.setCloudifyManager(cloudifyManager); } this.validCloudConfig=true; - + } finally { try { if (reader != null) { @@ -201,11 +235,20 @@ public class CloudConfig { public synchronized CloudConfig clone() { CloudConfig ccCopy = new CloudConfig(); for (Entry<String, CloudIdentity> e : identityServices.entrySet()) { + ccCopy.identityServices.put(e.getKey(), e.getValue().clone()); } + for (Entry<String, CloudSite> e : cloudSites.entrySet()) { + ccCopy.cloudSites.put(e.getKey(), e.getValue().clone()); } + + for (Entry<String,CloudifyManager> e:cloudifyManagers.entrySet()) { + + ccCopy.cloudifyManagers.put(e.getKey(), e.getValue().clone()); + } + ccCopy.configFilePath = this.configFilePath; ccCopy.refreshTimerInMinutes = this.refreshTimerInMinutes; ccCopy.validCloudConfig = this.validCloudConfig; @@ -261,5 +304,5 @@ public class CloudConfig { return true; } - + } diff --git a/adapters/mso-adapter-utils/src/main/java/org/openecomp/mso/cloud/CloudConfigFactory.java b/adapters/mso-adapter-utils/src/main/java/org/openecomp/mso/cloud/CloudConfigFactory.java index 144506c3bd..9f6520cf7e 100644 --- a/adapters/mso-adapter-utils/src/main/java/org/openecomp/mso/cloud/CloudConfigFactory.java +++ b/adapters/mso-adapter-utils/src/main/java/org/openecomp/mso/cloud/CloudConfigFactory.java @@ -34,8 +34,7 @@ import javax.ws.rs.Path; import javax.ws.rs.PathParam; import javax.ws.rs.Produces; import javax.ws.rs.core.Response; -import org.codehaus.jackson.JsonParseException; -import org.codehaus.jackson.map.JsonMappingException; + import org.openecomp.mso.logger.MessageEnum; import org.openecomp.mso.logger.MsoLogger; import org.openecomp.mso.openstack.exceptions.MsoCloudIdentityNotFound; @@ -43,6 +42,9 @@ import org.openecomp.mso.openstack.utils.MsoHeatUtils; import org.openecomp.mso.openstack.utils.MsoKeystoneUtils; import org.openecomp.mso.openstack.utils.MsoNeutronUtils; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.databind.JsonMappingException; + /** * This class returns a cloud Config instances */ diff --git a/adapters/mso-adapter-utils/src/main/java/org/openecomp/mso/cloud/CloudIdentity.java b/adapters/mso-adapter-utils/src/main/java/org/openecomp/mso/cloud/CloudIdentity.java index 3dd4cbfc9c..07f0546256 100644 --- a/adapters/mso-adapter-utils/src/main/java/org/openecomp/mso/cloud/CloudIdentity.java +++ b/adapters/mso-adapter-utils/src/main/java/org/openecomp/mso/cloud/CloudIdentity.java @@ -23,12 +23,12 @@ package org.openecomp.mso.cloud; +import java.security.GeneralSecurityException; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; +import com.fasterxml.jackson.databind.annotation.JsonSerialize; import com.woorea.openstack.keystone.model.Authentication; import com.woorea.openstack.keystone.model.authentication.UsernamePassword; -import java.security.GeneralSecurityException; -import org.codehaus.jackson.annotate.JsonProperty; -import org.codehaus.jackson.map.annotate.JsonDeserialize; -import org.codehaus.jackson.map.annotate.JsonSerialize; import org.openecomp.mso.cloud.authentication.AuthenticationMethodFactory; import org.openecomp.mso.cloud.authentication.AuthenticationWrapper; import org.openecomp.mso.cloud.authentication.wrappers.RackspaceAPIKeyWrapper; diff --git a/adapters/mso-adapter-utils/src/main/java/org/openecomp/mso/cloud/CloudSite.java b/adapters/mso-adapter-utils/src/main/java/org/openecomp/mso/cloud/CloudSite.java index 193931ecca..1d013ebc60 100644 --- a/adapters/mso-adapter-utils/src/main/java/org/openecomp/mso/cloud/CloudSite.java +++ b/adapters/mso-adapter-utils/src/main/java/org/openecomp/mso/cloud/CloudSite.java @@ -21,7 +21,7 @@ package org.openecomp.mso.cloud; -import org.codehaus.jackson.annotate.JsonProperty; +import com.fasterxml.jackson.annotation.JsonProperty; /** * JavaBean JSON class for a CloudSite. This bean represents a cloud location @@ -44,9 +44,17 @@ public class CloudSite { private String aic_version; @JsonProperty("clli") private String clli; + @JsonProperty("cloudify_id") + private String cloudifyId; + @JsonProperty("platform") + private String platform; + @JsonProperty("orchestrator") + private String orchestrator; // Derived property (set by CloudConfig loader based on identityServiceId) private CloudIdentity identityService; + // Derived property (set by CloudConfig loader based on cloudifyId) + private CloudifyManager cloudifyManager; public CloudSite() {} @@ -93,13 +101,48 @@ public class CloudSite { this.clli = clli; } + public String getCloudifyId() { + return cloudifyId; + } + + public void setCloudifyId (String id) { + this.cloudifyId = id; + } + + public CloudifyManager getCloudifyManager () { + return cloudifyManager; + } + + public void setCloudifyManager (CloudifyManager cloudify) { + this.cloudifyManager = cloudify; + } + + public String getPlatform() { + return platform; + } + + public void setPlatform(String platform) { + this.platform = platform; + } + + public String getOrchestrator() { + return orchestrator; + } + + public void setOrchestrator(String orchestrator) { + this.orchestrator = orchestrator; + } + @Override public String toString() { return "CloudSite: id=" + id + ", regionId=" + regionId + ", identityServiceId=" + identityServiceId + ", aic_version=" + aic_version + - ", clli=" + clli; + ", clli=" + clli + + ", cloudifyId=" + cloudifyId + + ", platform=" + platform + + ", orchestrator=" + orchestrator; } @Override @@ -111,6 +154,11 @@ public class CloudSite { cloudSiteCopy.aic_version = this.aic_version; cloudSiteCopy.clli = this.clli; cloudSiteCopy.identityService = this.identityService.clone(); + cloudSiteCopy.cloudifyId = this.cloudifyId; + if (this.cloudifyManager != null) cloudSiteCopy.cloudifyManager = this.cloudifyManager.clone(); + cloudSiteCopy.platform = this.platform; + cloudSiteCopy.orchestrator = this.orchestrator; + return cloudSiteCopy; } diff --git a/adapters/mso-adapter-utils/src/main/java/org/openecomp/mso/cloud/CloudifyManager.java b/adapters/mso-adapter-utils/src/main/java/org/openecomp/mso/cloud/CloudifyManager.java new file mode 100644 index 0000000000..98f2266216 --- /dev/null +++ b/adapters/mso-adapter-utils/src/main/java/org/openecomp/mso/cloud/CloudifyManager.java @@ -0,0 +1,169 @@ +/*- + * ============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.cloud; + +import java.security.GeneralSecurityException; + +import com.fasterxml.jackson.annotation.JsonProperty; + +import org.openecomp.mso.utils.CryptoUtils; +import org.openecomp.mso.logger.MessageEnum; +import org.openecomp.mso.logger.MsoLogger; + +/** + * JavaBean JSON class for a Cloudify Manager. This bean represents a Cloudify + * node through which TOSCA-based VNFs may be deployed. Each CloudSite in the + * CloudConfig may have a Cloudify Manager for deployments using TOSCA blueprints. + * Cloudify Managers may support multiple Cloud Sites, but each site will have + * at most one Cloudify Manager. + * + * This does not replace the ability to use the CloudSite directly via Openstack. + * + * Note that this is only used to access Cloud Configurations loaded from a + * JSON config file, so there are no explicit setters. + * + * @author JC1348 + */ +public class CloudifyManager { + + private static MsoLogger LOGGER = MsoLogger.getMsoLogger (MsoLogger.Catalog.RA); + + @JsonProperty + private String id; + @JsonProperty ("cloudify_url") + private String cloudifyUrl; + @JsonProperty("username") + private String username; + @JsonProperty("password") + private String password; + @JsonProperty("version") + private String version; + + private static String cloudKey = "aa3871669d893c7fb8abbcda31b88b4f"; + + public CloudifyManager() {} + + public String getId() { + return id; + } + public void setId(String id) { + this.id = id; + } + + public String getCloudifyUrl() { + return cloudifyUrl; + } + + public void setCloudifyUrl(String cloudifyUrl) { + this.cloudifyUrl = cloudifyUrl; + } + + public String getUsername() { + return username; + } + + public void setUsername(String username) { + this.username = username; + } + + public String getPassword() { + try { + return CryptoUtils.decrypt (password, cloudKey); + } catch (GeneralSecurityException e) { + LOGGER.error (MessageEnum.RA_GENERAL_EXCEPTION, "", "", MsoLogger.ErrorCode.BusinessProcesssError, "Exception in getMsoPass", e); + return null; + } + } + + public void setPassword(String password) { + this.password = password; + } + + public String getVersion() { + return version; + } + + public void setVersion(String version) { + this.version = version; + } + + + @Override + public String toString() { + return "CloudifyManager: id=" + id + + ", cloudifyUrl=" + cloudifyUrl + + ", username=" + username + + ", password=" + password + + ", version=" + version; + } + + @Override + public CloudifyManager clone() { + CloudifyManager cloudifyManagerCopy = new CloudifyManager(); + cloudifyManagerCopy.id = this.id; + cloudifyManagerCopy.cloudifyUrl = this.cloudifyUrl; + cloudifyManagerCopy.username = this.username; + cloudifyManagerCopy.password = this.password; + cloudifyManagerCopy.version = this.version; + return cloudifyManagerCopy; + } + + @Override + public int hashCode() { + final int prime = 31; + int result = 1; + result = prime * result + ((id == null) ? 0 : id.hashCode()); + result = prime * result + ((cloudifyUrl == null) ? 0 : cloudifyUrl.hashCode()); + result = prime * result + ((username == null) ? 0 : username.hashCode()); + result = prime * result + ((password == null) ? 0 : password.hashCode()); + result = prime * result + ((version == null) ? 0 : version.hashCode()); + return result; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) + return true; + if (obj == null) + return false; + if (getClass() != obj.getClass()) + return false; + CloudifyManager other = (CloudifyManager) obj; + if (!cmp(id, other.id)) + return false; + if (!cmp(cloudifyUrl, other.cloudifyUrl)) + return false; + if (!cmp(username, other.username)) + return false; + if (!cmp(version, other.version)) + return false; + if (!cmp(password, other.password)) + return false; + return true; + } + private boolean cmp(Object a, Object b) { + if (a == null) { + return (b == null); + } else { + return a.equals(b); + } + } +} diff --git a/adapters/mso-adapter-utils/src/main/java/org/openecomp/mso/cloud/IdentityAuthenticationTypeJsonDeserializer.java b/adapters/mso-adapter-utils/src/main/java/org/openecomp/mso/cloud/IdentityAuthenticationTypeJsonDeserializer.java index dcd8de79aa..2b50c2690c 100644 --- a/adapters/mso-adapter-utils/src/main/java/org/openecomp/mso/cloud/IdentityAuthenticationTypeJsonDeserializer.java +++ b/adapters/mso-adapter-utils/src/main/java/org/openecomp/mso/cloud/IdentityAuthenticationTypeJsonDeserializer.java @@ -21,16 +21,17 @@ package org.openecomp.mso.cloud; import java.io.IOException;
-import org.codehaus.jackson.JsonParser;
-import org.codehaus.jackson.JsonToken;
-import org.codehaus.jackson.map.DeserializationContext;
-import org.codehaus.jackson.map.JsonDeserializer;
+import com.fasterxml.jackson.core.JsonParser;
+import com.fasterxml.jackson.core.JsonProcessingException;
+import com.fasterxml.jackson.core.JsonToken;
+import com.fasterxml.jackson.databind.DeserializationContext;
+import com.fasterxml.jackson.databind.JsonDeserializer;
public class IdentityAuthenticationTypeJsonDeserializer extends JsonDeserializer<IdentityAuthenticationTypeAbstract> {
@Override
public IdentityAuthenticationTypeAbstract deserialize(JsonParser jsonParser, DeserializationContext deserializationContext)
- throws IOException {
+ throws IOException, JsonProcessingException {
JsonToken token = jsonParser.getCurrentToken();
if (JsonToken.VALUE_STRING.equals(token)) {
return IdentityAuthenticationTypeAbstract.valueOf(jsonParser.getText());
diff --git a/adapters/mso-adapter-utils/src/main/java/org/openecomp/mso/cloud/IdentityAuthenticationTypeJsonSerializer.java b/adapters/mso-adapter-utils/src/main/java/org/openecomp/mso/cloud/IdentityAuthenticationTypeJsonSerializer.java index 052f09ab85..065010035c 100644 --- a/adapters/mso-adapter-utils/src/main/java/org/openecomp/mso/cloud/IdentityAuthenticationTypeJsonSerializer.java +++ b/adapters/mso-adapter-utils/src/main/java/org/openecomp/mso/cloud/IdentityAuthenticationTypeJsonSerializer.java @@ -21,9 +21,9 @@ package org.openecomp.mso.cloud; import java.io.IOException;
-import org.codehaus.jackson.JsonGenerator;
-import org.codehaus.jackson.map.JsonSerializer;
-import org.codehaus.jackson.map.SerializerProvider;
+import com.fasterxml.jackson.core.JsonGenerator;
+import com.fasterxml.jackson.databind.JsonSerializer;
+import com.fasterxml.jackson.databind.SerializerProvider;
public class IdentityAuthenticationTypeJsonSerializer extends JsonSerializer<IdentityAuthenticationTypeAbstract> {
diff --git a/adapters/mso-adapter-utils/src/main/java/org/openecomp/mso/cloud/IdentityServerTypeJsonDeserializer.java b/adapters/mso-adapter-utils/src/main/java/org/openecomp/mso/cloud/IdentityServerTypeJsonDeserializer.java index bb8a3f1fd9..093f7ff38b 100644 --- a/adapters/mso-adapter-utils/src/main/java/org/openecomp/mso/cloud/IdentityServerTypeJsonDeserializer.java +++ b/adapters/mso-adapter-utils/src/main/java/org/openecomp/mso/cloud/IdentityServerTypeJsonDeserializer.java @@ -23,16 +23,18 @@ package org.openecomp.mso.cloud; import java.io.IOException;
-import org.codehaus.jackson.JsonParser;
-import org.codehaus.jackson.JsonToken;
-import org.codehaus.jackson.map.DeserializationContext;
-import org.codehaus.jackson.map.JsonDeserializer;
+import com.fasterxml.jackson.core.JsonParser;
+import com.fasterxml.jackson.core.JsonProcessingException;
+import com.fasterxml.jackson.core.JsonToken;
+import com.fasterxml.jackson.databind.DeserializationContext;
+import com.fasterxml.jackson.databind.JsonDeserializer;
+
public class IdentityServerTypeJsonDeserializer extends JsonDeserializer<IdentityServerTypeAbstract> {
@Override
public IdentityServerTypeAbstract deserialize(JsonParser jsonParser, DeserializationContext deserializationContext)
- throws IOException {
+ throws IOException, JsonProcessingException {
JsonToken token = jsonParser.getCurrentToken();
if (JsonToken.VALUE_STRING.equals(token)) {
return IdentityServerTypeAbstract.valueOf(jsonParser.getText());
diff --git a/adapters/mso-adapter-utils/src/main/java/org/openecomp/mso/cloud/IdentityServerTypeJsonSerializer.java b/adapters/mso-adapter-utils/src/main/java/org/openecomp/mso/cloud/IdentityServerTypeJsonSerializer.java index a05d0b8872..d2662a1622 100644 --- a/adapters/mso-adapter-utils/src/main/java/org/openecomp/mso/cloud/IdentityServerTypeJsonSerializer.java +++ b/adapters/mso-adapter-utils/src/main/java/org/openecomp/mso/cloud/IdentityServerTypeJsonSerializer.java @@ -21,15 +21,17 @@ package org.openecomp.mso.cloud; import java.io.IOException;
-import org.codehaus.jackson.JsonGenerator;
-import org.codehaus.jackson.map.JsonSerializer;
-import org.codehaus.jackson.map.SerializerProvider;
+import com.fasterxml.jackson.core.JsonGenerator;
+import com.fasterxml.jackson.core.JsonProcessingException;
+import com.fasterxml.jackson.databind.JsonSerializer;
+import com.fasterxml.jackson.databind.SerializerProvider;
+
public class IdentityServerTypeJsonSerializer extends JsonSerializer<IdentityServerTypeAbstract> {
@Override
public void serialize(IdentityServerTypeAbstract tmpObj, JsonGenerator jsonGenerator, SerializerProvider serializerProvider)
- throws IOException {
+ throws IOException, JsonProcessingException {
jsonGenerator.writeObject(tmpObj.toString());
}
}
diff --git a/adapters/mso-adapter-utils/src/main/java/org/openecomp/mso/cloud/authentication/models/RackspaceAuthentication.java b/adapters/mso-adapter-utils/src/main/java/org/openecomp/mso/cloud/authentication/models/RackspaceAuthentication.java index c96b809ff9..6c00349b85 100644 --- a/adapters/mso-adapter-utils/src/main/java/org/openecomp/mso/cloud/authentication/models/RackspaceAuthentication.java +++ b/adapters/mso-adapter-utils/src/main/java/org/openecomp/mso/cloud/authentication/models/RackspaceAuthentication.java @@ -23,8 +23,9 @@ package org.openecomp.mso.cloud.authentication.models; -import org.codehaus.jackson.annotate.JsonProperty; -import org.codehaus.jackson.map.annotate.JsonRootName; +import com.fasterxml.jackson.annotation.JsonIgnore; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonRootName; import com.woorea.openstack.keystone.model.Authentication; @JsonRootName("auth") diff --git a/adapters/mso-adapter-utils/src/main/java/org/openecomp/mso/cloudify/beans/DeploymentInfo.java b/adapters/mso-adapter-utils/src/main/java/org/openecomp/mso/cloudify/beans/DeploymentInfo.java new file mode 100644 index 0000000000..9387e22f38 --- /dev/null +++ b/adapters/mso-adapter-utils/src/main/java/org/openecomp/mso/cloudify/beans/DeploymentInfo.java @@ -0,0 +1,186 @@ +/*- + * ============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.cloudify.beans; + +import java.util.Map; +import java.util.HashMap; + +import org.openecomp.mso.cloudify.v3.model.Deployment; +import org.openecomp.mso.cloudify.v3.model.DeploymentOutputs; +import org.openecomp.mso.cloudify.v3.model.Execution; + +/* + * This Java bean class relays Heat stack status information to ActiveVOS processes. + * + * This bean is returned by all Heat-specific adapter operations (create, query, delete) + */ + +public class DeploymentInfo { + // Set defaults for everything + private String id = ""; + private DeploymentStatus status = DeploymentStatus.NOTFOUND; + private Map<String,Object> outputs = new HashMap<String,Object>(); + private Map<String,Object> inputs = new HashMap<String,Object>(); + private String lastAction; + private String actionStatus; + private String errorMessage; + + public DeploymentInfo () { + } + + public DeploymentInfo (String id, Map<String,Object> outputs) { + this.id = id; + if (outputs != null) this.outputs = outputs; + } + + public DeploymentInfo (String id) { + this.id = id; + } + + public DeploymentInfo (String id, DeploymentStatus status) { + this.id = id; + this.status = status; + } + + public DeploymentInfo (Deployment deployment) { + this(deployment, null, null); + } + + /** + * Construct a DeploymentInfo object from a deployment and the latest Execution action + * @param deployment + * @param execution + */ + public DeploymentInfo (Deployment deployment, DeploymentOutputs outputs, Execution execution) + { + if (deployment == null) { + this.id = null; + return; + } + + this.id = deployment.getId(); + + if (outputs != null) + this.outputs = outputs.getOutputs(); + + if (deployment.getInputs() != null) + this.inputs = deployment.getInputs(); + + if (execution != null) { + this.lastAction = execution.getWorkflowId(); + this.actionStatus = execution.getStatus(); + this.errorMessage = execution.getError(); + + // Compute the status based on the last workflow + if (lastAction.equals("install")) { + if (actionStatus.equals("terminated")) + this.status = DeploymentStatus.INSTALLED; + else if (actionStatus.equals("failed")) + this.status = DeploymentStatus.FAILED; + else if (actionStatus.equals("started") || actionStatus.equals("pending")) + this.status = DeploymentStatus.INSTALLING; + else + this.status = DeploymentStatus.UNKNOWN; + } + else if (lastAction.equals("uninstall")) { + if (actionStatus.equals("terminated")) + this.status = DeploymentStatus.CREATED; + else if (actionStatus.equals("failed")) + this.status = DeploymentStatus.FAILED; + else if (actionStatus.equals("started") || actionStatus.equals("pending")) + this.status = DeploymentStatus.UNINSTALLING; + else + this.status = DeploymentStatus.UNKNOWN; + } + else { + // Could have more cases in the future for different actions. + this.status = DeploymentStatus.UNKNOWN; + } + } + else { + this.status = DeploymentStatus.CREATED; + } + } + + public String getId() { + return id; + } + + public void setId (String id) { + this.id = id; + } + + public DeploymentStatus getStatus() { + return status; + } + + public void setStatus (DeploymentStatus status) { + this.status = status; + } + + public Map<String,Object> getOutputs () { + return outputs; + } + + public void setOutputs (Map<String,Object> outputs) { + this.outputs = outputs; + } + + public Map<String,Object> getInputs () { + return inputs; + } + + public void setInputs (Map<String,Object> inputs) { + this.inputs = inputs; + } + + public String getLastAction() { + return lastAction; + } + + public String getActionStatus() { + return actionStatus; + } + + public String getErrorMessage() { + return errorMessage; + } + + public void saveExecutionStatus (Execution execution) { + this.lastAction = execution.getWorkflowId(); + this.actionStatus = execution.getStatus(); + this.errorMessage = execution.getError(); + } + + @Override + public String toString() { + return "DeploymentInfo {" + + "id='" + id + '\'' + + ", inputs='" + inputs + '\'' + + ", outputs='" + outputs + '\'' + + ", lastAction='" + lastAction + '\'' + + ", status='" + status + '\'' + + ", errorMessage='" + errorMessage + '\'' + + '}'; + } + +} + diff --git a/adapters/mso-adapter-utils/src/main/java/org/openecomp/mso/openstack/beans/VnfStatus.java b/adapters/mso-adapter-utils/src/main/java/org/openecomp/mso/cloudify/beans/DeploymentStatus.java index cc7e66eecb..cef5e78c20 100644 --- a/adapters/mso-adapter-utils/src/main/java/org/openecomp/mso/openstack/beans/VnfStatus.java +++ b/adapters/mso-adapter-utils/src/main/java/org/openecomp/mso/cloudify/beans/DeploymentStatus.java @@ -18,13 +18,14 @@ * ============LICENSE_END========================================================= */ -package org.openecomp.mso.openstack.beans; +package org.openecomp.mso.cloudify.beans; /* - * Enum status values to mirror the Openstack Heat stack status values + * Enum status values to capture the state of a deployment, based on last known workflow + * (assume only INSTALL and UNINSTALL at this point). */ -public enum VnfStatus { - ACTIVE, FAILED, NOTFOUND, UNKNOWN +public enum DeploymentStatus { + NOTFOUND, CREATED, INSTALLED, FAILED, INSTALLING, UNINSTALLING, UNKNOWN } diff --git a/adapters/mso-adapter-utils/src/main/java/org/openecomp/mso/openstack/exceptions/MsoNetworkNotFound.java b/adapters/mso-adapter-utils/src/main/java/org/openecomp/mso/cloudify/exceptions/MsoBlueprintAlreadyExists.java index 5802aa1208..1bdd6f3850 100644 --- a/adapters/mso-adapter-utils/src/main/java/org/openecomp/mso/openstack/exceptions/MsoNetworkNotFound.java +++ b/adapters/mso-adapter-utils/src/main/java/org/openecomp/mso/cloudify/exceptions/MsoBlueprintAlreadyExists.java @@ -7,9 +7,9 @@ * 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. @@ -18,18 +18,16 @@ * ============LICENSE_END========================================================= */ -package org.openecomp.mso.openstack.exceptions; +package org.openecomp.mso.cloudify.exceptions; - - -public class MsoNetworkNotFound extends MsoOpenstackException { +public class MsoBlueprintAlreadyExists extends MsoCloudifyException { private static final long serialVersionUID = 1L; - // Constructor to create a new MsoOpenstackException instance - public MsoNetworkNotFound (String networkId, String tenant, String cloud) { + // Constructor to create a new MsoCloudifyException instance + public MsoBlueprintAlreadyExists (String blueprintId, String cloud) { // Set the detailed error as the Exception 'message' - super(404, "Not Found", "Network " + networkId + " does not exist in Cloud/Tenant " + cloud + "/" + tenant); + super(409, "Conflict", "Blueprint " + blueprintId + " already exists in Cloudify Manager supporting cloud site + " + cloud); } } diff --git a/adapters/mso-adapter-utils/src/main/java/org/openecomp/mso/openstack/exceptions/MsoOpenstackException.java b/adapters/mso-adapter-utils/src/main/java/org/openecomp/mso/cloudify/exceptions/MsoCloudifyException.java index eead8439d4..f2469f4706 100644 --- a/adapters/mso-adapter-utils/src/main/java/org/openecomp/mso/openstack/exceptions/MsoOpenstackException.java +++ b/adapters/mso-adapter-utils/src/main/java/org/openecomp/mso/cloudify/exceptions/MsoCloudifyException.java @@ -7,9 +7,9 @@ * 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. @@ -18,13 +18,15 @@ * ============LICENSE_END========================================================= */ -package org.openecomp.mso.openstack.exceptions; +package org.openecomp.mso.cloudify.exceptions; +import org.openecomp.mso.openstack.exceptions.MsoException; +import org.openecomp.mso.openstack.exceptions.MsoExceptionCategory; /** * OpenStack exception. */ -public class MsoOpenstackException extends MsoException +public class MsoCloudifyException extends MsoException { /** @@ -35,6 +37,7 @@ public class MsoOpenstackException extends MsoException private int statusCode; private String statusMessage; private String errorDetail; + private boolean pendingWorkflow; /** * Constructor to create a new MsoOpenstackException instance @@ -42,7 +45,7 @@ public class MsoOpenstackException extends MsoException * @param message the error message * @param detail error details */ - public MsoOpenstackException (int code, String message, String detail) { + public MsoCloudifyException (int code, String message, String detail) { // Set the detailed error as the Exception 'message' super(detail); super.category = MsoExceptionCategory.OPENSTACK; @@ -50,6 +53,7 @@ public class MsoOpenstackException extends MsoException this.statusCode = code; this.statusMessage = message; this.errorDetail = detail; + this.pendingWorkflow = false; } /** @@ -59,7 +63,7 @@ public class MsoOpenstackException extends MsoException * @param detail error details * @param e the cause */ - public MsoOpenstackException (int code, String message, String detail, Exception e) { + public MsoCloudifyException (int code, String message, String detail, Exception e) { // Set the detailed error as the Exception 'message' super(detail, e); super.category = MsoExceptionCategory.OPENSTACK; @@ -67,14 +71,16 @@ public class MsoOpenstackException extends MsoException this.statusCode = code; this.statusMessage = message; this.errorDetail = detail; + this.pendingWorkflow = false; } - + + public void setPendingWorkflow (boolean pendingWorkflow) { + this.pendingWorkflow = pendingWorkflow; + } + @Override - public String toString() { - return statusCode + - " " + - statusMessage + - ": " + - errorDetail; + public String toString () { + String error = "" + statusCode + " " + statusMessage + ": " + errorDetail + (pendingWorkflow ? " [workflow pending]" : ""); + return error; } } diff --git a/adapters/mso-adapter-utils/src/main/java/org/openecomp/mso/openstack/exceptions/MsoTenantAlreadyExists.java b/adapters/mso-adapter-utils/src/main/java/org/openecomp/mso/cloudify/exceptions/MsoCloudifyManagerNotFound.java index 7a597d6f4d..601e5b78ea 100644 --- a/adapters/mso-adapter-utils/src/main/java/org/openecomp/mso/openstack/exceptions/MsoTenantAlreadyExists.java +++ b/adapters/mso-adapter-utils/src/main/java/org/openecomp/mso/cloudify/exceptions/MsoCloudifyManagerNotFound.java @@ -18,15 +18,16 @@ * ============LICENSE_END========================================================= */ -package org.openecomp.mso.openstack.exceptions; +package org.openecomp.mso.cloudify.exceptions; -public class MsoTenantAlreadyExists extends MsoOpenstackException { +public class MsoCloudifyManagerNotFound extends MsoCloudifyException { private static final long serialVersionUID = 1L; - public MsoTenantAlreadyExists (String tenant, String cloud) { + // Constructor to create a new MsoCloudifyException instance + public MsoCloudifyManagerNotFound (String cloudSiteId) { // Set the detailed error as the Exception 'message' - super(409, "Conflict", "Tenant " + tenant + " already exists in Cloud " + cloud); + super(0, "Cloudify Manager Not Found", "No Cloudify Manager configured for cloud site " + cloudSiteId); } - + } diff --git a/adapters/mso-adapter-utils/src/main/java/org/openecomp/mso/cloudify/exceptions/MsoCloudifyTimeout.java b/adapters/mso-adapter-utils/src/main/java/org/openecomp/mso/cloudify/exceptions/MsoCloudifyTimeout.java new file mode 100644 index 0000000000..ba1e2a721b --- /dev/null +++ b/adapters/mso-adapter-utils/src/main/java/org/openecomp/mso/cloudify/exceptions/MsoCloudifyTimeout.java @@ -0,0 +1,64 @@ +/*- + * ============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.cloudify.exceptions; + +import org.openecomp.mso.cloudify.v3.model.Execution; +import org.openecomp.mso.openstack.exceptions.MsoException; +import org.openecomp.mso.openstack.exceptions.MsoExceptionCategory; + +/** + * MSO Exception when a Cloudify workflow execution times out waiting for completion. + * Exception includes the last known state of the workflow execution. + */ +public class MsoCloudifyTimeout extends MsoException +{ + + /** + * Serialization id. + */ + private static final long serialVersionUID = 3313636124141766495L; + + private Execution execution; + + /** + * Constructor to create a new MsoOpenstackException instance + * @param code the error code + * @param message the error message + * @param detail error details + */ + public MsoCloudifyTimeout (Execution execution) { + // Set the detailed error as the Exception 'message' + super("Cloudify Workflow Timeout for workflow " + execution.getWorkflowId() + " on deployment " + execution.getDeploymentId()); + super.category = MsoExceptionCategory.OPENSTACK; + + this.execution = execution; + } + + public Execution getExecution() { + return this.execution; + } + + @Override + public String toString () { + String error = "Workflow timeout: workflow=" + execution.getWorkflowId() + ",deployment=" + execution.getDeploymentId(); + return error; + } +} diff --git a/adapters/mso-adapter-utils/src/main/java/org/openecomp/mso/openstack/exceptions/MsoAdapterException.java b/adapters/mso-adapter-utils/src/main/java/org/openecomp/mso/cloudify/exceptions/MsoCloudifyWorkflowException.java index 454880cee1..a397135667 100644 --- a/adapters/mso-adapter-utils/src/main/java/org/openecomp/mso/openstack/exceptions/MsoAdapterException.java +++ b/adapters/mso-adapter-utils/src/main/java/org/openecomp/mso/cloudify/exceptions/MsoCloudifyWorkflowException.java @@ -7,9 +7,9 @@ * 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. @@ -18,28 +18,37 @@ * ============LICENSE_END========================================================= */ -package org.openecomp.mso.openstack.exceptions; - - +package org.openecomp.mso.cloudify.exceptions; /** - * General MSO Exception class for any non-specific errors. - * + * Reports an error with a Cloudify Workflow execution. + * @author JC1348 * */ -public class MsoAdapterException extends MsoException -{ +public class MsoCloudifyWorkflowException extends MsoCloudifyException { + private static final long serialVersionUID = 1L; + + private String workflowStatus; + private boolean workflowStillRunning = false; - // Constructor to create a new MsoException instance - public MsoAdapterException (String message) { - super(message); - super.category = MsoExceptionCategory.INTERNAL; + // Constructor to create a new MsoCloudifyException instance + public MsoCloudifyWorkflowException (String message, String deploymentId, String workflowId, String workflowStatus) + { + super(0, "Workflow Exception", "Workflow " + workflowId + " failed on deployment " + deploymentId + ": " + message); + this.workflowStatus = workflowStatus; + if (workflowStatus.equals("pending") || workflowStatus.equals("started") || + workflowStatus.equals("cancelling") || workflowStatus.equals("force_cancelling")) + { + workflowStillRunning = true; + } } - - // Constructor to wrap a nested exception - public MsoAdapterException (String message, Throwable t) { - super(message, t); - super.category = MsoExceptionCategory.INTERNAL; + + public String getWorkflowStatus() { + return workflowStatus; + } + + public boolean isWorkflowStillRunning () { + return workflowStillRunning; } } diff --git a/adapters/mso-adapter-utils/src/main/java/org/openecomp/mso/openstack/exceptions/MsoNetworkAlreadyExists.java b/adapters/mso-adapter-utils/src/main/java/org/openecomp/mso/cloudify/exceptions/MsoDeploymentAlreadyExists.java index 98b85394be..37f97a8ce9 100644 --- a/adapters/mso-adapter-utils/src/main/java/org/openecomp/mso/openstack/exceptions/MsoNetworkAlreadyExists.java +++ b/adapters/mso-adapter-utils/src/main/java/org/openecomp/mso/cloudify/exceptions/MsoDeploymentAlreadyExists.java @@ -7,9 +7,9 @@ * 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. @@ -18,18 +18,16 @@ * ============LICENSE_END========================================================= */ -package org.openecomp.mso.openstack.exceptions; +package org.openecomp.mso.cloudify.exceptions; - - -public class MsoNetworkAlreadyExists extends MsoOpenstackException { +public class MsoDeploymentAlreadyExists extends MsoCloudifyException { private static final long serialVersionUID = 1L; - // Constructor to create a new MsoOpenstackException instance - public MsoNetworkAlreadyExists (String stack, String tenant, String cloud) { + // Constructor to create a new MsoCloudifyException instance + public MsoDeploymentAlreadyExists (String deploymentId, String cloud) { // Set the detailed error as the Exception 'message' - super(409, "Conflict", "Stack " + stack + " already exists in Tenant + " + tenant + " in Cloud " + cloud); + super(409, "Conflict", "Deployment " + deploymentId + " already exists in Cloudify Manager suppporting cloud " + cloud); } } diff --git a/adapters/mso-adapter-utils/src/main/java/org/openecomp/mso/cloudify/utils/MsoCloudifyUtils.java b/adapters/mso-adapter-utils/src/main/java/org/openecomp/mso/cloudify/utils/MsoCloudifyUtils.java new file mode 100644 index 0000000000..f72e46a9d8 --- /dev/null +++ b/adapters/mso-adapter-utils/src/main/java/org/openecomp/mso/cloudify/utils/MsoCloudifyUtils.java @@ -0,0 +1,1220 @@ +/*- + * ============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.cloudify.utils; + +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; +import java.io.IOException; +import java.io.InputStream; +import java.util.HashMap; +import java.util.Map; +import java.util.Optional; +import java.util.zip.ZipEntry; +import java.util.zip.ZipOutputStream; + +import org.openecomp.mso.cloud.CloudConfig; +import org.openecomp.mso.cloud.CloudConfigFactory; +import org.openecomp.mso.cloud.CloudSite; +import org.openecomp.mso.cloud.CloudifyManager; +import org.openecomp.mso.cloudify.base.client.CloudifyBaseException; +import org.openecomp.mso.cloudify.base.client.CloudifyClientTokenProvider; +import org.openecomp.mso.cloudify.base.client.CloudifyConnectException; +import org.openecomp.mso.cloudify.base.client.CloudifyRequest; +import org.openecomp.mso.cloudify.base.client.CloudifyResponseException; +import org.openecomp.mso.cloudify.beans.DeploymentInfo; +import org.openecomp.mso.cloudify.beans.DeploymentStatus; +import org.openecomp.mso.cloudify.exceptions.MsoCloudifyException; +import org.openecomp.mso.cloudify.exceptions.MsoCloudifyManagerNotFound; +import org.openecomp.mso.cloudify.exceptions.MsoDeploymentAlreadyExists; +import org.openecomp.mso.cloudify.v3.client.BlueprintsResource.GetBlueprint; +import org.openecomp.mso.cloudify.v3.client.BlueprintsResource.UploadBlueprint; +import org.openecomp.mso.cloudify.v3.client.Cloudify; +import org.openecomp.mso.cloudify.v3.client.DeploymentsResource.CreateDeployment; +import org.openecomp.mso.cloudify.v3.client.DeploymentsResource.DeleteDeployment; +import org.openecomp.mso.cloudify.v3.client.DeploymentsResource.GetDeployment; +import org.openecomp.mso.cloudify.v3.client.DeploymentsResource.GetDeploymentOutputs; +import org.openecomp.mso.cloudify.v3.client.ExecutionsResource.CancelExecution; +import org.openecomp.mso.cloudify.v3.client.ExecutionsResource.GetExecution; +import org.openecomp.mso.cloudify.v3.client.ExecutionsResource.ListExecutions; +import org.openecomp.mso.cloudify.v3.client.ExecutionsResource.StartExecution; +import org.openecomp.mso.cloudify.v3.model.Blueprint; +import org.openecomp.mso.cloudify.v3.model.CancelExecutionParams; +import org.openecomp.mso.cloudify.v3.model.CloudifyError; +import org.openecomp.mso.cloudify.v3.model.CreateDeploymentParams; +import org.openecomp.mso.cloudify.v3.model.Deployment; +import org.openecomp.mso.cloudify.v3.model.DeploymentOutputs; +import org.openecomp.mso.cloudify.v3.model.Execution; +import org.openecomp.mso.cloudify.v3.model.Executions; +import org.openecomp.mso.cloudify.v3.model.OpenstackConfig; +import org.openecomp.mso.cloudify.v3.model.StartExecutionParams; +import org.openecomp.mso.db.catalog.beans.HeatTemplateParam; +import org.openecomp.mso.logger.MessageEnum; +import org.openecomp.mso.logger.MsoAlarmLogger; +import org.openecomp.mso.logger.MsoLogger; +import org.openecomp.mso.openstack.exceptions.MsoAdapterException; +import org.openecomp.mso.openstack.exceptions.MsoCloudSiteNotFound; +import org.openecomp.mso.openstack.exceptions.MsoException; +import org.openecomp.mso.openstack.exceptions.MsoExceptionCategory; +import org.openecomp.mso.openstack.exceptions.MsoIOException; +import org.openecomp.mso.openstack.exceptions.MsoOpenstackException; +import org.openecomp.mso.openstack.utils.MsoCommonUtils; +import org.openecomp.mso.properties.MsoJavaProperties; +import org.openecomp.mso.properties.MsoPropertiesException; +import org.openecomp.mso.properties.MsoPropertiesFactory; + +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.databind.JsonNode; +import com.fasterxml.jackson.databind.ObjectMapper; + +public class MsoCloudifyUtils extends MsoCommonUtils { + + private MsoPropertiesFactory msoPropertiesFactory; + private CloudConfigFactory cloudConfigFactory; + + private static final String CLOUDIFY_ERROR = "CloudifyError"; + + private static final String CREATE_DEPLOYMENT = "CreateDeployment"; + private static final String DELETE_DEPLOYMENT = "DeleteDeployment"; + + // Fetch cloud configuration each time (may be cached in CloudConfig class) + protected CloudConfig cloudConfig; + + private static MsoLogger LOGGER = MsoLogger.getMsoLogger (MsoLogger.Catalog.RA); + + protected MsoJavaProperties msoProps = null; + + // Properties names and variables (with default values) + protected String createPollIntervalProp = "ecomp.mso.adapters.heat.create.pollInterval"; + private String deletePollIntervalProp = "ecomp.mso.adapters.heat.delete.pollInterval"; + + protected int createPollIntervalDefault = 15; + private int deletePollIntervalDefault = 15; + + private static final ObjectMapper JSON_MAPPER = new ObjectMapper(); + + /** + * This constructor MUST be used ONLY in the JUNIT tests, not for real code. + * The MsoPropertiesFactory will be added by EJB injection. + * + * @param msoPropID ID of the mso pro config as defined in web.xml + * @param msoPropFactory The mso properties factory instanciated by EJB injection + * @param cloudConfFactory the Cloud Config instantiated by EJB injection + */ + public MsoCloudifyUtils (String msoPropID, MsoPropertiesFactory msoPropFactory, CloudConfigFactory cloudConfFactory) { + msoPropertiesFactory = msoPropFactory; + cloudConfigFactory = cloudConfFactory; + // Dynamically get properties each time (in case reloaded). + + try { + msoProps = msoPropertiesFactory.getMsoJavaProperties (msoPropID); + } catch (MsoPropertiesException e) { + LOGGER.error (MessageEnum.LOAD_PROPERTIES_FAIL, "Unknown. Mso Properties ID not found in cache: " + msoPropID, "", "", MsoLogger.ErrorCode.DataError, "Exception - Mso Properties ID not found in cache", e); + } + cloudConfig = cloudConfigFactory.getCloudConfig (); + LOGGER.debug("MsoCloudifyUtils:" + msoPropID); + + } + + + /** + * Create a new Deployment from a specified blueprint, and install it in the specified + * cloud location and tenant. The blueprint identifier and parameter map are passed in + * as arguments, along with the cloud access credentials. The blueprint should have been + * previously uploaded to Cloudify. + * + * It is expected that parameters have been validated and contain at minimum the required + * parameters for the given template with no extra (undefined) parameters.. + * + * The deployment ID supplied by the caller must be unique in the scope of the Cloudify + * tenant (not the Openstack tenant). However, it should also be globally unique, as it + * will be the identifier for the resource going forward in Inventory. This latter is + * managed by the higher levels invoking this function. + * + * This function executes the "install" workflow on the newly created workflow. Cloudify + * will be polled for completion unless the client requests otherwise. + * + * An error will be thrown if the requested Deployment already exists in the specified + * Cloudify instance. + * + * @param cloudSiteId The cloud (may be a region) in which to create the stack. + * @param tenantId The Openstack ID of the tenant in which to create the Stack + * @param deploymentId The identifier (name) of the deployment to create + * @param blueprintId The blueprint from which to create the deployment. + * @param inputs A map of key/value inputs + * @param pollForCompletion Indicator that polling should be handled in Java vs. in the client + * @param timeoutMinutes Timeout after which the "install" will be cancelled + * @param environment An optional yaml-format string to specify environmental parameters + * @param backout Flag to delete deployment on install Failure - defaulted to True + * @return A DeploymentInfo object + * @throws MsoCloudifyException Thrown if the Cloudify API call returns an exception. + * @throws MsoIOException Thrown on Cloudify connection errors. + */ + + public DeploymentInfo createAndInstallDeployment (String cloudSiteId, + String tenantId, + String deploymentId, + String blueprintId, + Map <String, ? extends Object> inputs, + boolean pollForCompletion, + int timeoutMinutes, + boolean backout) throws MsoException + { + // Obtain the cloud site information where we will create the stack + Optional<CloudSite> cloudSite = cloudConfig.getCloudSite (cloudSiteId); + if (!cloudSite.isPresent()) { + throw new MsoCloudSiteNotFound (cloudSiteId); + } + + Cloudify cloudify = getCloudifyClient (cloudSite.get()); + + // Create the Cloudify OpenstackConfig with the credentials + OpenstackConfig openstackConfig = getOpenstackConfig (cloudSite.get(), tenantId); + + LOGGER.debug ("Ready to Create Deployment (" + deploymentId + ") with input params: " + inputs); + + // Build up the inputs, including: + // - from provided "environment" file + // - passed in by caller + // - special input for Openstack Credentials + Map<String,Object> expandedInputs = new HashMap<String,Object> (inputs); + expandedInputs.put("openstack_config", openstackConfig); + + // Build up the parameters to create a new deployment + CreateDeploymentParams deploymentParams = new CreateDeploymentParams(); + deploymentParams.setBlueprintId(blueprintId); + deploymentParams.setInputs((Map<String,Object>)expandedInputs); + + Deployment deployment = null; + try { + CreateDeployment createDeploymentRequest = cloudify.deployments().create(deploymentId, deploymentParams); + LOGGER.debug (createDeploymentRequest.toString()); + + deployment = executeAndRecordCloudifyRequest (createDeploymentRequest); + } + catch (CloudifyResponseException e) { + // Since this came on the 'Create Deployment' command, nothing was changed + // in the cloud. Return the error as an exception. + if (e.getStatus () == 409) { + // Deployment already exists. Return a specific error for this case + MsoException me = new MsoDeploymentAlreadyExists (deploymentId, cloudSiteId); + me.addContext (CREATE_DEPLOYMENT); + throw me; + } else { + // Convert the CloudifyResponseException to an MsoException + LOGGER.debug("ERROR STATUS = " + e.getStatus() + ",\n" + e.getMessage() + "\n" + e.getLocalizedMessage()); + MsoException me = cloudifyExceptionToMsoException (e, CREATE_DEPLOYMENT); + me.setCategory (MsoExceptionCategory.OPENSTACK); + throw me; + } + } catch (CloudifyConnectException e) { + // Error connecting to Cloudify instance. Convert to an MsoException + MsoException me = cloudifyExceptionToMsoException (e, CREATE_DEPLOYMENT); + throw me; + } catch (RuntimeException e) { + // Catch-all + throw runtimeExceptionToMsoException (e, CREATE_DEPLOYMENT); + } + + /* + * It can take some time for Cloudify to be ready to execute a workflow + * on the deployment. Sleep 10 seconds. + */ + try { + Thread.sleep(10000); + } catch (InterruptedException e) {} + + /* + * Next execute the "install" workflow. + * Note - this assumes there are no additional parameters required for the workflow. + */ + int createPollInterval = msoProps.getIntProperty (createPollIntervalProp, createPollIntervalDefault); + int pollTimeout = (timeoutMinutes * 60) + createPollInterval; + + Execution installWorkflow = null; + + try { + installWorkflow = executeWorkflow (cloudify, deploymentId, "install", null, pollForCompletion, pollTimeout, createPollInterval); + + if (installWorkflow.getStatus().equals("terminated")) { + // Success! + // Create and return a DeploymentInfo structure. Include the Runtime outputs + DeploymentOutputs outputs = getDeploymentOutputs (cloudify, deploymentId); + DeploymentInfo deploymentInfo = new DeploymentInfo (deployment, outputs, installWorkflow); + return deploymentInfo; + } + else { + // The workflow completed with errors. Must try to back it out. + if (!backout) + { + LOGGER.warn(MessageEnum.RA_CREATE_STACK_ERR, "Deployment installation failed, backout deletion suppressed", "", "", MsoLogger.ErrorCode.BusinessProcesssError, "Exception in Deployment Installation, backout suppressed"); + } + else { + // Poll on delete if we rollback - use same values for now + int deletePollInterval = createPollInterval; + int deletePollTimeout = pollTimeout; + + try { + // Run the uninstall to undo the install + Execution uninstallWorkflow = executeWorkflow (cloudify, deploymentId, "uninstall", null, pollForCompletion, deletePollTimeout, deletePollInterval); + + if (uninstallWorkflow.getStatus().equals("terminated")) + { + // The uninstall completed. Delete the deployment itself + DeleteDeployment deleteRequest = cloudify.deployments().deleteByName(deploymentId); + executeAndRecordCloudifyRequest (deleteRequest); + } + else { + // Didn't uninstall successfully. Log this error + LOGGER.error (MessageEnum.RA_CREATE_STACK_ERR, "Create Deployment: Cloudify error rolling back deployment install: " + installWorkflow.getError(), "", "", MsoLogger.ErrorCode.BusinessProcesssError, "Create Stack: Cloudify error rolling back deployment installation"); + } + } + catch (Exception e) { + // Catch-all for backout errors trying to uninstall/delete + // Log this error, and return the original exception + LOGGER.error (MessageEnum.RA_CREATE_STACK_ERR, "Create Stack: Nested exception rolling back deployment install: " + e, "", "", MsoLogger.ErrorCode.BusinessProcesssError, "Create Stack: Nested exception rolling back deployment installation"); + } + } + + MsoCloudifyException me = new MsoCloudifyException (0, "Workflow Execution Failed", installWorkflow.getError()); + me.addContext (CREATE_DEPLOYMENT); + alarmLogger.sendAlarm(CLOUDIFY_ERROR, MsoAlarmLogger.CRITICAL, me.getContextMessage()); + throw me; + } + } + catch (MsoException me) { + // Install failed. Unless requested otherwise, back out the deployment + + if (!backout) + { + LOGGER.warn(MessageEnum.RA_CREATE_STACK_ERR, "Deployment installation failed, backout deletion suppressed", "", "", MsoLogger.ErrorCode.BusinessProcesssError, "Exception in Deployment Installation, backout suppressed"); + } + else { + // Poll on delete if we rollback - use same values for now + int deletePollInterval = createPollInterval; + int deletePollTimeout = pollTimeout; + + try { + // Run the uninstall to undo the install. + // Always try to run it, as it should be idempotent + executeWorkflow (cloudify, deploymentId, "uninstall", null, pollForCompletion, deletePollTimeout, deletePollInterval); + + // Delete the deployment itself + DeleteDeployment deleteRequest = cloudify.deployments().deleteByName(deploymentId); + executeAndRecordCloudifyRequest (deleteRequest); + } + catch (Exception e) { + // Catch-all for backout errors trying to uninstall/delete + // Log this error, and return the original exception + LOGGER.error (MessageEnum.RA_CREATE_STACK_ERR, "Create Stack: Nested exception rolling back deployment install: " + e, "", "", MsoLogger.ErrorCode.BusinessProcesssError, "Create Stack: Nested exception rolling back deployment installation"); + + } + } + + // Propagate the original exception from Stack Query. + me.addContext (CREATE_DEPLOYMENT); + alarmLogger.sendAlarm(CLOUDIFY_ERROR, MsoAlarmLogger.CRITICAL, me.getContextMessage()); + throw me; + } + } + + + /* + * Get the runtime Outputs of a deployment. + * Return the Map of tag/value outputs. + */ + private DeploymentOutputs getDeploymentOutputs (Cloudify cloudify, String deploymentId) + throws MsoException + { + // Build and send the Cloudify request + DeploymentOutputs deploymentOutputs = null; + try { + GetDeploymentOutputs queryDeploymentOutputs = cloudify.deployments().outputsById(deploymentId); + LOGGER.debug (queryDeploymentOutputs.toString()); + + deploymentOutputs = executeAndRecordCloudifyRequest(queryDeploymentOutputs, msoProps); + } + catch (CloudifyConnectException ce) { + // Couldn't connect to Cloudify + LOGGER.error (MessageEnum.RA_CREATE_STACK_ERR, "QueryDeploymentOutputs: Cloudify connection failure: " + ce, "", "", MsoLogger.ErrorCode.BusinessProcesssError, "QueryDeploymentOutputs: Cloudify connection failure"); + throw new MsoIOException (ce.getMessage(), ce); + } + catch (CloudifyResponseException re) { + if (re.getStatus () == 404) { + // No Outputs + return null; + } + throw new MsoCloudifyException (re.getStatus(), re.getMessage(), re.getLocalizedMessage(), re); + } + catch (Exception e) { + // Catch-all + throw new MsoAdapterException (e.getMessage(), e); + } + + return deploymentOutputs; + } + + /* + * Execute a workflow on a deployment. Handle polling for completion with timeout. + * Return the final Execution object with status. + * Throw an exception on Errors. + * Question - how does the client know whether rollback needs to be done? + */ + private Execution executeWorkflow (Cloudify cloudify, String deploymentId, String workflowId, Map<String,Object> workflowParams, boolean pollForCompletion, int timeout, int pollInterval) + throws MsoCloudifyException + { + LOGGER.debug("Executing '" + workflowId + "' workflow on deployment '" + deploymentId + "'"); + + StartExecutionParams executeParams = new StartExecutionParams(); + executeParams.setWorkflowId(workflowId); + executeParams.setDeploymentId(deploymentId); + executeParams.setParameters(workflowParams); + + Execution execution = null; + String executionId = null; + String command = "start"; + Exception savedException = null; + + try { + StartExecution executionRequest = cloudify.executions().start(executeParams); + LOGGER.debug (executionRequest.toString()); + execution = executeAndRecordCloudifyRequest (executionRequest); + executionId = execution.getId(); + + if (!pollForCompletion) { + // Client did not request polling, so just return the Execution object + return execution; + } + + // Enter polling loop + boolean timedOut = false; + int pollTimeout = timeout; + + String status = execution.getStatus(); + + // Create a reusable cloudify query request + GetExecution queryExecution = cloudify.executions().byId(executionId); + command = "query"; + + while (!timedOut && !(status.equals("terminated") || status.equals("failed") || status.equals("cancelled"))) + { + // workflow is still running; check for timeout + if (pollTimeout <= 0) { + LOGGER.debug ("workflow " + execution.getWorkflowId() + " timed out on deployment " + execution.getDeploymentId()); + timedOut = true; + continue; + } + + try { + Thread.sleep (pollInterval * 1000L); + } catch (InterruptedException e) {} + + pollTimeout -= pollInterval; + LOGGER.debug("pollTimeout remaining: " + pollTimeout); + + execution = queryExecution.execute(); + status = execution.getStatus(); + } + + // Broke the loop. Check again for a terminal state + if (status.equals("terminated")){ + // Success! + LOGGER.debug ("Workflow '" + workflowId + "' completed successfully on deployment '" + deploymentId + "'"); + return execution; + } + else if (status.equals("failed")){ + // Workflow failed. Log it and return the execution object (don't throw exception here) + LOGGER.error (MessageEnum.RA_CREATE_STACK_ERR, "Cloudify workflow failure: " + execution.getError(), "", "", MsoLogger.ErrorCode.BusinessProcesssError, "Execute Workflow: Failed: " + execution.getError()); + return execution; + } + else if (status.equals("cancelled")){ + // Workflow was cancelled, leaving the deployment in an indeterminate state. Log it and return the execution object (don't throw exception here) + LOGGER.error (MessageEnum.RA_CREATE_STACK_ERR, "Cloudify workflow cancelled. Deployment is in an indeterminate state", "", "", MsoLogger.ErrorCode.BusinessProcesssError, "Execute Workflow cancelled: " + workflowId); + return execution; + } + else { + // Can only get here after a timeout + LOGGER.error (MessageEnum.RA_CREATE_STACK_ERR, "Cloudify workflow timeout", "", "", MsoLogger.ErrorCode.BusinessProcesssError, "Execute Workflow: Timed Out"); + } + } + catch (CloudifyConnectException ce) { + LOGGER.error (MessageEnum.RA_CREATE_STACK_ERR, "Execute Workflow (" + command + "): Cloudify connection failure: " + ce, "", "", MsoLogger.ErrorCode.BusinessProcesssError, "Execute Workflow (" + command + "): Cloudify connection failure"); + savedException = ce; + } + catch (CloudifyResponseException re) { + LOGGER.error (MessageEnum.RA_CREATE_STACK_ERR, "Execute Workflow (" + command + "): Cloudify response error: " + re, "", "", MsoLogger.ErrorCode.BusinessProcesssError, "Execute Workflow (" + command + "): Cloudify error" + re.getMessage()); + savedException = re; + } + catch (RuntimeException e) { + // Catch-all + LOGGER.error (MessageEnum.RA_CREATE_STACK_ERR, "Execute Workflow (" + command + "): Unexpected error: " + e, "", "", MsoLogger.ErrorCode.BusinessProcesssError, "Execute Workflow (" + command + "): Internal error" + e.getMessage()); + savedException = e; + } + + // Get to this point ONLY on an error or timeout + // The cloudify execution is still running (we've not received a terminal status), + // so try to Cancel it. + CancelExecutionParams cancelParams = new CancelExecutionParams(); + cancelParams.setAction("cancel"); + // TODO: Use force_cancel? + + Execution cancelExecution = null; + + try { + CancelExecution cancelRequest = cloudify.executions().cancel(executionId, cancelParams); + LOGGER.debug (cancelRequest.toString()); + cancelExecution = cancelRequest.execute(); + + // Enter polling loop + boolean timedOut = false; + int cancelTimeout = timeout; // TODO: For now, just use same timeout + + String status = cancelExecution.getStatus(); + + // Poll for completion. Create a reusable cloudify query request + GetExecution queryExecution = cloudify.executions().byId(executionId); + + while (!timedOut && !status.equals("cancelled")) + { + // workflow is still running; check for timeout + if (cancelTimeout <= 0) { + LOGGER.debug ("Cancel timeout for workflow " + workflowId + " on deployment " + deploymentId); + timedOut = true; + continue; + } + + try { + Thread.sleep (pollInterval * 1000L); + } catch (InterruptedException e) {} + + cancelTimeout -= pollInterval; + LOGGER.debug("pollTimeout remaining: " + cancelTimeout); + + execution = queryExecution.execute(); + status = execution.getStatus(); + } + + // Broke the loop. Check again for a terminal state + if (status.equals("cancelled")){ + // Finished cancelling. Return the original exception + LOGGER.debug ("Cancel workflow " + workflowId + " completed on deployment " + deploymentId); + throw new MsoCloudifyException (-1, "", "", savedException); + } + else { + // Can only get here after a timeout + LOGGER.debug ("Cancel workflow " + workflowId + " timeout out on deployment " + deploymentId); + MsoCloudifyException exception = new MsoCloudifyException (-1, "", "", savedException); + exception.setPendingWorkflow(true); + throw exception; + } + } + catch (Exception e) { + // Catch-all. Log the message and throw the original exception +// LOGGER.error (MessageEnum.RA_CREATE_STACK_ERR, "Execute Workflow (" + command + "): Unexpected error: " + e, "", "", MsoLogger.ErrorCode.BusinessProcesssError, "Execute Workflow (" + command + "): Internal error" + e.getMessage()); + LOGGER.debug ("Cancel workflow " + workflowId + " failed for deployment " + deploymentId + ": " + e.getMessage()); + MsoCloudifyException exception = new MsoCloudifyException (-1, "", "", savedException); + exception.setPendingWorkflow(true); + throw exception; + } + } + + + + /** + * Query for a Cloudify Deployment (by Name). This call will always return a + * DeploymentInfo object. If the deployment does not exist, an "empty" DeploymentInfo will be + * returned - containing only the deployment ID and a special status of NOTFOUND. + * + * @param tenantId The Openstack ID of the tenant in which to query + * @param cloudSiteId The cloud identifier (may be a region) in which to query + * @param stackName The name of the stack to query (may be simple or canonical) + * @return A StackInfo object + * @throws MsoOpenstackException Thrown if the Openstack API call returns an exception. + */ + public DeploymentInfo queryDeployment (String cloudSiteId, String tenantId, String deploymentId) + throws MsoException + { + LOGGER.debug ("Query Cloudify Deployment: " + deploymentId + " in tenant " + tenantId); + + // Obtain the cloud site information where we will create the stack + Optional<CloudSite> cloudSite = cloudConfig.getCloudSite (cloudSiteId); + if (!cloudSite.isPresent()) { + throw new MsoCloudSiteNotFound (cloudSiteId); + } + + Cloudify cloudify = getCloudifyClient (cloudSite.get()); + + // Build and send the Cloudify request + Deployment deployment = null; + DeploymentOutputs outputs = null; + try { + GetDeployment queryDeployment = cloudify.deployments().byId(deploymentId); + LOGGER.debug (queryDeployment.toString()); + +// deployment = queryDeployment.execute(); + deployment = executeAndRecordCloudifyRequest(queryDeployment, msoProps); + + outputs = getDeploymentOutputs (cloudify, deploymentId); + + // Next look for the latest execution + ListExecutions listExecutions = cloudify.executions().listFiltered ("deployment_id=" + deploymentId, "-created_at"); + Executions executions = listExecutions.execute(); + + // If no executions, does this give NOT_FOUND or empty set? + if (executions.getItems().isEmpty()) { + return new DeploymentInfo (deployment); + } + else { + return new DeploymentInfo (deployment, outputs, executions.getItems().get(0)); + } + } + catch (CloudifyConnectException ce) { + // Couldn't connect to Cloudify + LOGGER.error (MessageEnum.RA_CREATE_STACK_ERR, "QueryDeployment: Cloudify connection failure: " + ce, "", "", MsoLogger.ErrorCode.BusinessProcesssError, "QueryDeployment: Cloudify connection failure"); + throw new MsoIOException (ce.getMessage(), ce); + } + catch (CloudifyResponseException re) { + if (re.getStatus () == 404) { + // Got a NOT FOUND error. React differently based on deployment vs. execution + if (deployment != null) { + // Got NOT_FOUND on the executions. Assume this is a valid "empty" set + return new DeploymentInfo (deployment, outputs, null); + } else { + // Deployment not found. Default status of a DeploymentInfo object is NOTFOUND + return new DeploymentInfo (deploymentId); + } + } + throw new MsoCloudifyException (re.getStatus(), re.getMessage(), re.getLocalizedMessage(), re); + } + catch (Exception e) { + // Catch-all + throw new MsoAdapterException (e.getMessage(), e); + } + } + + + /** + * Delete a Cloudify deployment (by ID). If the deployment is not found, it will be + * considered a successful deletion. The return value is a DeploymentInfo object which + * contains the last deployment status. + * + * There is no rollback from a successful deletion. A deletion failure will + * also result in an undefined deployment state - the components may or may not have been + * all or partially deleted, so the resulting deployment must be considered invalid. + * + * @param tenantId The Openstack ID of the tenant in which to perform the delete + * @param cloudSiteId The cloud identifier (may be a region) from which to delete the stack. + * @param stackName The name/id of the stack to delete. May be simple or canonical + * @param pollForCompletion Indicator that polling should be handled in Java vs. in the client + * @return A StackInfo object + * @throws MsoOpenstackException Thrown if the Openstack API call returns an exception. + * @throws MsoCloudSiteNotFound + */ + public DeploymentInfo uninstallAndDeleteDeployment (String cloudSiteId, + String tenantId, + String deploymentId, + int timeoutMinutes) throws MsoException + { + // Obtain the cloud site information where we will create the stack + Optional<CloudSite> cloudSite = cloudConfig.getCloudSite (cloudSiteId); + if (!cloudSite.isPresent()) { + throw new MsoCloudSiteNotFound (cloudSiteId); + } + + Cloudify cloudify = getCloudifyClient (cloudSite.get()); + + LOGGER.debug ("Ready to Uninstall/Delete Deployment (" + deploymentId + ")"); + + // Query first to save the trouble if deployment not found + Deployment deployment = null; + try { + GetDeployment queryDeploymentRequest = cloudify.deployments().byId(deploymentId); + LOGGER.debug (queryDeploymentRequest.toString()); + + deployment = executeAndRecordCloudifyRequest (queryDeploymentRequest); + } + catch (CloudifyResponseException e) { + // Since this came on the 'Create Deployment' command, nothing was changed + // in the cloud. Return the error as an exception. + if (e.getStatus () == 404) { + // Deployment doesn't exist. Return a "NOTFOUND" DeploymentInfo object + // TODO: Should return NULL? + LOGGER.debug("Deployment requested for deletion does not exist: " + deploymentId); + return new DeploymentInfo (deploymentId, DeploymentStatus.NOTFOUND); + } else { + // Convert the CloudifyResponseException to an MsoOpenstackException + LOGGER.debug("ERROR STATUS = " + e.getStatus() + ",\n" + e.getMessage() + "\n" + e.getLocalizedMessage()); + MsoException me = cloudifyExceptionToMsoException (e, DELETE_DEPLOYMENT); + me.setCategory (MsoExceptionCategory.INTERNAL); + throw me; + } + } catch (CloudifyConnectException e) { + // Error connecting to Cloudify instance. Convert to an MsoException + MsoException me = cloudifyExceptionToMsoException (e, DELETE_DEPLOYMENT); + throw me; + } catch (RuntimeException e) { + // Catch-all + throw runtimeExceptionToMsoException (e, DELETE_DEPLOYMENT); + } + + /* + * Query the outputs before deleting so they can be returned as well + */ + DeploymentOutputs outputs = getDeploymentOutputs (cloudify, deploymentId); + + /* + * Next execute the "uninstall" workflow. + * Note - this assumes there are no additional parameters required for the workflow. + */ + // TODO: No deletePollInterval that I'm aware of. Use the create interval + int deletePollInterval = msoProps.getIntProperty (deletePollIntervalProp, deletePollIntervalDefault); + int pollTimeout = (timeoutMinutes * 60) + deletePollInterval; + + Execution uninstallWorkflow = null; + + try { + uninstallWorkflow = executeWorkflow (cloudify, deploymentId, "uninstall", null, true, pollTimeout, deletePollInterval); + + if (uninstallWorkflow.getStatus().equals("terminated")) { + // Successful uninstall. + LOGGER.debug("Uninstall successful for deployment " + deploymentId); + } + else { + // The uninstall workflow completed with an error. Must fail the request, but will + // leave the deployment in an indeterminate state, as cloud resources may still exist. + MsoCloudifyException me = new MsoCloudifyException (0, "Uninstall Workflow Failed", uninstallWorkflow.getError()); + me.addContext (DELETE_DEPLOYMENT); + alarmLogger.sendAlarm(CLOUDIFY_ERROR, MsoAlarmLogger.CRITICAL, me.getContextMessage()); + throw me; + } + } + catch (MsoException me) { + // Uninstall workflow has failed. + // Must fail the deletion... may leave the deployment in an inconclusive state + me.addContext (DELETE_DEPLOYMENT); + alarmLogger.sendAlarm(CLOUDIFY_ERROR, MsoAlarmLogger.CRITICAL, me.getContextMessage()); + throw me; + } + + // At this point, the deployment has been successfully uninstalled. + // Next step is to delete the deployment itself + try { + DeleteDeployment deleteRequest = cloudify.deployments().deleteByName(deploymentId); + LOGGER.debug(deleteRequest.toString()); + + // The delete request returns the deleted deployment + deployment = deleteRequest.execute(); + + } + catch (CloudifyConnectException ce) { + // Failed to delete. Must fail the request, but will leave the (uninstalled) + // deployment in Cloudify DB. + MsoCloudifyException me = new MsoCloudifyException (0, "Deployment Delete Failed", ce.getMessage(), ce); + me.addContext (DELETE_DEPLOYMENT); + alarmLogger.sendAlarm(CLOUDIFY_ERROR, MsoAlarmLogger.CRITICAL, me.getContextMessage()); + throw me; + } + catch (CloudifyResponseException re) { + // Failed to delete. Must fail the request, but will leave the (uninstalled) + // deployment in the Cloudify DB. + MsoCloudifyException me = new MsoCloudifyException (re.getStatus(), re.getMessage(), re.getMessage(), re); + me.addContext (DELETE_DEPLOYMENT); + alarmLogger.sendAlarm(CLOUDIFY_ERROR, MsoAlarmLogger.CRITICAL, me.getContextMessage()); + throw me; + } + catch (Exception e) { + // Catch-all + MsoAdapterException ae = new MsoAdapterException (e.getMessage(), e); + ae.addContext (DELETE_DEPLOYMENT); + alarmLogger.sendAlarm(CLOUDIFY_ERROR, MsoAlarmLogger.CRITICAL, ae.getContextMessage()); + throw ae; + } + + // Return the deleted deployment info (with runtime outputs) along with the completed uninstall workflow status + return new DeploymentInfo (deployment, outputs, uninstallWorkflow); + } + + + /** + * Check if a blueprint is available for use at a targeted cloud site. + * This requires checking the Cloudify Manager which is servicing that + * cloud site to see if the specified blueprint has been loaded. + * + * @param cloudSiteId The cloud site where the blueprint is needed + * @param blueprintId The ID for the blueprint in Cloudify + */ + public boolean isBlueprintLoaded (String cloudSiteId, String blueprintId) + throws MsoException + { + // Obtain the cloud site information where we will load the blueprint + Optional<CloudSite> cloudSite = cloudConfig.getCloudSite (cloudSiteId); + if (!cloudSite.isPresent()) { + throw new MsoCloudSiteNotFound (cloudSiteId); + } + + Cloudify cloudify = getCloudifyClient (cloudSite.get()); + + GetBlueprint getRequest = cloudify.blueprints().getMetadataById(blueprintId); + try { + Blueprint bp = getRequest.execute(); + LOGGER.debug("Blueprint exists: " + bp.getId()); + return true; + } + catch (CloudifyResponseException ce) { + if (ce.getStatus() == 404) { + return false; + } else { + throw ce; + } + } catch (Exception e) { + throw e; + } + } + + /** + * Upload a blueprint to the Cloudify Manager that is servicing a Cloud Site. + * The blueprint currently must be structured as a single directory with all + * of the required files. One of those files is designated the "main file" + * for the blueprint. Files are provided as byte arrays, though expect only + * text files will be distributed from ASDC and stored by MSO. + * + * Cloudify requires a single root directory in its blueprint zip files. + * The requested blueprint ID will also be used as the directory. + * All of the files will be added to this directory in the zip file. + */ + public void uploadBlueprint (String cloudSiteId, + String blueprintId, + String mainFileName, + Map<String,byte[]> blueprintFiles, + boolean failIfExists) + throws MsoException + { + // Obtain the cloud site information where we will load the blueprint + Optional<CloudSite> cloudSite = cloudConfig.getCloudSite (cloudSiteId); + if (!cloudSite.isPresent()) { + throw new MsoCloudSiteNotFound (cloudSiteId); + } + + Cloudify cloudify = getCloudifyClient (cloudSite.get()); + + boolean blueprintUploaded = uploadBlueprint (cloudify, blueprintId, mainFileName, blueprintFiles); + + if (!blueprintUploaded && failIfExists) { + throw new MsoAdapterException ("Blueprint already exists"); + } + } + + /* + * Common method to load a blueprint. May be called from + */ + private boolean uploadBlueprint (Cloudify cloudify, String blueprintId, String mainFileName, Map<String,byte[]> blueprintFiles) + throws MsoException + { + // Check if it already exists. If so, return false. + GetBlueprint getRequest = cloudify.blueprints().getMetadataById(blueprintId); + try { + Blueprint bp = getRequest.execute(); + LOGGER.debug("Blueprint " + bp.getId() + " already exists."); + return false; + } + catch (CloudifyResponseException ce) { + if (ce.getStatus() == 404) { + // This is the expected result. + LOGGER.debug("Verified that Blueprint doesn't exist yet"); + } else { + throw ce; + } + } catch (Exception e) { + throw e; + } + + // Create a blueprint ZIP file in memory + ByteArrayOutputStream zipBuffer = new ByteArrayOutputStream(); + ZipOutputStream zipOut = new ZipOutputStream(zipBuffer); + + try { + // Put the root directory + String rootDir = blueprintId + ((blueprintId.endsWith("/") ? "" : "/")); + zipOut.putNextEntry(new ZipEntry (rootDir)); + zipOut.closeEntry(); + + for (String fileName : blueprintFiles.keySet()) { + ZipEntry ze = new ZipEntry (rootDir + fileName); + zipOut.putNextEntry (ze); + zipOut.write (blueprintFiles.get(fileName)); + zipOut.closeEntry(); + } + zipOut.close(); + } + catch (IOException e) { + // Since we're writing to a byte array, this should never happen + } + LOGGER.debug ("Blueprint zip file size: " + zipBuffer.size()); + + // Ready to upload the blueprint zip + InputStream blueprintStream = new ByteArrayInputStream (zipBuffer.toByteArray()); + try { + UploadBlueprint uploadRequest = cloudify.blueprints().uploadFromStream(blueprintId, mainFileName, blueprintStream); + Blueprint blueprint = uploadRequest.execute(); + System.out.println("Successfully uploaded blueprint " + blueprint.getId()); + } + catch (CloudifyResponseException e) { + MsoException me = cloudifyExceptionToMsoException (e, "UPLOAD_BLUEPRINT"); + throw me; + } + catch (CloudifyConnectException e) { + MsoException me = cloudifyExceptionToMsoException (e, "UPLOAD_BLUEPRINT"); + throw me; + } + catch (RuntimeException e) { + // Catch-all + MsoException me = runtimeExceptionToMsoException (e, "UPLOAD_BLUEPRINT"); + throw me; + } + finally { + try { + blueprintStream.close(); + } catch (IOException e) {} + } + + return true; + } + + + + // --------------------------------------------------------------- + // PRIVATE FUNCTIONS FOR USE WITHIN THIS CLASS + + /** + * Get a Cloudify client for the specified cloud site. + * Everything that is required can be found in the Cloud Config. + * + * @param cloudSite + * @return a Cloudify object + */ + public Cloudify getCloudifyClient (CloudSite cloudSite) throws MsoException + { + CloudifyManager cloudifyConfig = cloudSite.getCloudifyManager(); + if (cloudifyConfig == null) { + throw new MsoCloudifyManagerNotFound (cloudSite.getId()); + } + + // Get a Cloudify client + // Set a Token Provider to fetch tokens from Cloudify itself. + String cloudifyUrl = cloudifyConfig.getCloudifyUrl(); + Cloudify cloudify = new Cloudify (cloudifyUrl); + cloudify.setTokenProvider(new CloudifyClientTokenProvider(cloudifyUrl, cloudifyConfig.getUsername(), cloudifyConfig.getPassword())); + + return cloudify; + } + + + /* + * Query for a Cloudify Deployment. This function is needed in several places, so + * a common method is useful. This method takes an authenticated CloudifyClient + * (which internally identifies the cloud & tenant to search), and returns + * a Deployment object if found, Null if not found, or an MsoCloudifyException + * if the Cloudify API call fails. + * + * @param cloudifyClient an authenticated Cloudify client + * + * @param deploymentId the deployment to query + * + * @return a Deployment object or null if the requested deployment doesn't exist. + * + * @throws MsoCloudifyException Thrown if the Cloudify API call returns an exception + */ + protected Deployment queryDeployment (Cloudify cloudify, String deploymentId) throws MsoException { + if (deploymentId == null) { + return null; + } + try { + GetDeployment request = cloudify.deployments().byId (deploymentId); + return executeAndRecordCloudifyRequest (request, msoProps); + } catch (CloudifyResponseException e) { + if (e.getStatus () == 404) { + LOGGER.debug ("queryDeployment - not found: " + deploymentId); + return null; + } else { + // Convert the CloudifyResponseException to an MsoCloudifyException + throw cloudifyExceptionToMsoException (e, "QueryDeployment"); + } + } catch (CloudifyConnectException e) { + // Connection to Openstack failed + throw cloudifyExceptionToMsoException (e, "QueryDeployment"); + } + } + + + public void copyStringOutputsToInputs(Map<String, String> inputs, + Map<String, Object> otherStackOutputs, boolean overWrite) { + if (inputs == null || otherStackOutputs == null) + return; + for (String key : otherStackOutputs.keySet()) { + if (!inputs.containsKey(key)) { + Object obj = otherStackOutputs.get(key); + if (obj instanceof String) { + inputs.put(key, (String) otherStackOutputs.get(key)); + } else if (obj instanceof JsonNode ){ + // This is a bit of mess - but I think it's the least impacting + // let's convert it BACK to a string - then it will get converted back later + try { + String str = this.convertNode((JsonNode) obj); + inputs.put(key, str); + } catch (Exception e) { + LOGGER.debug("WARNING: unable to convert JsonNode output value for "+ key); + //effect here is this value will not have been copied to the inputs - and therefore will error out downstream + } + } else if (obj instanceof java.util.LinkedHashMap) { + LOGGER.debug("LinkedHashMap - this is showing up as a LinkedHashMap instead of JsonNode"); + try { + String str = JSON_MAPPER.writeValueAsString(obj); + inputs.put(key, str); + } catch (Exception e) { + LOGGER.debug("WARNING: unable to convert LinkedHashMap output value for "+ key); + } + } else { + // just try to cast it - could be an integer or some such + try { + String str = (String) obj; + inputs.put(key, str); + } catch (Exception e) { + LOGGER.debug("WARNING: unable to convert output value for "+ key); + //effect here is this value will not have been copied to the inputs - and therefore will error out downstream + } + } + } + } + return; + } + + /* + * Normalize an input value to an Object, based on the target parameter type. + * If the type is not recognized, it will just be returned unchanged (as a string). + */ + public Object convertInputValue (String inputValue, HeatTemplateParam templateParam) + { + String type = templateParam.getParamType(); + LOGGER.debug("Parameter: " + templateParam.getParamName() + " is of type " + type); + + if (type.equalsIgnoreCase("number")) { + try { + return Integer.valueOf(inputValue); + } + catch (Exception e) { + LOGGER.debug("Unable to convert " + inputValue + " to an integer!"); + return null; + } + } else if (type.equalsIgnoreCase("json")) { + try { + JsonNode jsonNode = new ObjectMapper().readTree(inputValue); + return jsonNode; + } + catch (Exception e) { + LOGGER.debug("Unable to convert " + inputValue + " to a JsonNode!"); + return null; + } + } else if (type.equalsIgnoreCase("boolean")) { + return new Boolean(inputValue); + } + + // Nothing else matched. Return the original string + return inputValue; + } + + + private String convertNode(final JsonNode node) { + try { + final Object obj = JSON_MAPPER.treeToValue(node, Object.class); + final String json = JSON_MAPPER.writeValueAsString(obj); + return json; + } catch (JsonParseException jpe) { + LOGGER.debug("Error converting json to string " + jpe.getMessage()); + } catch (Exception e) { + LOGGER.debug("Error converting json to string " + e.getMessage()); + } + return "[Error converting json to string]"; + } + + + /* + * Method to execute a Cloudify command and track its execution time. + * For the metrics log, a category of "Cloudify" is used along with a + * sub-category that identifies the specific call (using the real + * cloudify-client classname of the CloudifyRequest<T> parameter). + */ + + protected static <T> T executeAndRecordCloudifyRequest (CloudifyRequest <T> request) + { + return executeAndRecordCloudifyRequest (request, null); + } + protected static <T> T executeAndRecordCloudifyRequest (CloudifyRequest <T> request, MsoJavaProperties msoProps) { + + int limit; + // Get the name and method name of the parent class, which triggered this method + StackTraceElement[] classArr = new Exception ().getStackTrace (); + if (classArr.length >=2) { + limit = 3; + } else { + limit = classArr.length; + } + String parentServiceMethodName = classArr[0].getClassName () + "." + classArr[0].getMethodName (); + for (int i = 1; i < limit; i++) { + String className = classArr[i].getClassName (); + if (!className.equals (MsoCommonUtils.class.getName ())) { + parentServiceMethodName = className + "." + classArr[i].getMethodName (); + break; + } + } + + String requestType; + if (request.getClass ().getEnclosingClass () != null) { + requestType = request.getClass ().getEnclosingClass ().getSimpleName () + "." + + request.getClass ().getSimpleName (); + } else { + requestType = request.getClass ().getSimpleName (); + } + + int retryDelay = retryDelayDefault; + int retryCount = retryCountDefault; + String retryCodes = retryCodesDefault; + if (msoProps != null) //extra check to avoid NPE + { + retryDelay = msoProps.getIntProperty (retryDelayProp, retryDelayDefault); + retryCount = msoProps.getIntProperty (retryCountProp, retryCountDefault); + retryCodes = msoProps.getProperty (retryCodesProp, retryCodesDefault); + } + + // Run the actual command. All exceptions will be propagated + while (true) + { + try { + return request.execute (); + } + catch (CloudifyResponseException e) { + boolean retry = false; + if (retryCodes != null ) { + int code = e.getStatus(); + LOGGER.debug ("Config values RetryDelay:" + retryDelay + " RetryCount:" + retryCount + " RetryCodes:" + retryCodes + " ResponseCode:" + code); + for (String rCode : retryCodes.split (",")) { + try { + if (retryCount > 0 && code == Integer.parseInt (rCode)) + { + retryCount--; + retry = true; + LOGGER.debug ("CloudifyResponseException ResponseCode:" + code + " at:" + parentServiceMethodName + " request:" + requestType + " Retry indicated. Attempts remaining:" + retryCount); + break; + } + } catch (NumberFormatException e1) { + LOGGER.error (MessageEnum.RA_CONFIG_EXC, "No retries. Exception in parsing retry code in config:" + rCode, "", "", MsoLogger.ErrorCode.SchemaError, "Exception in parsing retry code in config"); + throw e; + } + } + } + if (retry) + { + try { + Thread.sleep (retryDelay * 1000L); + } catch (InterruptedException e1) { + LOGGER.debug ("Thread interrupted while sleeping", e1); + } + } + else + throw e; // exceeded retryCount or code is not retryable + } + catch (CloudifyConnectException e) { + // Connection to Cloudify failed + if (retryCount > 0) + { + retryCount--; + LOGGER.debug ("CloudifyConnectException at:" + parentServiceMethodName + " request:" + requestType + " Retry indicated. Attempts remaining:" + retryCount); + try { + Thread.sleep (retryDelay * 1000L); + } catch (InterruptedException e1) { + LOGGER.debug ("Thread interrupted while sleeping", e1); + } + } + else + throw e; + + } + } + } + /* + * Convert an Exception on a Cloudify call to an MsoCloudifyException. + * This method supports CloudifyResponseException and CloudifyConnectException. + */ + protected MsoException cloudifyExceptionToMsoException (CloudifyBaseException e, String context) { + MsoException me = null; + + if (e instanceof CloudifyResponseException) { + CloudifyResponseException re = (CloudifyResponseException) e; + + try { + // Failed Cloudify calls return an error entity body. + CloudifyError error = re.getResponse ().getErrorEntity (CloudifyError.class); + LOGGER.error (MessageEnum.RA_CONNECTION_EXCEPTION, "Cloudify", "Cloudify Error on " + context + ": " + error.getErrorCode(), "Cloudify", "", MsoLogger.ErrorCode.DataError, "Exception - Cloudify Error on " + context); + String fullError = error.getErrorCode() + ": " + error.getMessage(); + LOGGER.debug(fullError); + me = new MsoCloudifyException (re.getStatus(), + re.getMessage(), + fullError); + } catch (Exception e2) { + // Couldn't parse the body as a "CloudifyError". Report the original HTTP error. + LOGGER.error (MessageEnum.RA_CONNECTION_EXCEPTION, "Cloudify", "HTTP Error on " + context + ": " + re.getStatus() + "," + e.getMessage(), "Cloudify", "", MsoLogger.ErrorCode.DataError, "Exception - HTTP Error on " + context, e2); + me = new MsoCloudifyException (re.getStatus (), re.getMessage (), ""); + } + + // Add the context of the error + me.addContext (context); + + // Generate an alarm for 5XX and higher errors. + if (re.getStatus () >= 500) { + alarmLogger.sendAlarm ("CloudifyError", MsoAlarmLogger.CRITICAL, me.getContextMessage ()); + } + } else if (e instanceof CloudifyConnectException) { + CloudifyConnectException ce = (CloudifyConnectException) e; + + me = new MsoIOException (ce.getMessage ()); + me.addContext (context); + + // Generate an alarm for all connection errors. + alarmLogger.sendAlarm ("CloudifyIOError", MsoAlarmLogger.CRITICAL, me.getContextMessage ()); + LOGGER.error(MessageEnum.RA_CONNECTION_EXCEPTION, "Cloudify", "Cloudify connection error on " + context + ": " + e, "Cloudify", "", MsoLogger.ErrorCode.DataError, "Cloudify connection error on " + context); + } + + return me; + } + + /* + * Return an OpenstackConfig object as expected by Cloudify Openstack Plug-in. + * Base the values on the CloudSite definition. + */ + private OpenstackConfig getOpenstackConfig (CloudSite cloudSite, String tenantId) { + OpenstackConfig openstackConfig = new OpenstackConfig(); + openstackConfig.setRegion (cloudSite.getRegionId()); + openstackConfig.setAuthUrl (cloudSite.getIdentityService().getIdentityUrl()); + openstackConfig.setUsername (cloudSite.getIdentityService().getMsoId()); + openstackConfig.setPassword (cloudSite.getIdentityService().getMsoPass()); + openstackConfig.setTenantName (tenantId); + return openstackConfig; + } +} diff --git a/adapters/mso-adapter-utils/src/main/java/org/openecomp/mso/openstack/beans/HeatStatus.java b/adapters/mso-adapter-utils/src/main/java/org/openecomp/mso/openstack/beans/HeatStatus.java deleted file mode 100644 index 3e4ea27d5f..0000000000 --- a/adapters/mso-adapter-utils/src/main/java/org/openecomp/mso/openstack/beans/HeatStatus.java +++ /dev/null @@ -1,29 +0,0 @@ -/*- - * ============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.openstack.beans; - -/* - * Enum status values to mirror the Openstack Heat stack status values - */ -public enum HeatStatus { - INIT, CREATED, NOTFOUND, FAILED, BUILDING, DELETING, UNKNOWN, UPDATING, UPDATED -} - diff --git a/adapters/mso-adapter-utils/src/main/java/org/openecomp/mso/openstack/beans/MsoTenant.java b/adapters/mso-adapter-utils/src/main/java/org/openecomp/mso/openstack/beans/MsoTenant.java deleted file mode 100644 index 5e037096df..0000000000 --- a/adapters/mso-adapter-utils/src/main/java/org/openecomp/mso/openstack/beans/MsoTenant.java +++ /dev/null @@ -1,66 +0,0 @@ -/*- - * ============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.openstack.beans; - - - -import java.util.Map; - -/** - * This bean class represents the Openstack tenant properties that are - * needed by MSO. - * - * - */ -public class MsoTenant { - private String tenantId; - private String tenantName; - private Map<String,String> metadata; - - public MsoTenant() {} - - public MsoTenant (String id, String name, Map<String,String> metadata) { - this.tenantId = id; - this.tenantName = name; - this.metadata = metadata; - } - - public String getTenantId() { - return tenantId; - } - public void setTenantId(String tenantId) { - this.tenantId = tenantId; - } - - public String getTenantName() { - return tenantName; - } - public void setTenantName(String tenantName) { - this.tenantName = tenantName; - } - - public Map<String, String> getMetadata() { - return metadata; - } - public void setMetadata(Map<String, String> metadata) { - this.metadata = metadata; - } -} diff --git a/adapters/mso-adapter-utils/src/main/java/org/openecomp/mso/openstack/beans/NetworkInfo.java b/adapters/mso-adapter-utils/src/main/java/org/openecomp/mso/openstack/beans/NetworkInfo.java deleted file mode 100644 index 64460b20bb..0000000000 --- a/adapters/mso-adapter-utils/src/main/java/org/openecomp/mso/openstack/beans/NetworkInfo.java +++ /dev/null @@ -1,151 +0,0 @@ -/*- - * ============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.openstack.beans; - -import java.util.ArrayList; -import java.util.List; -import java.util.Map; -import java.util.HashMap; - -import com.woorea.openstack.quantum.model.Network; -import com.woorea.openstack.quantum.model.Segment; - -/* - * This Java bean class relays Network details (including status) to ActiveVOS processes. - * - * This bean is returned by all Network-specific adapter operations (create, query, delete) - */ -public class NetworkInfo { - // Set defaults for everything - private String name = ""; - private String id = ""; - private NetworkStatus status = NetworkStatus.UNKNOWN; - private String provider = ""; - private List<Integer> vlans = new ArrayList<>(); - private List<String> subnets = new ArrayList<>(); - - static Map<String,NetworkStatus> NetworkStatusMap; - static { - NetworkStatusMap = new HashMap<>(); - NetworkStatusMap.put("ACTIVE", NetworkStatus.ACTIVE); - NetworkStatusMap.put("DOWN", NetworkStatus.DOWN); - NetworkStatusMap.put("BUILD", NetworkStatus.BUILD); - NetworkStatusMap.put("ERROR", NetworkStatus.ERROR); - } - - /** - * Capture the data from a Neutron Network object. - * - * For MSO, there are assumptions regarding all networks. - * - Everything will be a provider network - * - All provider networks are VLANs - * - Multiple VLANs are supported, and indicated by multi-provider segments. - * Each will have the same physical network & network type "vlan". - * - * @param network - */ - public NetworkInfo(Network network) { - if (network != null) { - initFieldsWithDataFromNetwork(network); - } else { - status = NetworkStatus.NOTFOUND; - } - } - - private void initFieldsWithDataFromNetwork(Network network){ - name = network.getName(); - id = network.getId(); - - if (network.getStatus() != null && NetworkStatusMap.containsKey(network.getStatus())) { - status = NetworkStatusMap.get(network.getStatus()); - } - if (network.getProviderPhysicalNetwork() != null) { - provider = network.getProviderPhysicalNetwork(); - if ("vlan".equals(network.getProviderNetworkType())) { - vlans.add(network.getProviderSegmentationId()); - } - } - else if (network.getSegments() != null && !network.getSegments().isEmpty()) { - Segment s = network.getSegments().get(0); - provider = s.getProviderPhysicalNetwork(); - if ("vlan".equals(s.getProviderNetworkType())) { - network.getSegments().forEach(segment -> vlans.add(segment.getProviderSegmentationId())); - } - } - subnets = network.getSubnets(); - } - - public String getName() { - return name; - } - - public void setName (String name) { - this.name = name; - } - - public String getId() { - return id; - } - - public void setId (String id) { - this.id = id; - } - - public NetworkStatus getStatus() { - return status; - } - - public void setStatus (NetworkStatus status) { - this.status = status; - } - - public String getProvider() { - return provider; - } - - public void setProvider (String provider) { - this.provider = provider; - } - - public List<Integer> getVlans () { - return vlans; - } - - public void setVlans (List<Integer> vlans) { - this.vlans = vlans; - } - - public List<String> getSubnets () { - return subnets; - } - - @Override - public String toString() { - return "NetworkInfo{" + "name='" + name + '\'' + - ", id='" + id + '\'' + - ", status=" + status + - ", provider='" + provider + '\'' + - ", vlans=" + vlans + - ", subnets=" + subnets + - '}'; - } -} - diff --git a/adapters/mso-adapter-utils/src/main/java/org/openecomp/mso/openstack/beans/NetworkRollback.java b/adapters/mso-adapter-utils/src/main/java/org/openecomp/mso/openstack/beans/NetworkRollback.java deleted file mode 100644 index 6878e5f6b4..0000000000 --- a/adapters/mso-adapter-utils/src/main/java/org/openecomp/mso/openstack/beans/NetworkRollback.java +++ /dev/null @@ -1,148 +0,0 @@ -/*- - * ============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.openstack.beans; - - -import java.util.List; - -import org.openecomp.mso.entity.MsoRequest; - -/** - * Javabean representing the rollback criteria following a "Create Network" - * or "Update Network" operation. This structure can be passed back to the - * "Rollback Network" operation to undo the effects of the create/update. - * - * Once a network is created, the only possible update through MSO is to - * the set of VLANs supported by the network. The vlans attribute of the - * rollback object contains the previous VLANs before update. - * - * - */ -public class NetworkRollback { - private String networkId; - private String neutronNetworkId; - private String networkStackId; - private String tenantId; - private String cloudId; - private String networkType; - private String modelCustomizationUuid; - private boolean networkCreated = false; - // Previous values for updates - private String networkName = null; - private String physicalNetwork = null; - private List<Integer> vlans = null; - private MsoRequest msoRequest; - - public String getNetworkId() { - return networkId; - } - public void setNetworkId(String networkId) { - this.networkId = networkId; - } - - public String getNeutronNetworkId() { - return neutronNetworkId; - } - public void setNeutronNetworkId(String neutronNetworkId) { - this.neutronNetworkId = neutronNetworkId; - } - - public String getNetworkStackId() { - return networkStackId; - } - public void setNetworkStackId(String networkStackId) { - this.networkStackId = networkStackId; - } - public String getTenantId() { - return tenantId; - } - public void setTenantId(String tenantId) { - this.tenantId = tenantId; - } - - public String getCloudId() { - return cloudId; - } - public void setCloudId(String cloudId) { - this.cloudId = cloudId; - } - - public String getNetworkType() { - return networkType; - } - public void setNetworkType(String networkType) { - this.networkType = networkType; - } - - public String getModelCustomizationUuid() { - return this.modelCustomizationUuid; - } - - public void setModelCustomizationUuid(String modelCustomizationUuid) { - this.modelCustomizationUuid = modelCustomizationUuid; - } - - public boolean getNetworkCreated() { - return networkCreated; - } - public void setNetworkCreated(boolean networkCreated) { - this.networkCreated = networkCreated; - } - - public String getNetworkName() { - return networkName; - } - public void setNetworkName(String networkName) { - this.networkName = networkName; - } - - public String getPhysicalNetwork() { - return physicalNetwork; - } - public void setPhysicalNetwork(String physicalNetwork) { - this.physicalNetwork = physicalNetwork; - } - - public List<Integer> getVlans () { - return vlans; - } - public void setVlans (List<Integer> vlans) { - this.vlans = vlans; - } - - public MsoRequest getMsoRequest() { - return msoRequest; - } - public void setMsoRequest (MsoRequest msoRequest) { - this.msoRequest = msoRequest; - } - - @Override - public String toString() { - return "NetworkRollback [networkId=" + networkId - + ", neutronNetworkId=" + neutronNetworkId + ", networkStackId=" - + networkStackId + ", tenantId=" + tenantId + ", cloudId=" - + cloudId + ", networkType=" + networkType - + ", networkCreated=" + networkCreated + ", networkName=" + networkName - + ", physicalNetwork=" + physicalNetwork + "]"; - } - -} diff --git a/adapters/mso-adapter-utils/src/main/java/org/openecomp/mso/openstack/beans/NetworkStatus.java b/adapters/mso-adapter-utils/src/main/java/org/openecomp/mso/openstack/beans/NetworkStatus.java deleted file mode 100644 index 199028e56c..0000000000 --- a/adapters/mso-adapter-utils/src/main/java/org/openecomp/mso/openstack/beans/NetworkStatus.java +++ /dev/null @@ -1,31 +0,0 @@ -/*- - * ============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.openstack.beans; - - -/** - * Enum status values to mirror the Openstack Neutron - * network status values - */ -public enum NetworkStatus { - NOTFOUND, ACTIVE, DOWN, BUILD, ERROR, UNKNOWN -} - diff --git a/adapters/mso-adapter-utils/src/main/java/org/openecomp/mso/openstack/beans/Pool.java b/adapters/mso-adapter-utils/src/main/java/org/openecomp/mso/openstack/beans/Pool.java deleted file mode 100644 index a3a04abc60..0000000000 --- a/adapters/mso-adapter-utils/src/main/java/org/openecomp/mso/openstack/beans/Pool.java +++ /dev/null @@ -1,69 +0,0 @@ -/*- - * ============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.openstack.beans; - - - -import javax.xml.bind.annotation.XmlAccessType; -import javax.xml.bind.annotation.XmlAccessorType; -import javax.xml.bind.annotation.XmlType; - -@XmlAccessorType(XmlAccessType.FIELD) -@XmlType(name = "", propOrder = { - "start", - "end" -}) -public class Pool { - - private String start; - private String end; - - /** - * @return the start - */ - public String getStart() { - return start; - } - /** - * @param start the start to set - */ - public void setStart(String start) { - this.start = start; - } - /** - * @return the end - */ - public String getEnd() { - return end; - } - /** - * @param end the end to set - */ - public void setEnd(String end) { - this.end = end; - } - - @Override - public String toString() { - return "Allocation_pool [start=" + start + ", end=" + end + "]"; - } - -} diff --git a/adapters/mso-adapter-utils/src/main/java/org/openecomp/mso/openstack/beans/StackInfo.java b/adapters/mso-adapter-utils/src/main/java/org/openecomp/mso/openstack/beans/StackInfo.java deleted file mode 100644 index 506b62994d..0000000000 --- a/adapters/mso-adapter-utils/src/main/java/org/openecomp/mso/openstack/beans/StackInfo.java +++ /dev/null @@ -1,106 +0,0 @@ -/*- - * ============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.openstack.beans; - -import com.woorea.openstack.heat.model.Stack; -import java.util.HashMap; -import java.util.Map; - -/* - * This Java bean class relays Heat stack status information to ActiveVOS processes. - * - * This bean is returned by all Heat-specific adapter operations (create, query, delete) - */ -public class StackInfo { - private String name = ""; - private String canonicalName = ""; - private HeatStatus status; - private Map<String, Object> outputs = new HashMap<>(); - private Map<String,Object> parameters = new HashMap<>(); - static private Map<String, HeatStatus> heatStatusMap; - - static { - heatStatusMap = new HashMap<>(); - heatStatusMap.put("CREATE_IN_PROGRESS", HeatStatus.BUILDING); - heatStatusMap.put("CREATE_COMPLETE", HeatStatus.CREATED); - heatStatusMap.put("CREATE_FAILED", HeatStatus.FAILED); - heatStatusMap.put("DELETE_IN_PROGRESS", HeatStatus.DELETING); - heatStatusMap.put("DELETE_COMPLETE", HeatStatus.NOTFOUND); - heatStatusMap.put("DELETE_FAILED", HeatStatus.FAILED); - heatStatusMap.put("UPDATE_IN_PROGRESS", HeatStatus.UPDATING); - heatStatusMap.put("UPDATE_FAILED", HeatStatus.FAILED); - heatStatusMap.put("UPDATE_COMPLETE", HeatStatus.UPDATED); - } - - public StackInfo (String name, HeatStatus status) { - this.name = name; - this.canonicalName = name; // Don't have an ID, so just use name - this.status = status; - } - - public StackInfo (Stack stack) - { - if (stack == null) { - this.status = HeatStatus.NOTFOUND; - return; - } - this.name = stack.getStackName(); - this.canonicalName = stack.getStackName() + "/" + stack.getId(); - - if (stack.getStackStatus() == null) { - this.status = HeatStatus.INIT; - } else { - this.status = heatStatusMap.getOrDefault(stack.getStackStatus(), HeatStatus.UNKNOWN); - } - if (stack.getOutputs() != null) { - this.outputs = new HashMap<>(); - stack.getOutputs().forEach(output -> outputs.put(output.getOutputKey(), output.getOutputValue())); - } - - this.parameters = stack.getParameters(); - } - - public String getName() { - return name; - } - - public void setName (String name) { - this.name = name; - } - - public String getCanonicalName() { - return canonicalName; - } - - public HeatStatus getStatus() { - return status; - } - - public Map<String, Object> getOutputs() { - return outputs; - } - - public Map<String,Object> getParameters () { - return parameters; - } - -} - diff --git a/adapters/mso-adapter-utils/src/main/java/org/openecomp/mso/openstack/beans/Subnet.java b/adapters/mso-adapter-utils/src/main/java/org/openecomp/mso/openstack/beans/Subnet.java deleted file mode 100644 index eea47413e4..0000000000 --- a/adapters/mso-adapter-utils/src/main/java/org/openecomp/mso/openstack/beans/Subnet.java +++ /dev/null @@ -1,200 +0,0 @@ -/*- - * ============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.openstack.beans; - - - -import java.util.List; - -import javax.xml.bind.annotation.XmlTransient; - -public class Subnet { - - private String subnetName; - - private String neutronId; - - private String subnetId; // value from aai - - private String cidr; //Only field required - - private String gatewayIp=""; - - private String ipVersion="4"; - - private Boolean enableDHCP=false; - - private List<String> hostRoutes; - - private List<Pool> allocationPools; - - private List<String> dnsNameServers; - - public Subnet () { - } - - public String getSubnetName() { - return subnetName; - } - - public void setSubnetName(String subnetName) { - this.subnetName = subnetName; - } - - public List<Pool> getAllocationPools() { - return allocationPools; - } - - /** - * @return the cidr - */ - public String getCidr() { - return cidr; - } - - /** - * @return the dnsNames - */ - public List<String> getDnsNameServers() { - return dnsNameServers; - } - - - public Boolean getEnableDHCP() { - return enableDHCP; - } - - /** - * @return the gw - */ - public String getGatewayIp() { - return gatewayIp; - } - - /** - * @return the hostRoutes - */ - public List<String> getHostRoutes() { - return hostRoutes; - } - - /** - * @return the NeutronId - */ - @XmlTransient - public String getNeutronId() { - return neutronId; - } - - /** - * @return the ipversion - */ - public String getIpVersion() { - return ipVersion; - } - - /** - * @return the name - */ - public String getSubnetId() { - return subnetId; - } - - public void setAllocationPools(List<Pool> allocationPools) { - this.allocationPools = allocationPools; - } - - /** - * @param cidr - * the cidr to set - */ - public void setCidr(String cidr) { - this.cidr = cidr; - } - - /** - * @param dnsNames - * the dnsNames to set - */ - public void setDnsNameServers(List<String> dnsNameServers) { - this.dnsNameServers = dnsNameServers; - } - - /** - * @param enableDHCP - * the enableDHCP to set - */ - public void setEnableDHCP(Boolean enableDHCP) { - this.enableDHCP = enableDHCP; - } - - /** - * @param gw - * the gw to set - */ - public void setGatewayIp(String gatewayIp) { - this.gatewayIp = gatewayIp; - } - - /** - * @param hostRoutes - * the hostRoutes to set - */ - public void setHostRoutes(List<String> hostRoutes) { - this.hostRoutes = hostRoutes; - } - - /** - * @param neutronId - * the id to set - */ - public void setNeutronId(String neutronId) { - this.neutronId = neutronId; - } - - /** - * @param ipversion - * the ipversion to set - */ - public void setIpVersion(String ipVersion) { - this.ipVersion = ipVersion; - } - - /** - * @param name - * the name to set - */ - public void setSubnetId(String subnetId) { - this.subnetId = subnetId; - } - - - @Override - public String toString() { - return "Subnet [subnetName=" + subnetName + ", neutronId=" + neutronId - + ", subnetId=" + subnetId + ", cidr=" + cidr + ", gatewayIp=" - + gatewayIp + ", ipVersion=" + ipVersion + ", enableDHCP=" - + enableDHCP + ", hostRoutes=" + hostRoutes - + ", allocationPools=" + allocationPools + ", dnsNameServers=" - + dnsNameServers + "]"; - } - -} diff --git a/adapters/mso-adapter-utils/src/main/java/org/openecomp/mso/openstack/beans/VnfRollback.java b/adapters/mso-adapter-utils/src/main/java/org/openecomp/mso/openstack/beans/VnfRollback.java index 8cb41deba5..43b742f326 100644 --- a/adapters/mso-adapter-utils/src/main/java/org/openecomp/mso/openstack/beans/VnfRollback.java +++ b/adapters/mso-adapter-utils/src/main/java/org/openecomp/mso/openstack/beans/VnfRollback.java @@ -43,9 +43,24 @@ public class VnfRollback { private boolean isBase = false; private String vfModuleStackId; private String modelCustomizationUuid; //NOTE: this is the vfModule's modelCustomizationUuid + private String mode = "HEAT"; public VnfRollback() {} + /** + * For backwards compatibility... orchestration mode defaults to HEAT + * + * @param vnfId + * @param tenantId + * @param cloudSiteId + * @param tenantCreated + * @param vnfCreated + * @param msoRequest + * @param volumeGroupName + * @param volumeGroupId + * @param requestType + * @param modelCustomizationUuid + */ public VnfRollback(String vnfId, String tenantId, String cloudSiteId, boolean tenantCreated, boolean vnfCreated, MsoRequest msoRequest, @@ -63,6 +78,38 @@ public class VnfRollback { this.modelCustomizationUuid = modelCustomizationUuid; } + /** + * For backwards compatibility... orchestration mode defaults to HEAT + * + * @param vnfId + * @param tenantId + * @param cloudSiteId + * @param tenantCreated + * @param vnfCreated + * @param msoRequest + * @param volumeGroupName + * @param volumeGroupId + * @param requestType + * @param modelCustomizationUuid + */ + public VnfRollback(String vnfId, String tenantId, String cloudSiteId, + boolean tenantCreated, boolean vnfCreated, + MsoRequest msoRequest, String volumeGroupName, String volumeGroupId, + String requestType, String modelCustomizationUuid, String orchestrationMode) { + super(); + this.vnfId = vnfId; + this.tenantId = tenantId; + this.cloudSiteId = cloudSiteId; + this.tenantCreated = tenantCreated; + this.vnfCreated = vnfCreated; + this.msoRequest = msoRequest; + this.volumeGroupName = volumeGroupName; + this.volumeGroupId = volumeGroupId; + this.requestType = requestType; + this.modelCustomizationUuid = modelCustomizationUuid; + this.mode = orchestrationMode; + } + public String getVnfId() { return vnfId; } @@ -150,11 +197,18 @@ public class VnfRollback { public void setModelCustomizationUuid(String modelCustomizationUuid) { this.modelCustomizationUuid = modelCustomizationUuid; } + public String getMode() { + return this.mode; + } + public void setMode(String mode) { + this.mode = mode; + } @Override public String toString() { return "VnfRollback: cloud=" + cloudSiteId + ", tenant=" + tenantId + ", vnf=" + vnfId + ", tenantCreated=" + tenantCreated + ", vnfCreated=" + vnfCreated + ", requestType = " + requestType - + ", modelCustomizationUuid=" + this.modelCustomizationUuid; + + ", modelCustomizationUuid=" + this.modelCustomizationUuid + + ", mode=" + mode; } } diff --git a/adapters/mso-adapter-utils/src/main/java/org/openecomp/mso/openstack/exceptions/MsoCloudIdentityNotFound.java b/adapters/mso-adapter-utils/src/main/java/org/openecomp/mso/openstack/exceptions/MsoCloudIdentityNotFound.java deleted file mode 100644 index 7e21d9d15a..0000000000 --- a/adapters/mso-adapter-utils/src/main/java/org/openecomp/mso/openstack/exceptions/MsoCloudIdentityNotFound.java +++ /dev/null @@ -1,49 +0,0 @@ -/*- - * ============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.openstack.exceptions; - -/** - * Signals that an attempt to find a specific mso cloud identity has failed. - */ -public class MsoCloudIdentityNotFound extends MsoException { - - private static final long serialVersionUID = 2583769056266415665L; - - - /** - * Default constructor (needed for BPEL/JAXB) - */ - public MsoCloudIdentityNotFound () { - super("Cloud Identity not found"); - super.category=MsoExceptionCategory.USERDATA; - } - - public MsoCloudIdentityNotFound (String cloudIdentity) { - // Set the detailed error as the Exception 'message' - super("Cloud Identity [" + cloudIdentity + "] not found"); - super.category=MsoExceptionCategory.USERDATA; - } - - @Override - public String toString () { - return getMessage(); - } -} diff --git a/adapters/mso-adapter-utils/src/main/java/org/openecomp/mso/openstack/exceptions/MsoCloudSiteNotFound.java b/adapters/mso-adapter-utils/src/main/java/org/openecomp/mso/openstack/exceptions/MsoCloudSiteNotFound.java deleted file mode 100644 index 7c6e98d55f..0000000000 --- a/adapters/mso-adapter-utils/src/main/java/org/openecomp/mso/openstack/exceptions/MsoCloudSiteNotFound.java +++ /dev/null @@ -1,48 +0,0 @@ -/*- - * ============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.openstack.exceptions; - -/** - * Signals that an attempt to find a specific mso cloud site has failed. - */ -public class MsoCloudSiteNotFound extends MsoException { - - private static final long serialVersionUID = 2583769056266415664L; - - /** - * Default constructor (needed for BPEL/JAXB) - */ - public MsoCloudSiteNotFound () { - super("Cloud site not found"); - super.category=MsoExceptionCategory.USERDATA; - } - - public MsoCloudSiteNotFound (String cloudSite) { - // Set the detailed error as the Exception 'message' - super("Cloud Site [" + cloudSite + "] not found"); - super.category=MsoExceptionCategory.USERDATA; - } - - @Override - public String toString () { - return getMessage(); - } -} diff --git a/adapters/mso-adapter-utils/src/main/java/org/openecomp/mso/openstack/exceptions/MsoException.java b/adapters/mso-adapter-utils/src/main/java/org/openecomp/mso/openstack/exceptions/MsoException.java deleted file mode 100644 index b8a7a5571c..0000000000 --- a/adapters/mso-adapter-utils/src/main/java/org/openecomp/mso/openstack/exceptions/MsoException.java +++ /dev/null @@ -1,66 +0,0 @@ -/*- - * ============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.openstack.exceptions; - - - -public abstract class MsoException extends Exception -{ - private static final long serialVersionUID = 1L; - - protected MsoExceptionCategory category = MsoExceptionCategory.INTERNAL; - protected String context = null; - - protected MsoException (String message) { - super(message); - } - - protected MsoException (String message, Throwable t) { - super(message,t); - } - - public MsoExceptionCategory getCategory() { - return category; - } - public void setCategory (MsoExceptionCategory category) { - this.category = category; - } - - public String getContext () { - return context; - } - public void setContext (String context) { - this.context = context; - } - public void addContext (String ctx) { - if (this.context != null) - this.context = ctx + ":" + this.context; - else - this.context = ctx; - } - - public String getContextMessage () { - if (this.context == null) - return getMessage(); - else - return "[" + context + "] " + getMessage(); - } -} diff --git a/adapters/mso-adapter-utils/src/main/java/org/openecomp/mso/openstack/exceptions/MsoExceptionCategory.java b/adapters/mso-adapter-utils/src/main/java/org/openecomp/mso/openstack/exceptions/MsoExceptionCategory.java deleted file mode 100644 index 81a0edc2d3..0000000000 --- a/adapters/mso-adapter-utils/src/main/java/org/openecomp/mso/openstack/exceptions/MsoExceptionCategory.java +++ /dev/null @@ -1,27 +0,0 @@ -/*- - * ============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.openstack.exceptions; - - - -public enum MsoExceptionCategory { - OPENSTACK, IO, INTERNAL, USERDATA -} diff --git a/adapters/mso-adapter-utils/src/main/java/org/openecomp/mso/openstack/exceptions/MsoIOException.java b/adapters/mso-adapter-utils/src/main/java/org/openecomp/mso/openstack/exceptions/MsoIOException.java deleted file mode 100644 index 9c7f6fa91a..0000000000 --- a/adapters/mso-adapter-utils/src/main/java/org/openecomp/mso/openstack/exceptions/MsoIOException.java +++ /dev/null @@ -1,53 +0,0 @@ -/*- - * ============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.openstack.exceptions; - - -/** - * I/O exception - */ -public class MsoIOException extends MsoException -{ - - /** - * Serialization id. - */ - private static final long serialVersionUID = 6752445132721635760L; - - /** - * Basic constructor with message - * @param message the error message - */ - public MsoIOException (String message) { - super(message); - super.category = MsoExceptionCategory.IO; - } - - /** - * Constructor to wrap a nested exception - * @param message the error message - * @param t the cause - */ - public MsoIOException (String message, Throwable t) { - super (message, t); - super.category = MsoExceptionCategory.IO; - } -} diff --git a/adapters/mso-adapter-utils/src/main/java/org/openecomp/mso/openstack/exceptions/MsoStackAlreadyExists.java b/adapters/mso-adapter-utils/src/main/java/org/openecomp/mso/openstack/exceptions/MsoStackAlreadyExists.java deleted file mode 100644 index 2901b6b3a7..0000000000 --- a/adapters/mso-adapter-utils/src/main/java/org/openecomp/mso/openstack/exceptions/MsoStackAlreadyExists.java +++ /dev/null @@ -1,35 +0,0 @@ -/*- - * ============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.openstack.exceptions; - - - -public class MsoStackAlreadyExists extends MsoOpenstackException { - - private static final long serialVersionUID = 1L; - - // Constructor to create a new MsoOpenstackException instance - public MsoStackAlreadyExists (String stack, String tenant, String cloud) { - // Set the detailed error as the Exception 'message' - super(409, "Conflict", "Stack " + stack + " already exists in Tenant + " + tenant + " in Cloud " + cloud); - } - -} diff --git a/adapters/mso-adapter-utils/src/main/java/org/openecomp/mso/openstack/exceptions/MsoStackNotFound.java b/adapters/mso-adapter-utils/src/main/java/org/openecomp/mso/openstack/exceptions/MsoStackNotFound.java deleted file mode 100644 index 21082a28c9..0000000000 --- a/adapters/mso-adapter-utils/src/main/java/org/openecomp/mso/openstack/exceptions/MsoStackNotFound.java +++ /dev/null @@ -1,44 +0,0 @@ -/*- - * ============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.openstack.exceptions; - - -/** - * Thrown when HEAT stack is not found or deleted. - */ -public class MsoStackNotFound extends MsoOpenstackException { - - /** - * Serialization id. - */ - private static final long serialVersionUID = 7354069716354359246L; - - /** - * Constructor to create a new MsoOpenstackException instance. - * @param stack the stack name - * @param tenant the tenant name - * @param cloud the cloud name - */ - public MsoStackNotFound (String stack, String tenant, String cloud) { - // Set the detailed error as the Exception 'message' - super(404, "Not Found", "Stack " + stack + " does not exist in Cloud/Tenant " + cloud + "/" + tenant); - } -} diff --git a/adapters/mso-adapter-utils/src/main/java/org/openecomp/mso/openstack/exceptions/MsoTenantNotFound.java b/adapters/mso-adapter-utils/src/main/java/org/openecomp/mso/openstack/exceptions/MsoTenantNotFound.java deleted file mode 100644 index f26d6b6d49..0000000000 --- a/adapters/mso-adapter-utils/src/main/java/org/openecomp/mso/openstack/exceptions/MsoTenantNotFound.java +++ /dev/null @@ -1,43 +0,0 @@ -/*- - * ============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.openstack.exceptions; - - -/** - * Tenant not found exception. - */ -public class MsoTenantNotFound extends MsoOpenstackException { - - /** - * Serialization id. - */ - private static final long serialVersionUID = 5640069939645577063L; - - /** - * Constructor to create the exception - * @param tenant the tenant id - * @param cloud the cloud id - */ - public MsoTenantNotFound (String tenant, String cloud) { - // Set the detailed error as the Exception 'message' - super(404, "Not Found", "Tenant " + tenant + " does not exist in Cloud " + cloud); - } -} diff --git a/adapters/mso-adapter-utils/src/main/java/org/openecomp/mso/openstack/utils/MsoHeatEnvironmentEntry.java b/adapters/mso-adapter-utils/src/main/java/org/openecomp/mso/openstack/utils/MsoHeatEnvironmentEntry.java index 04dbf523d0..92220f8717 100644 --- a/adapters/mso-adapter-utils/src/main/java/org/openecomp/mso/openstack/utils/MsoHeatEnvironmentEntry.java +++ b/adapters/mso-adapter-utils/src/main/java/org/openecomp/mso/openstack/utils/MsoHeatEnvironmentEntry.java @@ -21,81 +21,219 @@ package org.openecomp.mso.openstack.utils; + + +import java.util.HashSet; +import java.util.ArrayList; import java.util.Set; +import org.openecomp.mso.db.catalog.beans.HeatTemplateParam; import org.openecomp.mso.logger.MsoLogger; public class MsoHeatEnvironmentEntry { - private static final MsoLogger LOGGER = MsoLogger.getMsoLogger(MsoLogger.Catalog.RA); - private Set<MsoHeatEnvironmentParameter> parameters; - private String rawEntry; + private static final MsoLogger LOGGER = MsoLogger.getMsoLogger (MsoLogger.Catalog.RA); + + private Set<MsoHeatEnvironmentParameter> parameters = null; + private Set<MsoHeatEnvironmentResource> resources = null; + private StringBuilder rawEntry = null; private boolean valid = true; - private String errorString; - private String resourceRegistryEntryRaw; - - private MsoHeatEnvironmentEntry(String rawEntry) { - this.rawEntry = rawEntry; + private String errorString = null; + private StringBuilder resourceRegistryEntryRaw = null; + + public MsoHeatEnvironmentEntry() { + super(); } - - private MsoHeatEnvironmentEntry(Set<MsoHeatEnvironmentParameter> parameters, String rawEntry, boolean valid, - String errorString, String resourceRegistryEntryRaw) { - this.parameters = parameters; - this.rawEntry = rawEntry; - this.valid = valid; - this.errorString = errorString; - this.resourceRegistryEntryRaw = resourceRegistryEntryRaw; + + public MsoHeatEnvironmentEntry(StringBuilder sb) { + this(); + this.rawEntry = sb; + this.processRawEntry(); } - + + private void processRawEntry() { + try { + if (this.rawEntry == null || "".equals(this.rawEntry)) + return; + byte[] b = this.rawEntry.toString().getBytes(); + MsoYamlEditorWithEnvt yaml = new MsoYamlEditorWithEnvt(b); + this.parameters = yaml.getParameterListFromEnvt(); + //this.resources = yaml.getResourceListFromEnvt(); + StringBuilder sb = this.getResourceRegistryRawEntry(); + if (sb == null) { + this.resourceRegistryEntryRaw = new StringBuilder(""); + } else { + this.resourceRegistryEntryRaw = sb; + } + } catch (Exception e) { + LOGGER.debug("Exception:", e); + this.valid = false; + this.errorString = e.getMessage(); + //e.printStackTrace(); + } + } + public boolean isValid() { return this.valid; } public String getErrorString() { return this.errorString; } - + + public Set<MsoHeatEnvironmentParameter> getParameters() { + return this.parameters; + } + public Set<MsoHeatEnvironmentResource> getResources() { + return this.resources; + } + public void setParameters(Set<MsoHeatEnvironmentParameter> paramSet) { + if (paramSet == null) { + this.parameters = null; + } else { + this.parameters = paramSet; + } + } + public void setResources(Set<MsoHeatEnvironmentResource> resourceSet) { + if (resourceSet == null) { + this.resources = null; + } else { + this.resources = resourceSet; + } + } + + public void addParameter(MsoHeatEnvironmentParameter hep) { + if (this.parameters == null) { + this.parameters = new HashSet<>(); + } + this.parameters.add(hep); + } + public void addResource(MsoHeatEnvironmentResource her) { + if (this.resources == null) { + this.resources = new HashSet<>(); + } + this.resources.add(her); + } + + public int getNumberOfParameters() { + return this.parameters.size(); + } + public int getNumberOfResources() { + return this.resources.size(); + } + + public boolean hasResources() { + if (this.resources != null && this.resources.size() > 0) { + return true; + } + return false; + } + public boolean hasParameters() { + if (this.parameters != null && this.parameters.size() > 0) { + return true; + } + return false; + } + public boolean containsParameter(String paramName) { + boolean contains = false; if (this.parameters == null || this.parameters.size() < 1) { return false; } if (this.parameters.contains(new MsoHeatEnvironmentParameter(paramName))) { + contains = true; + } + return contains; + } + + public boolean containsParameter(String paramName, String paramAlias) { + if (this.containsParameter(paramName)) { + return true; + } + if (this.containsParameter(paramAlias)) { return true; } return false; } - + @Override public String toString() { return "MsoHeatEnvironmentEntry{" + "parameters=" + parameters + ", resourceRegistryEntryRaw='" + resourceRegistryEntryRaw + '\'' + '}'; } - - public String getRawEntry() { - return rawEntry; + + public StringBuilder toFullStringExcludeNonParams(Set<HeatTemplateParam> params) { + // Basically give back the envt - but exclude the params that aren't in the HeatTemplate + + StringBuilder sb = new StringBuilder(); + ArrayList<String> paramNameList = new ArrayList<String>(params.size()); + for (HeatTemplateParam htp : params) { + paramNameList.add(htp.getParamName()); + } + + if (this.hasParameters()) { + sb.append("parameters:\n"); + for (MsoHeatEnvironmentParameter hep : this.parameters) { + String paramName = hep.getName(); + if (paramNameList.contains(paramName)) { + // This parameter *is* in the Heat Template - so include it: + sb.append(" " + hep.getName() + ": " + hep.getValue() + "\n"); + // New - 1607 - if any of the params mapped badly - JUST RETURN THE ORIGINAL ENVT! + if (hep.getValue().startsWith("_BAD")) { + return this.rawEntry; + } + } + } + sb.append("\n"); + } +// if (this.hasResources()) { +// sb.append("resource_registry:\n"); +// for (MsoHeatEnvironmentResource her : this.resources) { +// sb.append(" \"" + her.getName() + "\": " + her.getValue() + "\n"); +// } +// } + sb.append("\n"); + sb.append(this.resourceRegistryEntryRaw); + return sb; } - private static String getResourceRegistryRawEntry(String rawEntry) { - int indexOf = rawEntry.indexOf("resource_registry:"); - if (indexOf < 0) { - return ""; + public StringBuilder toFullString() { + StringBuilder sb = new StringBuilder(); + + if (this.hasParameters()) { + sb.append("parameters:\n"); + for (MsoHeatEnvironmentParameter hep : this.parameters) { + sb.append(" " + hep.getName() + ": " + hep.getValue() + "\n"); + } + sb.append("\n"); } - return rawEntry.substring(indexOf); +// if (this.hasResources()) { +// sb.append("resource_registry:\n"); +// for (MsoHeatEnvironmentResource her : this.resources) { +// sb.append(" \"" + her.getName() + "\": " + her.getValue() + "\n"); +// } +// } + sb.append("\n"); + sb.append(this.resourceRegistryEntryRaw); + return sb; } - - public static MsoHeatEnvironmentEntry create(String rawEntry) { - if (rawEntry == null || rawEntry.isEmpty()) { - return new MsoHeatEnvironmentEntry(rawEntry); + + public StringBuilder getRawEntry() { + return this.rawEntry; + } + + private StringBuilder getResourceRegistryRawEntry() { + + if (this.rawEntry == null) { + return null; } - try { - Set<MsoHeatEnvironmentParameter> parameters = new MsoYamlEditorWithEnvt(rawEntry.getBytes()) - .getParameterListFromEnvt(); - return new MsoHeatEnvironmentEntry(parameters, rawEntry, true, null, - getResourceRegistryRawEntry(rawEntry)); - } catch (Exception e) { - LOGGER.debug(String.format("An exception occurred during processing the following raw entry: %s", rawEntry), - e); - return new MsoHeatEnvironmentEntry(null, rawEntry, false, e.getMessage(), null); + + StringBuilder sb = new StringBuilder(); + int indexOf = this.rawEntry.indexOf("resource_registry:"); + if (indexOf < 0) { // no resource_registry: + return null; } + sb.append(this.rawEntry.substring(indexOf)); + return sb; } - + } diff --git a/adapters/mso-adapter-utils/src/main/java/org/openecomp/mso/openstack/utils/MsoHeatUtils.java b/adapters/mso-adapter-utils/src/main/java/org/openecomp/mso/openstack/utils/MsoHeatUtils.java index 6862492d7e..7dd14d865c 100644 --- a/adapters/mso-adapter-utils/src/main/java/org/openecomp/mso/openstack/utils/MsoHeatUtils.java +++ b/adapters/mso-adapter-utils/src/main/java/org/openecomp/mso/openstack/utils/MsoHeatUtils.java @@ -30,10 +30,6 @@ import java.util.List; import java.util.Map; import java.util.Set; -import org.codehaus.jackson.map.ObjectMapper; -import org.codehaus.jackson.JsonNode; -import org.codehaus.jackson.JsonParseException; - import org.openecomp.mso.cloud.CloudConfig; import org.openecomp.mso.cloud.CloudConfigFactory; import org.openecomp.mso.cloud.CloudIdentity; @@ -55,6 +51,10 @@ import org.openecomp.mso.openstack.exceptions.MsoTenantNotFound; import org.openecomp.mso.properties.MsoJavaProperties; import org.openecomp.mso.properties.MsoPropertiesException; import org.openecomp.mso.properties.MsoPropertiesFactory; + +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.databind.JsonNode; +import com.fasterxml.jackson.databind.ObjectMapper; import com.woorea.openstack.base.client.OpenStackConnectException; import com.woorea.openstack.base.client.OpenStackRequest; import com.woorea.openstack.base.client.OpenStackResponseException; @@ -359,6 +359,21 @@ public class MsoHeatUtils extends MsoCommonUtils { stack.setFiles (heatFiles); } } + + // 1802 - attempt to add better formatted printout of request to openstack + try { + Map<String, Object> inputs = new HashMap<String, Object>(); + for (String key : stackInputs.keySet()) { + Object o = (Object) stackInputs.get(key); + if (o != null) { + inputs.put(key, o); + } + } + LOGGER.debug(this.printStackRequest(tenantId, heatFiles, files, environment, inputs, stackName, heatTemplate, timeoutMinutes, backout, cloudSiteId)); + } catch (Exception e) { + // that's okay - this is a nice-to-have + LOGGER.debug("(had an issue printing nicely formatted request to debuglog) " + e.getMessage()); + } Stack heatStack = null; try { @@ -372,7 +387,7 @@ public class MsoHeatUtils extends MsoCommonUtils { request.header ("X-Auth-User", cloudIdentity.getMsoId ()); request.header ("X-Auth-Key", cloudIdentity.getMsoPass ()); LOGGER.debug ("headers added, about to executeAndRecordOpenstackRequest"); - LOGGER.debug(this.requestToStringBuilder(stack).toString()); + //LOGGER.debug(this.requestToStringBuilder(stack).toString()); // END - try to fix X-Auth-User heatStack = executeAndRecordOpenstackRequest (request, msoProps); } catch (OpenStackResponseException e) { @@ -1416,7 +1431,7 @@ public class MsoHeatUtils extends MsoCommonUtils { * (heat variable type) -> java Object type * string -> String * number -> Integer - * json -> JsonNode + * json -> JsonNode XXX Removed with MSO-1475 / 1802 * comma_delimited_list -> ArrayList * boolean -> Boolean * if any of the conversions should fail, we will default to adding it to the inputs @@ -1506,26 +1521,14 @@ public class MsoHeatUtils extends MsoCommonUtils { newInputs.put(key, integerString); } } else if ("json".equalsIgnoreCase(type)) { + // MSO-1475 - Leave this as a string now String jsonString = inputs.get(key); - JsonNode jsonNode = null; - try { - jsonNode = new ObjectMapper().readTree(jsonString); - } catch (Exception e) { - LOGGER.debug("Unable to convert " + jsonString + " to a JsonNode!!", e); - jsonNode = null; - } - if (jsonNode != null) { - if (alias) - newInputs.put(realName, jsonNode); - else - newInputs.put(key, jsonNode); - } - else { - if (alias) - newInputs.put(realName, jsonString); - else - newInputs.put(key, jsonString); - } + LOGGER.debug("Skipping conversion to jsonNode..."); + if (alias) + newInputs.put(realName, jsonString); + else + newInputs.put(key, jsonString); + //} } else if ("comma_delimited_list".equalsIgnoreCase(type)) { String commaSeparated = inputs.get(key); try { @@ -1559,5 +1562,85 @@ public class MsoHeatUtils extends MsoCommonUtils { } return newInputs; } - + + + /* + * Create a string suitable for being dumped to a debug log that creates a + * pseudo-JSON request dumping what's being sent to Openstack API in the create or update request + */ + + private String printStackRequest(String tenantId, + Map<String, Object> heatFiles, + Map<String, Object> nestedTemplates, + String environment, + Map<String, Object> inputs, + String vfModuleName, + String template, + int timeoutMinutes, + boolean backout, + String cloudSiteId) { + StringBuffer sb = new StringBuffer(); + sb.append("CREATE STACK REQUEST (formatted for readability)\n"); + sb.append("tenant=" + tenantId + ", cloud=" + cloudSiteId); + sb.append("{\n"); + sb.append(" \"stack_name\": \"" + vfModuleName + "\",\n"); + sb.append(" \"disable_rollback\": " + backout + ",\n"); + sb.append(" \"timeout_mins\": " + timeoutMinutes + ",\n"); + sb.append(" \"template\": {\n"); + sb.append(template); + sb.append(" },\n"); + sb.append(" \"environment\": {\n"); + if (environment == null) + sb.append("<none>"); + else + sb.append(environment); + sb.append(" },\n"); + sb.append(" \"files\": {\n"); + int filesCounter = 0; + if (heatFiles != null) { + for (String key : heatFiles.keySet()) { + filesCounter++; + if (filesCounter > 1) { + sb.append(",\n"); + } + sb.append(" \"" + key + "\": {\n"); + sb.append(heatFiles.get(key).toString() + "\n }"); + } + } + if (nestedTemplates != null) { + for (String key : nestedTemplates.keySet()) { + filesCounter++; + if (filesCounter > 1) { + sb.append(",\n"); + } + sb.append(" \"" + key + "\": {\n"); + sb.append(nestedTemplates.get(key).toString() + "\n }"); + } + } + sb.append("\n },\n"); + sb.append(" \"parameters\": {\n"); + int paramCounter = 0; + for (String name : inputs.keySet()) { + paramCounter++; + if (paramCounter > 1) { + sb.append(",\n"); + } + Object o = inputs.get(name); + if (o instanceof java.lang.String) { + sb.append(" \"" + name + "\": \"" + inputs.get(name).toString() + "\""); + } else if (o instanceof Integer) { + sb.append(" \"" + name + "\": " + inputs.get(name).toString() ); + } else if (o instanceof ArrayList) { + sb.append(" \"" + name + "\": " + inputs.get(name).toString() ); + } else if (o instanceof Boolean) { + sb.append(" \"" + name + "\": " + inputs.get(name).toString() ); + } else { + sb.append(" \"" + name + "\": " + "\"(there was an issue trying to dump this value...)\"" ); + } + } + sb.append("\n }\n}\n"); + + return sb.toString(); + } + } diff --git a/adapters/mso-adapter-utils/src/main/java/org/openecomp/mso/openstack/utils/MsoHeatUtilsWithUpdate.java b/adapters/mso-adapter-utils/src/main/java/org/openecomp/mso/openstack/utils/MsoHeatUtilsWithUpdate.java index 75bb00351c..595da58270 100644 --- a/adapters/mso-adapter-utils/src/main/java/org/openecomp/mso/openstack/utils/MsoHeatUtilsWithUpdate.java +++ b/adapters/mso-adapter-utils/src/main/java/org/openecomp/mso/openstack/utils/MsoHeatUtilsWithUpdate.java @@ -26,10 +26,6 @@ import java.util.HashMap; import java.util.List; import java.util.Map; -import org.codehaus.jackson.JsonNode; -import org.codehaus.jackson.JsonParseException; -import org.codehaus.jackson.map.ObjectMapper; - import org.openecomp.mso.cloud.CloudConfigFactory; import org.openecomp.mso.cloud.CloudSite; import org.openecomp.mso.logger.MessageEnum; @@ -42,12 +38,16 @@ import org.openecomp.mso.openstack.exceptions.MsoStackNotFound; import org.openecomp.mso.properties.MsoJavaProperties; import org.openecomp.mso.properties.MsoPropertiesException; import org.openecomp.mso.properties.MsoPropertiesFactory; + +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.databind.JsonNode; +import com.fasterxml.jackson.databind.ObjectMapper; import com.woorea.openstack.base.client.OpenStackBaseException; import com.woorea.openstack.base.client.OpenStackRequest; import com.woorea.openstack.heat.Heat; import com.woorea.openstack.heat.model.Stack; -import com.woorea.openstack.heat.model.UpdateStackParam; import com.woorea.openstack.heat.model.Stack.Output; +import com.woorea.openstack.heat.model.UpdateStackParam; public class MsoHeatUtilsWithUpdate extends MsoHeatUtils { diff --git a/adapters/mso-adapter-utils/src/main/java/org/openecomp/mso/openstack/utils/MsoKeystoneUtils.java b/adapters/mso-adapter-utils/src/main/java/org/openecomp/mso/openstack/utils/MsoKeystoneUtils.java index 3b710032c1..018396d6ec 100644 --- a/adapters/mso-adapter-utils/src/main/java/org/openecomp/mso/openstack/utils/MsoKeystoneUtils.java +++ b/adapters/mso-adapter-utils/src/main/java/org/openecomp/mso/openstack/utils/MsoKeystoneUtils.java @@ -383,7 +383,9 @@ public class MsoKeystoneUtils extends MsoTenantUtils { // Get the Identity service URL. Throws runtime exception if not found per region. String adminUrl = null; try { - adminUrl = KeystoneUtils.findEndpointURL (access.getServiceCatalog (), "identity", region, "admin"); + // TODO: FOR TESTING!!!! + adminUrl = KeystoneUtils.findEndpointURL (access.getServiceCatalog (), "identity", region, "public"); + adminUrl = adminUrl.replaceFirst("5000", "35357"); } catch (RuntimeException e) { String error = "Identity service not found: region=" + region + ",cloud=" + cloudIdentity.getId (); alarmLogger.sendAlarm ("MsoConfigurationError", MsoAlarmLogger.CRITICAL, error); diff --git a/adapters/mso-adapter-utils/src/main/java/org/openecomp/mso/openstack/utils/MsoTenantUtilsFactory.java b/adapters/mso-adapter-utils/src/main/java/org/openecomp/mso/openstack/utils/MsoTenantUtilsFactory.java index e36d46841d..cc9e869608 100644 --- a/adapters/mso-adapter-utils/src/main/java/org/openecomp/mso/openstack/utils/MsoTenantUtilsFactory.java +++ b/adapters/mso-adapter-utils/src/main/java/org/openecomp/mso/openstack/utils/MsoTenantUtilsFactory.java @@ -20,28 +20,30 @@ package org.openecomp.mso.openstack.utils; +import java.lang.reflect.InvocationTargetException; + import org.openecomp.mso.cloud.CloudConfig; import org.openecomp.mso.cloud.CloudConfigFactory; import org.openecomp.mso.cloud.CloudIdentity; import org.openecomp.mso.cloud.CloudSite; - -import java.lang.reflect.InvocationTargetException; +import org.openecomp.mso.logger.MsoLogger; import org.openecomp.mso.openstack.exceptions.MsoCloudSiteNotFound; public class MsoTenantUtilsFactory { - private CloudConfigFactory cloudConfigFactory= new CloudConfigFactory(); + private static MsoLogger LOGGER = MsoLogger.getMsoLogger (MsoLogger.Catalog.RA); + private CloudConfigFactory cloudConfigFactory= new CloudConfigFactory(); private CloudConfig cloudConfig; private String msoPropID; - + public MsoTenantUtilsFactory (String msoPropID) { this.msoPropID = msoPropID; } //based on Cloud IdentityServerType returns ORM or KEYSTONE Utils public MsoTenantUtils getTenantUtils(String cloudSiteId) throws MsoCloudSiteNotFound { - // Obtain the cloud site information + // Obtain the cloud site information cloudConfig = cloudConfigFactory.getCloudConfig(); CloudSite cloudSite = cloudConfig.getCloudSite(cloudSiteId).orElseThrow( () -> new MsoCloudSiteNotFound(cloudSiteId)); @@ -50,7 +52,7 @@ public class MsoTenantUtilsFactory { public MsoTenantUtils getTenantUtilsByServerType(String serverType) { - MsoTenantUtils tenantU; + MsoTenantUtils tenantU = null; if (CloudIdentity.IdentityServerType.KEYSTONE.toString().equals(serverType)) { tenantU = new MsoKeystoneUtils (msoPropID); } else { diff --git a/adapters/mso-adapter-utils/src/main/java/org/openecomp/mso/openstack/utils/MsoYamlEditorWithEnvt.java b/adapters/mso-adapter-utils/src/main/java/org/openecomp/mso/openstack/utils/MsoYamlEditorWithEnvt.java index 8002087ddd..8704911e26 100644 --- a/adapters/mso-adapter-utils/src/main/java/org/openecomp/mso/openstack/utils/MsoYamlEditorWithEnvt.java +++ b/adapters/mso-adapter-utils/src/main/java/org/openecomp/mso/openstack/utils/MsoYamlEditorWithEnvt.java @@ -32,7 +32,7 @@ import java.util.Map; import java.util.Set; import java.util.Map.Entry; import org.openecomp.mso.db.catalog.beans.HeatTemplateParam; -import org.codehaus.jackson.map.ObjectMapper; +import com.fasterxml.jackson.databind.ObjectMapper; import org.yaml.snakeyaml.Yaml; |