diff options
author | ChrisC <cc697w@intl.att.com> | 2017-01-31 11:40:03 +0100 |
---|---|---|
committer | ChrisC <cc697w@intl.att.com> | 2017-01-31 12:59:33 +0100 |
commit | 025301d08b061482c1f046d562bf017c8cbcfe8d (patch) | |
tree | 68a2a549736c9bf0f7cd4e71c76e40ef7e2606f2 /adapters/mso-adapter-utils/src | |
parent | 2754ad52f833278a5c925bd788a16d1dce16a598 (diff) |
Initial OpenECOMP MSO commit
Change-Id: Ia6a7574859480717402cc2f22534d9973a78fa6d
Signed-off-by: ChrisC <cc697w@intl.att.com>
Diffstat (limited to 'adapters/mso-adapter-utils/src')
89 files changed, 12243 insertions, 0 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 new file mode 100644 index 0000000000..abcea2d494 --- /dev/null +++ b/adapters/mso-adapter-utils/src/main/java/org/openecomp/mso/cloud/CloudConfig.java @@ -0,0 +1,262 @@ +/*- + * ============LICENSE_START======================================================= + * OPENECOMP - MSO + * ================================================================================ + * 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.io.FileReader; +import java.io.IOException; +import java.util.HashMap; +import java.util.Map; +import java.util.Map.Entry; + +import org.codehaus.jackson.JsonParseException; +import org.codehaus.jackson.annotate.JsonProperty; +import org.codehaus.jackson.map.DeserializationConfig; +import org.codehaus.jackson.map.JsonMappingException; +import org.codehaus.jackson.map.ObjectMapper; +import org.codehaus.jackson.map.annotate.JsonRootName; + +import org.openecomp.mso.logger.MsoLogger; + +/** + * 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 (in particular for the NVP/AIC cloud). + * 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 config file, so there are no explicit property setters. + * + * This class also contains methods to query cloud sites and/or identity + * services by ID. + * + */ + +@JsonRootName("cloud_config") +public class CloudConfig { + + @JsonProperty("identity_services") + private Map <String, CloudIdentity> identityServices = new HashMap <String, CloudIdentity> (); + @JsonProperty("cloud_sites") + private Map <String, CloudSite> cloudSites = new HashMap <String, CloudSite> (); + + private static ObjectMapper mapper = new ObjectMapper (); + + private static final MsoLogger LOGGER = MsoLogger.getMsoLogger (MsoLogger.Catalog.RA); + + protected String configFilePath; + + protected int refreshTimerInMinutes; + + public CloudConfig () { + mapper.enable (DeserializationConfig.Feature.UNWRAP_ROOT_VALUE); + mapper.enable (DeserializationConfig.Feature.ACCEPT_SINGLE_VALUE_AS_ARRAY); + } + + /** + * Get a Map of all IdentityServices that have been loaded. + * @return the Map + */ + public synchronized Map <String, CloudIdentity> getIdentityServices () { + return identityServices; + } + + /** + * Get a Map of all CloudSites that have been loaded. + * @return the Map + */ + public synchronized Map <String, CloudSite> getCloudSites () { + return cloudSites; + } + + /** + * 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 individual entries + * to try and find one with a CLLI that matches the ID and an AIC version of 2.5. + * @param id the ID to match + * @return a CloudSite, or null of no match found + */ + public synchronized CloudSite getCloudSite (String id) { + if (id != null) { + if (cloudSites.containsKey (id)) { + return cloudSites.get (id); + } + // check for id == CLLI now as well + return getCloudSiteWithClli(id, "2.5"); + } + return null; + } + + /** + * Get a specific CloudSites, based on a CLLI and (optional) version, which will be matched + * against the aic_version field of the CloudSite. + * @param clli the CLLI to match + * @param version the version to match; may be null in which case any version matches + * @return a CloudSite, or null of no match found + */ + public synchronized CloudSite getCloudSiteWithClli(String clli, String version) { + if (clli != null) { + // New with 1610 - find cloud site called "DEFAULT" - return that object, + // with the name modified to match what they asked for. We're looping thru + // the cloud sites anyway - so save off the default one in case we need it. + CloudSite defaultCloudSite = null; + for (CloudSite cs : cloudSites.values()) { + if (cs.getClli() != null && clli.equals(cs.getClli())) { + if (version == null || version.equals(cs.getAic_version())) { + return cs; + } + } else if (cs.getId().equalsIgnoreCase("default")) { + // save it off in case we need it + defaultCloudSite = cs.clone(); + } + } + // If we get here - we didn't find a match - so return the default cloud site + if (defaultCloudSite != null) { + defaultCloudSite.setRegionId(clli); + defaultCloudSite.setId(clli); + } + return defaultCloudSite; + } + return null; + } + + /** + * Get a specific CloudIdentity, based on an ID. + * @param id the ID to match + * @return a CloudIdentity, or null of no match found + */ + public synchronized CloudIdentity getIdentityService (String id) { + if (identityServices.containsKey (id)) { + return identityServices.get (id); + } + return null; + } + + protected synchronized void reloadPropertiesFile() throws JsonParseException, JsonMappingException, IOException { + this.loadCloudConfig(this.configFilePath, this.refreshTimerInMinutes); + } + + protected synchronized void loadCloudConfig (String configFile, int refreshTimer) throws JsonParseException, JsonMappingException, IOException { + + FileReader reader=null; + configFilePath=configFile; + this.refreshTimerInMinutes = refreshTimer; + + CloudConfig cloudConfig = null; + + try { + reader = new FileReader (configFile); + // Parse the JSON input into a CloudConfig + + cloudConfig = mapper.readValue (reader, CloudConfig.class); + + this.cloudSites = cloudConfig.cloudSites; + this.identityServices = cloudConfig.identityServices; + + // Copy Cloud Identity IDs to CloudIdentity objects + for (Entry <String, CloudIdentity> entry : cloudConfig.getIdentityServices ().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 ()) { + CloudSite s = entry.getValue (); + s.setId (entry.getKey ()); + s.setIdentityService (cloudConfig.getIdentityService (s.getIdentityServiceId ())); + } + } finally { + try { + if (reader != null) { + reader.close(); + } + } catch (IOException e) { + LOGGER.debug("Exception while closing reader for file:" + configFilePath, e); + } + } + } + + public String getConfigFilePath() { + return configFilePath; + } + + @Override + 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()); + } + + ccCopy.configFilePath = this.configFilePath; + + ccCopy.refreshTimerInMinutes = this.refreshTimerInMinutes; + + return ccCopy; + } + + @Override + public int hashCode() { + final int prime = 31; + int result = 1; + result = prime * result + ((cloudSites == null) ? 0 : cloudSites.hashCode()); + result = prime * result + ((configFilePath == null) ? 0 : configFilePath.hashCode()); + result = prime * result + ((identityServices == null) ? 0 : identityServices.hashCode()); + result = prime * result + refreshTimerInMinutes; + return result; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) + return true; + if (obj == null) + return false; + if (getClass() != obj.getClass()) + return false; + CloudConfig other = (CloudConfig) obj; + if (cloudSites == null) { + if (other.cloudSites != null) + return false; + } else if (!cloudSites.equals(other.cloudSites)) + return false; + if (configFilePath == null) { + if (other.configFilePath != null) + return false; + } else if (!configFilePath.equals(other.configFilePath)) + return false; + if (identityServices == null) { + if (other.identityServices != null) + return false; + } else if (!identityServices.equals(other.identityServices)) + return false; + if (refreshTimerInMinutes != other.refreshTimerInMinutes) + return false; + 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 new file mode 100644 index 0000000000..6ee6721083 --- /dev/null +++ b/adapters/mso-adapter-utils/src/main/java/org/openecomp/mso/cloud/CloudConfigFactory.java @@ -0,0 +1,226 @@ +/*- + * ============LICENSE_START======================================================= + * OPENECOMP - MSO + * ================================================================================ + * 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.io.IOException; +import java.io.Serializable; +import java.util.concurrent.TimeUnit; +import java.util.concurrent.locks.ReentrantReadWriteLock; + +import javax.ejb.ConcurrencyManagement; +import javax.ejb.ConcurrencyManagementType; +import javax.ejb.LocalBean; +import javax.ejb.Schedule; +import javax.ejb.Singleton; +import javax.ws.rs.GET; +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.MsoLogger; +import org.openecomp.mso.openstack.utils.MsoHeatUtils; +import org.openecomp.mso.openstack.utils.MsoKeystoneUtils; +import org.openecomp.mso.openstack.utils.MsoNeutronUtils; +import org.openecomp.mso.properties.MsoPropertiesException; +import org.openecomp.mso.logger.MessageEnum; + +/** + * This class returns a cloud Config instances + * + * + */ + +@Singleton(name = "CloudConfigFactory") +@ConcurrencyManagement(ConcurrencyManagementType.BEAN) +@LocalBean +@Path("/cloud") +public class CloudConfigFactory implements Serializable { + + private static final long serialVersionUID = 2956662716453261085L; + + private static CloudConfig cloudConfigCache = new CloudConfig (); + + protected static String prefixMsoPropertiesPath = System.getProperty ("mso.config.path"); + + private static final MsoLogger LOGGER = MsoLogger.getMsoLogger (MsoLogger.Catalog.RA); + + private static int refreshTimer; + + private static final ReentrantReadWriteLock rwl = new ReentrantReadWriteLock (); + + static { + if (prefixMsoPropertiesPath == null) { + prefixMsoPropertiesPath = ""; + } + } + + public void initializeCloudConfig (String filePath, int refreshTimer) { + + rwl.writeLock ().lock (); + try { + cloudConfigCache.loadCloudConfig (prefixMsoPropertiesPath + filePath, refreshTimer); + LOGGER.info (MessageEnum.RA_CONFIG_LOAD, prefixMsoPropertiesPath + filePath, "", ""); + } catch (JsonParseException e) { + LOGGER.error (MessageEnum.RA_CONFIG_EXC, "Error parsing cloud config file " + filePath, "", "", MsoLogger.ErrorCode.DataError, "Exception - JsonParseException", e); + } catch (JsonMappingException e) { + LOGGER.error (MessageEnum.RA_CONFIG_EXC, "Error parsing cloud config file " + filePath, "", "", MsoLogger.ErrorCode.DataError, "Exception - JsonMappingException", e); + } catch (IOException e) { + LOGGER.error (MessageEnum.RA_CONFIG_NOT_FOUND, filePath, "", "", MsoLogger.ErrorCode.DataError, "Exception - config not found", e); + } finally { + rwl.writeLock ().unlock (); + } + } + + public void changeMsoPropertiesFilePath (String newMsoPropPath) throws MsoPropertiesException { + rwl.writeLock ().lock (); + try { + CloudConfigFactory.cloudConfigCache.configFilePath = prefixMsoPropertiesPath + newMsoPropPath; + } finally { + rwl.writeLock ().unlock (); + } + } + + public CloudConfigFactory () { + } + + public CloudConfig getCloudConfig () { + rwl.readLock ().lock (); + try { + return cloudConfigCache.clone (); + } finally { + rwl.readLock ().unlock (); + } + } + + /** + * This method is not intended to be called, it's used to refresh the config + * automatically + * + * @return true if Properties have been reloaded, false otherwise + */ + @Schedule(minute = "*/1", hour = "*", persistent = false) + public void reloadCloudConfig () { + + try { + if (!rwl.writeLock ().tryLock () && !rwl.writeLock ().tryLock (30L, TimeUnit.SECONDS)) { + LOGGER.debug ("Busy write lock on mso cloud config factory, skipping the reloading"); + return; + } + } catch (InterruptedException e1) { + LOGGER.debug ("Interrupted while trying to acquire write lock on cloud config factory, skipping the reloading"); + Thread.currentThread ().interrupt (); + return; + } + try { + //LOGGER.debug ("Processing a reload of the mso properties file entries"); + try { + + if (refreshTimer <= 1) { + CloudConfig oldCloudConfig = cloudConfigCache.clone(); + cloudConfigCache.reloadPropertiesFile (); + refreshTimer = cloudConfigCache.refreshTimerInMinutes; + if (!cloudConfigCache.equals(oldCloudConfig)) { + LOGGER.info (MessageEnum.RA_CONFIG_LOAD, prefixMsoPropertiesPath + cloudConfigCache.configFilePath, "", ""); + } + + } else { + --refreshTimer; + } + + } catch (JsonParseException e) { + LOGGER.error (MessageEnum.RA_CONFIG_EXC, + "Error parsing cloud config file " + cloudConfigCache.configFilePath, "", "", MsoLogger.ErrorCode.DataError, "Exception - JsonParseException", + e); + } catch (JsonMappingException e) { + LOGGER.error (MessageEnum.RA_CONFIG_EXC, + "Error parsing cloud config file " + cloudConfigCache.configFilePath, "", "", MsoLogger.ErrorCode.DataError, "Exception - JsonMappingException", + e); + } catch (IOException e) { + LOGGER.error (MessageEnum.RA_CONFIG_NOT_FOUND, cloudConfigCache.configFilePath, "", "", MsoLogger.ErrorCode.DataError, "Exception - config not found", e); + } + } catch (Exception e) { + LOGGER.error (MessageEnum.LOAD_PROPERTIES_FAIL, "Unknown. Global issue while reloading", "", "", MsoLogger.ErrorCode.DataError, "Exception - Global issue while reloading\"", e); + } finally { + rwl.writeLock ().unlock (); + } + } + + @GET + @Path("/showConfig") + @Produces("text/plain") + public Response showCloudConfig () { + CloudConfig cloudConfig = this.getCloudConfig (); + + StringBuffer response = new StringBuffer (); + response.append ("Cloud Sites:\n"); + for (CloudSite site : cloudConfig.getCloudSites ().values ()) { + response.append (site.toString () + "\n"); + } + + response.append ("\n\nCloud Identity Services:\n"); + for (CloudIdentity identity : cloudConfig.getIdentityServices ().values ()) { + response.append (identity.toString () + "\n"); + } + + return Response.status (200).entity (response).build (); + } + + @GET + @Path("/resetClientCaches") + @Produces("text/plain") + public Response resetClientCaches () { + // Reset all cached clients/credentials + MsoKeystoneUtils.adminCacheReset (); + MsoHeatUtils.heatCacheReset (); + MsoNeutronUtils.neutronCacheReset (); + + String response = "Client caches reset. All entries removed."; + return Response.status (200).entity (response).build (); + } + + @GET + @Path("/cleanupClientCaches") + @Produces("text/plain") + public Response cleanupClientCaches () { + // Reset all cached clients/credentials + MsoKeystoneUtils.adminCacheCleanup (); + MsoHeatUtils.heatCacheCleanup (); + MsoNeutronUtils.neutronCacheCleanup (); + + String response = "Client caches cleaned up. All expired entries removed"; + return Response.status (200).entity (response).build (); + } + + @GET + @Path("/encryptPassword/{pwd}") + @Produces("text/plain") + public Response encryptPassword (@PathParam("pwd") String pwd) { + String encryptedPassword = CloudIdentity.encryptPassword (pwd); + + String response = "Encrypted Password = " + encryptedPassword; + return Response.status (200).entity (response).build (); + } +} 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 new file mode 100644 index 0000000000..a777e4133c --- /dev/null +++ b/adapters/mso-adapter-utils/src/main/java/org/openecomp/mso/cloud/CloudIdentity.java @@ -0,0 +1,316 @@ +/*- + * ============LICENSE_START======================================================= + * OPENECOMP - MSO + * ================================================================================ + * 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 org.codehaus.jackson.annotate.JsonProperty; +import org.openecomp.mso.openstack.exceptions.MsoException; +import org.openecomp.mso.logger.MessageEnum; +import org.openecomp.mso.logger.MsoLogger; +import com.woorea.openstack.keystone.model.authentication.RackspaceAuthentication; +import com.woorea.openstack.keystone.model.authentication.UsernamePassword; +import org.openecomp.mso.utils.CryptoUtils; +import com.woorea.openstack.keystone.model.Authentication; + +/** + * JavaBean JSON class for a CloudIdentity. This bean represents a cloud identity + * service instance (i.e. a DCP node) in the NVP/AIC cloud. It will be loaded via + * CloudConfig object, of which it is a component (a CloudConfig JSON configuration + * file may contain multiple CloudIdentity definitions). + * + * Note that this is only used to access Cloud Configurations loaded from a + * JSON config file, so there are no explicit setters. + * + */ +public class CloudIdentity { + + private static MsoLogger LOGGER = MsoLogger.getMsoLogger (MsoLogger.Catalog.RA); + + public enum IdentityServerType {KEYSTONE}; + + public enum IdentityAuthenticationType { USERNAME_PASSWORD, RACKSPACE_APIKEY }; + + @JsonProperty + private String id; + @JsonProperty("identity_url") + private String identityUrl; + @JsonProperty("mso_id") + private String msoId; + @JsonProperty("mso_pass") + private String msoPass; + @JsonProperty("admin_tenant") + private String adminTenant; + @JsonProperty("member_role") + private String memberRole; + @JsonProperty("tenant_metadata") + private Boolean tenantMetadata; + @JsonProperty("identity_server_type") + private IdentityServerType identityServerType; + @JsonProperty("identity_authentication_type") + private IdentityAuthenticationType identityAuthenticationType; + + private static String cloudKey = "aa3871669d893c7fb8abbcda31b88b4f"; + + public CloudIdentity () { + } + + public String getId () { + return id; + } + + public void setId (String id) { + this.id = id; + } + + //DEPRECATED + public String getKeystoneUrl () throws MsoException { + if (this.identityServerType.equals(IdentityServerType.KEYSTONE)) + return this.identityUrl; + else + return null; + } + + public String getKeystoneUrl (String regionId, String msoPropID) throws MsoException { + if (IdentityServerType.KEYSTONE.equals(this.identityServerType)) { + return this.identityUrl; + } + else { + return null; + } + } + + public Authentication getAuthentication () throws MsoException { + if (IdentityAuthenticationType.RACKSPACE_APIKEY.equals(this.identityAuthenticationType)) { + return new RackspaceAuthentication (this.getMsoId (),this.getMsoPass ()); + } + else { + // Use default case + return new UsernamePassword (this.getMsoId (),this.getMsoPass ()); + } + + } + + public void setKeystoneUrl (String url) { + if (IdentityServerType.KEYSTONE.equals(this.identityServerType)) { + this.identityUrl = url; + } + } + + public String getIdentityUrl() { + return this.identityUrl; + } + public void setIdentityUrl(String url) { + this.identityUrl = url; + } + + public String getMsoId () { + return msoId; + } + + public void setMsoId (String id) { + this.msoId = id; + } + + public String getMsoPass () { + try { + return CryptoUtils.decrypt (msoPass, cloudKey); + } catch (GeneralSecurityException e) { + LOGGER.error (MessageEnum.RA_GENERAL_EXCEPTION, "", "", MsoLogger.ErrorCode.BusinessProcesssError, "Exception in getMsoPass", e); + return null; + } + } + + public void setMsoPass (String pwd) { + this.msoPass = pwd; + } + + public String getAdminTenant () { + return adminTenant; + } + + public void setAdminTenant (String tenant) { + this.adminTenant = tenant; + } + + public String getMemberRole () { + return memberRole; + } + + public void setMemberRole (String role) { + this.memberRole = role; + } + + public boolean hasTenantMetadata () { + return tenantMetadata; + } + + public void setTenantMetadata (boolean meta) { + this.tenantMetadata = meta; + } + + public IdentityServerType getIdentityServerType() { + return this.identityServerType; + } + public void setIdentityServerType(IdentityServerType ist) { + this.identityServerType = ist; + } + public String getIdentityServerTypeAsString() { + return this.identityServerType.toString(); + } + /** + * @return the identityAuthenticationType + */ + public IdentityAuthenticationType getIdentityAuthenticationType() { + return identityAuthenticationType; + } + + /** + * @param identityAuthenticationType the identityAuthenticationType to set + */ + public void setIdentityAuthenticationType(IdentityAuthenticationType identityAuthenticationType) { + this.identityAuthenticationType = identityAuthenticationType; + } + + @Override + public String toString () { + StringBuilder stringBuilder = new StringBuilder (); + stringBuilder.append ("Cloud Identity Service: id=") + .append (id) + .append (", identityUrl=") + .append (this.identityUrl) + .append (", msoId=") + .append (msoId) + .append (", adminTenant=") + .append (adminTenant) + .append (", memberRole=") + .append (memberRole) + .append (", tenantMetadata=") + .append (tenantMetadata) + .append (", identityServerType=") + .append (identityServerType.toString()) + .append (", identityAuthenticationType=") + .append (identityAuthenticationType.toString()); + + return stringBuilder.toString (); + } + + public static String encryptPassword (String msoPass) { + try { + return CryptoUtils.encrypt (msoPass, cloudKey); + } catch (GeneralSecurityException e) { + LOGGER.error (MessageEnum.RA_GENERAL_EXCEPTION, "", "", MsoLogger.ErrorCode.BusinessProcesssError, "Exception in encryptPassword", e); + return null; + } + } + + + @Override + public CloudIdentity clone() { + CloudIdentity cloudIdentityCopy = new CloudIdentity(); + + cloudIdentityCopy.id = this.id; + cloudIdentityCopy.identityUrl = this.identityUrl; + cloudIdentityCopy.msoId = this.msoId; + cloudIdentityCopy.msoPass = this.msoPass; + cloudIdentityCopy.adminTenant = this.adminTenant; + cloudIdentityCopy.memberRole = this.memberRole; + cloudIdentityCopy.tenantMetadata = this.tenantMetadata; + cloudIdentityCopy.identityServerType = this.identityServerType; + cloudIdentityCopy.identityAuthenticationType = this.identityAuthenticationType; + + return cloudIdentityCopy; + } + + @Override + public int hashCode() { + final int prime = 31; + int result = 1; + result = prime * result + ((adminTenant == null) ? 0 : adminTenant.hashCode()); + result = prime * result + ((id == null) ? 0 : id.hashCode()); + result = prime * result + ((identityUrl == null) ? 0 : identityUrl.hashCode()); + result = prime * result + ((memberRole == null) ? 0 : memberRole.hashCode()); + result = prime * result + ((msoId == null) ? 0 : msoId.hashCode()); + result = prime * result + ((msoPass == null) ? 0 : msoPass.hashCode()); + result = prime * result + ((tenantMetadata == null) ? 0 : tenantMetadata.hashCode()); + result = prime * result + ((identityServerType == null) ? 0 : identityServerType.hashCode()); + result = prime * result + ((identityAuthenticationType == null) ? 0 : identityAuthenticationType.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; + CloudIdentity other = (CloudIdentity) obj; + if (adminTenant == null) { + if (other.adminTenant != null) + return false; + } else if (!adminTenant.equals(other.adminTenant)) + return false; + if (id == null) { + if (other.id != null) + return false; + } else if (!id.equals(other.id)) + return false; + if (identityUrl == null) { + if (other.identityUrl != null) + return false; + } else if (!identityUrl.equals(other.identityUrl)) + return false; + if (memberRole == null) { + if (other.memberRole != null) + return false; + } else if (!memberRole.equals(other.memberRole)) + return false; + if (msoId == null) { + if (other.msoId != null) + return false; + } else if (!msoId.equals(other.msoId)) + return false; + if (msoPass == null) { + if (other.msoPass != null) + return false; + } else if (!msoPass.equals(other.msoPass)) + return false; + if (tenantMetadata == null) { + if (other.tenantMetadata != null) + return false; + } else if (!tenantMetadata.equals(other.tenantMetadata)) + return false; + if (identityServerType == null) { + if (other.getIdentityServerType() != null) + return false; + } else if (!identityServerType.equals(other.getIdentityServerType())) + return false; + if (identityAuthenticationType == null) { + if (other.getIdentityAuthenticationType() != null) + return false; + } else if (!identityAuthenticationType.equals(other.getIdentityAuthenticationType())) + return false; + + return true; + } +} 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 new file mode 100644 index 0000000000..16963deb20 --- /dev/null +++ b/adapters/mso-adapter-utils/src/main/java/org/openecomp/mso/cloud/CloudSite.java @@ -0,0 +1,160 @@ +/*- + * ============LICENSE_START======================================================= + * OPENECOMP - MSO + * ================================================================================ + * 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 org.codehaus.jackson.annotate.JsonProperty; + +/** + * JavaBean JSON class for a CloudSite. This bean represents a cloud location + * (i.e. and LCP node) in the NVP/AIC cloud. It will be loaded via CloudConfig + * object, of which it is a component (a CloudConfig JSON configuration file + * will contain multiple CloudSite definitions). + * + * Note that this is only used to access Cloud Configurations loaded from a + * JSON config file, so there are no explicit setters. + * + */ +public class CloudSite { + @JsonProperty + private String id; + @JsonProperty("region_id") + private String regionId; + @JsonProperty("identity_service_id") + private String identityServiceId; + @JsonProperty("aic_version") + private String aic_version; + @JsonProperty("clli") + private String clli; + + // Derived property (set by CloudConfig loader based on identityServiceId) + private CloudIdentity identityService; + + public CloudSite() {} + + public String getId() { + return id; + } + public void setId(String id) { + this.id = id; + } + + public String getRegionId() { + return regionId; + } + + public void setRegionId(String regionId) { + this.regionId = regionId; + } + + public String getIdentityServiceId() { + return identityServiceId; + } + + public CloudIdentity getIdentityService () { + return identityService; + } + + public void setIdentityService (CloudIdentity identity) { + this.identityService = identity; + } + + public String getAic_version() { + return aic_version; + } + + public void setAic_version(String aic_version) { + this.aic_version = aic_version; + } + + public String getClli() { + return clli; + } + + public void setClli(String clli) { + this.clli = clli; + } + + @Override + public String toString() { + return "CloudSite: id=" + id + + ", regionId=" + regionId + + ", identityServiceId=" + identityServiceId + + ", aic_version=" + aic_version + + ", clli=" + clli; + } + + @Override + public CloudSite clone() { + CloudSite cloudSiteCopy = new CloudSite(); + cloudSiteCopy.id = this.id; + cloudSiteCopy.regionId = this.regionId; + cloudSiteCopy.identityServiceId = this.identityServiceId; + cloudSiteCopy.aic_version = this.aic_version; + cloudSiteCopy.clli = this.clli; + cloudSiteCopy.identityService = this.identityService.clone(); + return cloudSiteCopy; + } + + @Override + public int hashCode() { + final int prime = 31; + int result = 1; + result = prime * result + ((id == null) ? 0 : id.hashCode()); + result = prime * result + ((identityService == null) ? 0 : identityService.hashCode()); + result = prime * result + ((identityServiceId == null) ? 0 : identityServiceId.hashCode()); + result = prime * result + ((regionId == null) ? 0 : regionId.hashCode()); + result = prime * result + ((aic_version == null) ? 0 : aic_version.hashCode()); + result = prime * result + ((clli == null) ? 0 : clli.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; + CloudSite other = (CloudSite) obj; + if (!cmp(id, other.id)) + return false; + if (!cmp(regionId, other.regionId)) + return false; + if (!cmp(identityServiceId, other.identityServiceId)) + return false; + if (!cmp(aic_version, other.aic_version)) + return false; + if (!cmp(clli, other.clli)) + return false; + if (!cmp(identityService, other.identityService)) + 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/openstack/beans/HeatStatus.java b/adapters/mso-adapter-utils/src/main/java/org/openecomp/mso/openstack/beans/HeatStatus.java new file mode 100644 index 0000000000..8c51c746ef --- /dev/null +++ b/adapters/mso-adapter-utils/src/main/java/org/openecomp/mso/openstack/beans/HeatStatus.java @@ -0,0 +1,30 @@ +/*- + * ============LICENSE_START======================================================= + * OPENECOMP - MSO + * ================================================================================ + * 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 new file mode 100644 index 0000000000..95a58f35dd --- /dev/null +++ b/adapters/mso-adapter-utils/src/main/java/org/openecomp/mso/openstack/beans/MsoTenant.java @@ -0,0 +1,66 @@ +/*- + * ============LICENSE_START======================================================= + * OPENECOMP - MSO + * ================================================================================ + * 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 new file mode 100644 index 0000000000..11bf63b5c1 --- /dev/null +++ b/adapters/mso-adapter-utils/src/main/java/org/openecomp/mso/openstack/beans/NetworkInfo.java @@ -0,0 +1,177 @@ +/*- + * ============LICENSE_START======================================================= + * OPENECOMP - MSO + * ================================================================================ + * 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<Integer>(); + private List<String> subnets = new ArrayList<String>(); + private String shared = ""; + + static Map<String,NetworkStatus> NetworkStatusMap; + static { + NetworkStatusMap = new HashMap<String,NetworkStatus>(); + NetworkStatusMap.put("ACTIVE", NetworkStatus.ACTIVE); + NetworkStatusMap.put("DOWN", NetworkStatus.DOWN); + NetworkStatusMap.put("BUILD", NetworkStatus.BUILD); + NetworkStatusMap.put("ERROR", NetworkStatus.ERROR); + } + + public NetworkInfo () { + } + + public NetworkInfo (String name, NetworkStatus status) { + this.name = name; + this.id = name; // Don't have an ID, so just use name + this.status = status; + } + + /** + * 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) { + this.status = NetworkStatus.NOTFOUND; + return; + } + + this.name = network.getName(); + this.id = network.getId(); + + if (network.getStatus() == null) { + // Can this happen on a newly created network? + this.status = NetworkStatus.UNKNOWN; + } else if (NetworkStatusMap.containsKey(network.getStatus())) { + this.status = NetworkStatusMap.get(network.getStatus()); + } else { + this.status = NetworkStatus.UNKNOWN; + } + + if (network.getProviderPhysicalNetwork() != null) { + this.provider = network.getProviderPhysicalNetwork(); + if (network.getProviderNetworkType().equals("vlan")) { + this.vlans.add(network.getProviderSegmentationId()); + } + } + else if (network.getSegments() != null && network.getSegments().size() > 0) { + Segment s = network.getSegments().get(0); + this.provider = s.getProviderPhysicalNetwork(); + if (s.getProviderNetworkType().equals("vlan")) { + for (Segment s1 : network.getSegments()) { + this.vlans.add(s1.getProviderSegmentationId()); + } + } + } + this.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; + } + + public void setSubnets (List<String> subnets) { + this.subnets = subnets; + } + + public String getShared() { + return shared; + } + + public void setShared(String shared) { + this.shared = shared; + } + + @Override + public String toString () { + return "Network: name=" + name + ",id=" + id + ",status=" + status + + ",provider=" + provider + ",vlans=" + vlans + ",subnets=" + subnets + ",shared=" + shared; + } +} + 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 new file mode 100644 index 0000000000..11a74d4494 --- /dev/null +++ b/adapters/mso-adapter-utils/src/main/java/org/openecomp/mso/openstack/beans/NetworkRollback.java @@ -0,0 +1,139 @@ +/*- + * ============LICENSE_START======================================================= + * OPENECOMP - MSO + * ================================================================================ + * 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 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 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 new file mode 100644 index 0000000000..f1a5dad615 --- /dev/null +++ b/adapters/mso-adapter-utils/src/main/java/org/openecomp/mso/openstack/beans/NetworkStatus.java @@ -0,0 +1,31 @@ +/*- + * ============LICENSE_START======================================================= + * OPENECOMP - MSO + * ================================================================================ + * 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 new file mode 100644 index 0000000000..ae179c4354 --- /dev/null +++ b/adapters/mso-adapter-utils/src/main/java/org/openecomp/mso/openstack/beans/Pool.java @@ -0,0 +1,69 @@ +/*- + * ============LICENSE_START======================================================= + * OPENECOMP - MSO + * ================================================================================ + * 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 new file mode 100644 index 0000000000..cdf4b2c34b --- /dev/null +++ b/adapters/mso-adapter-utils/src/main/java/org/openecomp/mso/openstack/beans/StackInfo.java @@ -0,0 +1,155 @@ +/*- + * ============LICENSE_START======================================================= + * OPENECOMP - MSO + * ================================================================================ + * 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; +import java.util.HashMap; + +import com.woorea.openstack.heat.model.Stack; + +/* + * 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 { + // Set defaults for everything + private String name = ""; + private String canonicalName = ""; + private HeatStatus status = HeatStatus.UNKNOWN; + private String statusMessage = ""; + private Map<String,Object> outputs = new HashMap<String,Object>(); + private Map<String,Object> parameters = new HashMap<String,Object>(); + + static Map<String,HeatStatus> HeatStatusMap; + static { + HeatStatusMap = new HashMap<String,HeatStatus>(); + 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 () { + } + + public StackInfo (String name, HeatStatus status, String statusMessage, Map<String,Object> outputs) { + this.name = name; + this.canonicalName = name; // Don't have an ID, so just use name + + this.status = status; + if (statusMessage != null) this.statusMessage = statusMessage; + if (outputs != null) this.outputs = outputs; + } + + 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 if (HeatStatusMap.containsKey(stack.getStackStatus())) { + this.status = HeatStatusMap.get(stack.getStackStatus()); + } else { + this.status = HeatStatus.UNKNOWN; + } + + this.statusMessage = stack.getStackStatusReason(); + + if (stack.getOutputs() != null) { + this.outputs = new HashMap<String,Object>(); + for (Stack.Output output : stack.getOutputs()) { + this.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 void setCanonicalName (String name) { + this.canonicalName = name; + } + + public HeatStatus getStatus() { + return status; + } + + public void setStatus (HeatStatus status) { + this.status = status; + } + + public String getStatusMessage() { + return statusMessage; + } + + public void setStatusMessage (String statusMessage) { + this.statusMessage = statusMessage; + } + + public Map<String,Object> getOutputs () { + return outputs; + } + + public void setOutputs (Map<String,Object> outputs) { + this.outputs = outputs; + } + + public Map<String,Object> getParameters () { + return parameters; + } + + public void setParameters (Map<String,Object> parameters) { + this.parameters = 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 new file mode 100644 index 0000000000..eb514cd565 --- /dev/null +++ b/adapters/mso-adapter-utils/src/main/java/org/openecomp/mso/openstack/beans/Subnet.java @@ -0,0 +1,200 @@ +/*- + * ============LICENSE_START======================================================= + * OPENECOMP - MSO + * ================================================================================ + * 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 new file mode 100644 index 0000000000..b6e4a6e855 --- /dev/null +++ b/adapters/mso-adapter-utils/src/main/java/org/openecomp/mso/openstack/beans/VnfRollback.java @@ -0,0 +1,152 @@ +/*- + * ============LICENSE_START======================================================= + * OPENECOMP - MSO + * ================================================================================ + * 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 org.openecomp.mso.entity.MsoRequest; +/** + * Javabean representing the rollback criteria following a "Create VNF" + * operation. This structure can be passed back to the "Rollback VNF" + * operation to undo the effects of the create. + * + * + */ +public class VnfRollback { + private String vnfId; + private String tenantId; + private String cloudSiteId; + private boolean tenantCreated = false; + private boolean vnfCreated = false; + private MsoRequest msoRequest; + private String volumeGroupName; + private String volumeGroupId; + private String requestType; + private String volumeGroupHeatStackId; + private String baseGroupHeatStackId; + private boolean isBase = false; + private String vfModuleStackId; + + public VnfRollback() {} + + public VnfRollback(String vnfId, String tenantId, String cloudSiteId, + boolean tenantCreated, boolean vnfCreated, + MsoRequest msoRequest, + String volumeGroupName, String volumeGroupId, String requestType) { + 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; + } + + public String getVnfId() { + return vnfId; + } + public void setVnfId(String vnfId) { + this.vnfId = vnfId; + } + public String getTenantId() { + return tenantId; + } + + public void setTenantId(String tenantId) { + this.tenantId = tenantId; + } + public String getCloudSiteId() { + return cloudSiteId; + } + public void setCloudSiteId(String cloudId) { + this.cloudSiteId = cloudId; + } + public boolean getTenantCreated() { + return tenantCreated; + } + public void setTenantCreated(boolean tenantCreated) { + this.tenantCreated = tenantCreated; + } + public boolean getVnfCreated() { + return vnfCreated; + } + public void setVnfCreated(boolean vnfCreated) { + this.vnfCreated = vnfCreated; + } + public MsoRequest getMsoRequest() { + return msoRequest; + } + public void setMsoRequest (MsoRequest msoRequest) { + this.msoRequest = msoRequest; + } + public String getVolumeGroupName() { + return this.volumeGroupName; + } + public void setVolumeGroupName(String volumeGroupName) { + this.volumeGroupName = volumeGroupName; + } + public String getVolumeGroupId() { + return this.volumeGroupId; + } + public void setVolumeGroupId(String volumeGroupId) { + this.volumeGroupId = volumeGroupId; + } + public String getRequestType() { + return this.requestType; + } + public void setRequestType(String requestType) { + this.requestType = requestType; + } + public String getVolumeGroupHeatStackId() { + return this.volumeGroupHeatStackId; + } + public void setVolumeGroupHeatStackId(String volumeGroupHeatStackId) { + this.volumeGroupHeatStackId = volumeGroupHeatStackId; + } + + public String getBaseGroupHeatStackId() { + return this.baseGroupHeatStackId; + } + public void setBaseGroupHeatStackId(String baseGroupHeatStackId) { + this.baseGroupHeatStackId = baseGroupHeatStackId; + } + + public boolean isBase() { + return this.isBase; + } + public void setIsBase(boolean isBase) { + this.isBase = isBase; + } + public String getVfModuleStackId() { + return this.vfModuleStackId; + } + public void setVfModuleStackId(String vfModuleStackId) { + this.vfModuleStackId = vfModuleStackId; + } + + @Override + public String toString() { + return "VnfRollback: cloud=" + cloudSiteId + ", tenant=" + tenantId + + ", vnf=" + vnfId + ", tenantCreated=" + tenantCreated + + ", vnfCreated=" + vnfCreated + ", requestType = " + requestType; + } +} 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/openstack/beans/VnfStatus.java new file mode 100644 index 0000000000..40f46716fd --- /dev/null +++ b/adapters/mso-adapter-utils/src/main/java/org/openecomp/mso/openstack/beans/VnfStatus.java @@ -0,0 +1,30 @@ +/*- + * ============LICENSE_START======================================================= + * OPENECOMP - MSO + * ================================================================================ + * 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 VnfStatus { + ACTIVE, FAILED, NOTFOUND, UNKNOWN +} + 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/openstack/exceptions/MsoAdapterException.java new file mode 100644 index 0000000000..d7198aed5a --- /dev/null +++ b/adapters/mso-adapter-utils/src/main/java/org/openecomp/mso/openstack/exceptions/MsoAdapterException.java @@ -0,0 +1,45 @@ +/*- + * ============LICENSE_START======================================================= + * OPENECOMP - MSO + * ================================================================================ + * 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; + + + +/** + * General MSO Exception class for any non-specific errors. + * + * + */ +public class MsoAdapterException extends MsoException +{ + private static final long serialVersionUID = 1L; + + // Constructor to create a new MsoException instance + public MsoAdapterException (String message) { + super(message); + super.category = MsoExceptionCategory.INTERNAL; + } + + // Constructor to wrap a nested exception + public MsoAdapterException (String message, Throwable t) { + super(message, t); + super.category = MsoExceptionCategory.INTERNAL; + } +} 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 new file mode 100644 index 0000000000..4392ee039f --- /dev/null +++ b/adapters/mso-adapter-utils/src/main/java/org/openecomp/mso/openstack/exceptions/MsoCloudSiteNotFound.java @@ -0,0 +1,56 @@ +/*- + * ============LICENSE_START======================================================= + * OPENECOMP - MSO + * ================================================================================ + * 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; + + +/** + * Cloud site not found exception. + */ +public class MsoCloudSiteNotFound extends MsoException { + + /** + * Serialization id. + */ + private static final long serialVersionUID = 2583769056266415664L; + + /** + * Default constructor (needed for BPEL/JAXB) + */ + public MsoCloudSiteNotFound () { + super("Cloud site not found"); + super.category=MsoExceptionCategory.USERDATA; + } + + /** + * Constructor to create a new MsoOpenstackException instance + * @param cloudSite the cloud site + */ + 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 new file mode 100644 index 0000000000..538a60d499 --- /dev/null +++ b/adapters/mso-adapter-utils/src/main/java/org/openecomp/mso/openstack/exceptions/MsoException.java @@ -0,0 +1,66 @@ +/*- + * ============LICENSE_START======================================================= + * OPENECOMP - MSO + * ================================================================================ + * 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 new file mode 100644 index 0000000000..4cc6b410e5 --- /dev/null +++ b/adapters/mso-adapter-utils/src/main/java/org/openecomp/mso/openstack/exceptions/MsoExceptionCategory.java @@ -0,0 +1,27 @@ +/*- + * ============LICENSE_START======================================================= + * OPENECOMP - MSO + * ================================================================================ + * 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 new file mode 100644 index 0000000000..eafb033e4b --- /dev/null +++ b/adapters/mso-adapter-utils/src/main/java/org/openecomp/mso/openstack/exceptions/MsoIOException.java @@ -0,0 +1,53 @@ +/*- + * ============LICENSE_START======================================================= + * OPENECOMP - MSO + * ================================================================================ + * 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/MsoNetworkAlreadyExists.java b/adapters/mso-adapter-utils/src/main/java/org/openecomp/mso/openstack/exceptions/MsoNetworkAlreadyExists.java new file mode 100644 index 0000000000..d234bbf73a --- /dev/null +++ b/adapters/mso-adapter-utils/src/main/java/org/openecomp/mso/openstack/exceptions/MsoNetworkAlreadyExists.java @@ -0,0 +1,35 @@ +/*- + * ============LICENSE_START======================================================= + * OPENECOMP - MSO + * ================================================================================ + * 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 MsoNetworkAlreadyExists extends MsoOpenstackException { + + private static final long serialVersionUID = 1L; + + // Constructor to create a new MsoOpenstackException instance + public MsoNetworkAlreadyExists (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/MsoNetworkNotFound.java b/adapters/mso-adapter-utils/src/main/java/org/openecomp/mso/openstack/exceptions/MsoNetworkNotFound.java new file mode 100644 index 0000000000..8aa7115629 --- /dev/null +++ b/adapters/mso-adapter-utils/src/main/java/org/openecomp/mso/openstack/exceptions/MsoNetworkNotFound.java @@ -0,0 +1,35 @@ +/*- + * ============LICENSE_START======================================================= + * OPENECOMP - MSO + * ================================================================================ + * 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 MsoNetworkNotFound extends MsoOpenstackException { + + private static final long serialVersionUID = 1L; + + // Constructor to create a new MsoOpenstackException instance + public MsoNetworkNotFound (String networkId, String tenant, String cloud) { + // Set the detailed error as the Exception 'message' + super(404, "Not Found", "Network " + networkId + " does not exist in Cloud/Tenant " + cloud + "/" + tenant); + } + +} 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/openstack/exceptions/MsoOpenstackException.java new file mode 100644 index 0000000000..2ad0f5b26f --- /dev/null +++ b/adapters/mso-adapter-utils/src/main/java/org/openecomp/mso/openstack/exceptions/MsoOpenstackException.java @@ -0,0 +1,77 @@ +/*- + * ============LICENSE_START======================================================= + * OPENECOMP - MSO + * ================================================================================ + * 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; + + +/** + * OpenStack exception. + */ +public class MsoOpenstackException extends MsoException +{ + + /** + * Serialization id. + */ + private static final long serialVersionUID = 3313636124141766495L; + + private int statusCode; + private String statusMessage; + private String errorDetail; + + /** + * Constructor to create a new MsoOpenstackException instance + * @param code the error code + * @param message the error message + * @param detail error details + */ + public MsoOpenstackException (int code, String message, String detail) { + // Set the detailed error as the Exception 'message' + super(detail); + super.category = MsoExceptionCategory.OPENSTACK; + + this.statusCode = code; + this.statusMessage = message; + this.errorDetail = detail; + } + + /** + * Constructor to propagate the caught exception (mostly for stack trace) + * @param code the error code + * @param message the error message + * @param detail error details + * @param e the cause + */ + public MsoOpenstackException (int code, String message, String detail, Exception e) { + // Set the detailed error as the Exception 'message' + super(detail, e); + super.category = MsoExceptionCategory.OPENSTACK; + + this.statusCode = code; + this.statusMessage = message; + this.errorDetail = detail; + } + + @Override + public String toString () { + String error = "" + statusCode + " " + statusMessage + ": " + errorDetail; + return error; + } +} 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 new file mode 100644 index 0000000000..2aba5b9d03 --- /dev/null +++ b/adapters/mso-adapter-utils/src/main/java/org/openecomp/mso/openstack/exceptions/MsoStackAlreadyExists.java @@ -0,0 +1,35 @@ +/*- + * ============LICENSE_START======================================================= + * OPENECOMP - MSO + * ================================================================================ + * 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 new file mode 100644 index 0000000000..583d97616d --- /dev/null +++ b/adapters/mso-adapter-utils/src/main/java/org/openecomp/mso/openstack/exceptions/MsoStackNotFound.java @@ -0,0 +1,44 @@ +/*- + * ============LICENSE_START======================================================= + * OPENECOMP - MSO + * ================================================================================ + * 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/MsoTenantAlreadyExists.java b/adapters/mso-adapter-utils/src/main/java/org/openecomp/mso/openstack/exceptions/MsoTenantAlreadyExists.java new file mode 100644 index 0000000000..9edfdea591 --- /dev/null +++ b/adapters/mso-adapter-utils/src/main/java/org/openecomp/mso/openstack/exceptions/MsoTenantAlreadyExists.java @@ -0,0 +1,35 @@ +/*- + * ============LICENSE_START======================================================= + * OPENECOMP - MSO + * ================================================================================ + * 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 MsoTenantAlreadyExists extends MsoOpenstackException { + + private static final long serialVersionUID = 1L; + + // Constructor to create a new MsoOpenstackException instance + public MsoTenantAlreadyExists (String tenant, String cloud) { + // Set the detailed error as the Exception 'message' + super(409, "Conflict", "Tenant " + tenant + " already exists in Cloud " + cloud); + } + +} 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 new file mode 100644 index 0000000000..bd099388ee --- /dev/null +++ b/adapters/mso-adapter-utils/src/main/java/org/openecomp/mso/openstack/exceptions/MsoTenantNotFound.java @@ -0,0 +1,43 @@ +/*- + * ============LICENSE_START======================================================= + * OPENECOMP - MSO + * ================================================================================ + * 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/CloudConfigInitializer.java b/adapters/mso-adapter-utils/src/main/java/org/openecomp/mso/openstack/utils/CloudConfigInitializer.java new file mode 100644 index 0000000000..3d9c23cc32 --- /dev/null +++ b/adapters/mso-adapter-utils/src/main/java/org/openecomp/mso/openstack/utils/CloudConfigInitializer.java @@ -0,0 +1,81 @@ +/*- + * ============LICENSE_START======================================================= + * OPENECOMP - MSO + * ================================================================================ + * 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.utils; + + +import javax.ejb.EJB; +import javax.servlet.ServletContextEvent; +import javax.servlet.ServletContextListener; +import javax.servlet.annotation.WebListener; + +import org.openecomp.mso.cloud.CloudConfigFactory; +import org.openecomp.mso.logger.MessageEnum; +import org.openecomp.mso.logger.MsoLogger; + +/** + * This class will attempt to initialize Cloud Config when part of a web application. + * + * + * + */ +@WebListener +public class CloudConfigInitializer implements ServletContextListener +{ + + private CloudConfigFactory cloudConfigFactory=new CloudConfigFactory(); + + public CloudConfigInitializer () { + } + + @Override + public void contextDestroyed(ServletContextEvent event) { + // Nothing to do... + } + + + @Override + public void contextInitialized(ServletContextEvent event) + { + + // Note - this logger may be before or after MSO Logging configuration applied + MsoLogger initLogger = MsoLogger.getMsoLogger(MsoLogger.Catalog.GENERAL); + try { + // Look first in the init-parameters + String msoPropConfigParam = event.getServletContext().getInitParameter("mso.cloud_config.configuration"); + + String[] configFileSplit = msoPropConfigParam.split(","); + for (String msoPropConfig:configFileSplit) { + String[] msoPropDecoded = msoPropConfig.split("="); + + try { + cloudConfigFactory.initializeCloudConfig(msoPropDecoded[0], Integer.valueOf(msoPropDecoded[1])); + initLogger.info(MessageEnum.RA_CONFIG_LOAD, msoPropDecoded[0], "", ""); + initLogger.debug("Mso properties successfully loaded:"+msoPropDecoded[0]+"(Timer(mins):"+Integer.valueOf(msoPropDecoded[1])); + } catch (NumberFormatException ne) { + initLogger.error(MessageEnum.RA_CONFIG_EXC, msoPropDecoded[0] + ". MSO Properties failed due to conversion error (in web.xml file)", "", "", MsoLogger.ErrorCode.DataError, "MSO Properties failed due to conversion error (in web.xml file)", ne); + } + } + } + catch (Exception e) { + initLogger.error(MessageEnum.RA_CONFIG_EXC, "Unknown. MSO Properties failed to initialize completely", "", "", MsoLogger.ErrorCode.AvailabilityError, "Exception - MSO Properties failed to initialize completely", e); + } + } +} diff --git a/adapters/mso-adapter-utils/src/main/java/org/openecomp/mso/openstack/utils/MsoCommonUtils.java b/adapters/mso-adapter-utils/src/main/java/org/openecomp/mso/openstack/utils/MsoCommonUtils.java new file mode 100644 index 0000000000..6787e72df6 --- /dev/null +++ b/adapters/mso-adapter-utils/src/main/java/org/openecomp/mso/openstack/utils/MsoCommonUtils.java @@ -0,0 +1,315 @@ +/*- + * ============LICENSE_START======================================================= + * OPENECOMP - MSO + * ================================================================================ + * 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.utils; + + +import java.lang.StackTraceElement; +import org.openecomp.mso.logger.MsoAlarmLogger; +import org.openecomp.mso.logger.MsoLogger; +import org.openecomp.mso.logger.MessageEnum; +import org.openecomp.mso.openstack.exceptions.MsoAdapterException; +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.properties.MsoJavaProperties; +import com.woorea.openstack.base.client.OpenStackBaseException; +import com.woorea.openstack.base.client.OpenStackConnectException; +import com.woorea.openstack.base.client.OpenStackRequest; +import com.woorea.openstack.base.client.OpenStackResponseException; +import com.woorea.openstack.heat.model.Explanation; +import com.woorea.openstack.keystone.model.Error; +import com.woorea.openstack.quantum.model.NeutronError; + +public class MsoCommonUtils { + + private static MsoLogger LOGGER = MsoLogger.getMsoLogger(MsoLogger.Catalog.RA); + protected static MsoAlarmLogger alarmLogger = new MsoAlarmLogger(); + + protected static String retryDelayProp = "ecomp.mso.adapters.po.retryDelay"; + protected static String retryCountProp = "ecomp.mso.adapters.po.retryCount"; + protected static String retryCodesProp = "ecomp.mso.adapters.po.retryCodes"; + + protected static int retryDelayDefault = 5; + protected static int retryCountDefault = 3; + protected static String retryCodesDefault = "504"; + + /* + * Method to execute an Openstack command and track its execution time. + * For the metrics log, a category of "Openstack" is used along with a + * sub-category that identifies the specific call (using the real + * openstack-java-sdk classname of the OpenStackRequest<T> parameter). + */ + + protected static <T> T executeAndRecordOpenstackRequest (OpenStackRequest <T> request) + { + return executeAndRecordOpenstackRequest (request, null); + } + protected static <T> T executeAndRecordOpenstackRequest (OpenStackRequest <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; + } + } + + long start = System.currentTimeMillis (); + 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 (OpenStackResponseException 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 ("OpenStackResponseException 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 (OpenStackConnectException e) { + // Connection to Openstack failed + if (retryCount > 0) + { + retryCount--; + LOGGER.debug ("OpenstackConnectException 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 Openstack Exception on a Keystone call to an MsoException. + * This method supports both OpenstackResponseException and OpenStackConnectException. + */ + protected static MsoException keystoneErrorToMsoException (OpenStackBaseException e, String context) { + MsoException me = null; + + if (e instanceof OpenStackResponseException) { + OpenStackResponseException re = (OpenStackResponseException) e; + + try { + // Failed Keystone calls return an Error entity body. + Error error = re.getResponse ().getErrorEntity (Error.class); + LOGGER.error (MessageEnum.RA_CONNECTION_EXCEPTION, "Openstack Keystone Error on " + context + ": " + error, "Openstack", "", MsoLogger.ErrorCode.DataError, "Openstack Keystone Error on " + context); + me = new MsoOpenstackException (error.getCode (), error.getTitle (), error.getMessage ()); + } catch (Exception e2) { + // Can't parse the body as an "Error". Report the HTTP error + LOGGER.error (MessageEnum.RA_CONNECTION_EXCEPTION, "HTTP Error on " + context + ": " + re.getStatus() + "," + re.getMessage(), "Openstack", "", MsoLogger.ErrorCode.DataError, "HTTP Error on " + context, e2); + me = new MsoOpenstackException (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 ("KeystoneError", MsoAlarmLogger.CRITICAL, me.getContextMessage ()); + } + } else if (e instanceof OpenStackConnectException) { + OpenStackConnectException ce = (OpenStackConnectException) e; + + me = new MsoIOException (ce.getMessage ()); + me.addContext (context); + + // Generate an alarm for all connection errors. + LOGGER.error(MessageEnum.RA_GENERAL_EXCEPTION_ARG, "Openstack Keystone connection error on " + context + ": " + e, "Openstack", "", MsoLogger.ErrorCode.DataError, "Openstack Keystone connection error on " + context); + alarmLogger.sendAlarm ("KeystoneIOError", MsoAlarmLogger.CRITICAL, me.getContextMessage ()); + } + + return me; + } + + /* + * Convert an Openstack Exception on a Heat call to an MsoOpenstackException. + * This method supports both OpenstackResponseException and OpenStackConnectException. + */ + protected MsoException heatExceptionToMsoException (OpenStackBaseException e, String context) { + MsoException me = null; + + if (e instanceof OpenStackResponseException) { + OpenStackResponseException re = (OpenStackResponseException) e; + + try { + // Failed Heat calls return an Explanation entity body. + Explanation explanation = re.getResponse ().getErrorEntity (Explanation.class); + LOGGER.error (MessageEnum.RA_CONNECTION_EXCEPTION, "OpenStack", "Openstack Error on " + context + ": " + explanation.toString(), "Openstack", "", MsoLogger.ErrorCode.DataError, "Exception - Openstack Error on " + context); + String fullError = explanation.getExplanation() + ", error.type=" + explanation.getError().getType() + ", error.message=" + explanation.getError().getMessage(); + LOGGER.debug(fullError); + me = new MsoOpenstackException (explanation.getCode (), + explanation.getTitle (), + //explanation.getExplanation ()); + fullError); + } catch (Exception e2) { + // Couldn't parse the body as an "Explanation". Report the original HTTP error. + LOGGER.error (MessageEnum.RA_CONNECTION_EXCEPTION, "OpenStack", "HTTP Error on " + context + ": " + re.getStatus() + "," + e.getMessage(), "Openstack", "", MsoLogger.ErrorCode.DataError, "Exception - HTTP Error on " + context, e2); + me = new MsoOpenstackException (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 ("HeatError", MsoAlarmLogger.CRITICAL, me.getContextMessage ()); + } + } else if (e instanceof OpenStackConnectException) { + OpenStackConnectException ce = (OpenStackConnectException) e; + + me = new MsoIOException (ce.getMessage ()); + me.addContext (context); + + // Generate an alarm for all connection errors. + alarmLogger.sendAlarm ("HeatIOError", MsoAlarmLogger.CRITICAL, me.getContextMessage ()); + LOGGER.error(MessageEnum.RA_CONNECTION_EXCEPTION, "OpenStack", "Openstack Heat connection error on " + context + ": " + e, "Openstack", "", MsoLogger.ErrorCode.DataError, "Openstack Heat connection error on " + context); + } + + return me; + } + + /* + * Convert an Openstack Exception on a Neutron call to an MsoOpenstackException. + * This method supports both OpenstackResponseException and OpenStackConnectException. + */ + protected MsoException neutronExceptionToMsoException (OpenStackBaseException e, String context) { + MsoException me = null; + + if (e instanceof OpenStackResponseException) { + OpenStackResponseException re = (OpenStackResponseException) e; + + try { + // Failed Neutron calls return an NeutronError entity body + NeutronError error = re.getResponse ().getErrorEntity (NeutronError.class); + LOGGER.error (MessageEnum.RA_CONNECTION_EXCEPTION, "OpenStack", "Openstack Neutron Error on " + context + ": " + error, "Openstack", "", MsoLogger.ErrorCode.DataError, "Openstack Neutron Error on " + context); + me = new MsoOpenstackException (re.getStatus (), error.getType (), error.getMessage ()); + } catch (Exception e2) { + // Couldn't parse body as a NeutronError. Report the HTTP error. + LOGGER.error (MessageEnum.RA_CONNECTION_EXCEPTION, "OpenStack", "HTTP Error on " + context + ": " + re.getStatus() + "," + e.getMessage(), "Openstack", "", MsoLogger.ErrorCode.DataError, "Openstack HTTP Error on " + context, e2); + me = new MsoOpenstackException (re.getStatus (), re.getMessage (), null); + } + + // Add the context of the error + me.addContext (context); + + // Generate an alarm for 5XX and higher errors. + if (re.getStatus () >= 500) { + alarmLogger.sendAlarm ("NeutronError", MsoAlarmLogger.CRITICAL, me.getContextMessage ()); + } + } else if (e instanceof OpenStackConnectException) { + OpenStackConnectException ce = (OpenStackConnectException) e; + + me = new MsoIOException (ce.getMessage ()); + me.addContext (context); + + // Generate an alarm for all connection errors. + alarmLogger.sendAlarm ("NeutronIOError", MsoAlarmLogger.CRITICAL, me.getContextMessage ()); + LOGGER.error(MessageEnum.RA_CONNECTION_EXCEPTION, "OpenStack", "Openstack Neutron Connection error on "+ context + ": " + e, "OpenStack", "", MsoLogger.ErrorCode.DataError, "Openstack Neutron Connection error on "+ context); + } + + return me; + } + + /* + * Convert a Java Runtime Exception to an MsoException. + * All Runtime exceptions will be translated into an MsoAdapterException, + * which captures internal errors. + * Alarms will be generated on all such exceptions. + */ + protected MsoException runtimeExceptionToMsoException (RuntimeException e, String context) { + MsoAdapterException me = new MsoAdapterException (e.getMessage (), e); + me.addContext (context); + me.setCategory (MsoExceptionCategory.INTERNAL); + + // Always generate an alarm for internal exceptions + LOGGER.error(MessageEnum.RA_GENERAL_EXCEPTION_ARG, "An exception occured on "+ context + ": " + e, "OpenStack", "", MsoLogger.ErrorCode.DataError, "An exception occured on "+ context); + alarmLogger.sendAlarm ("AdapterInternalError", MsoAlarmLogger.CRITICAL, me.getContextMessage ()); + + return me; + } + + public static boolean isNullOrEmpty (String s) { + return s == null || s.isEmpty(); + } + + + +} 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 new file mode 100644 index 0000000000..13ea4331e8 --- /dev/null +++ b/adapters/mso-adapter-utils/src/main/java/org/openecomp/mso/openstack/utils/MsoHeatEnvironmentEntry.java @@ -0,0 +1,227 @@ +/*- + * ============LICENSE_START======================================================= + * OPENECOMP - MSO + * ================================================================================ + * 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.utils; + + + +import java.util.HashSet; +import java.util.ArrayList; +import java.util.Set; +import org.openecomp.mso.db.catalog.beans.HeatTemplateParam; + +public class MsoHeatEnvironmentEntry { + + private Set<MsoHeatEnvironmentParameter> parameters = null; + private Set<MsoHeatEnvironmentResource> resources = null; + private StringBuilder rawEntry = null; + private boolean valid = true; + private String errorString = null; + private StringBuilder resourceRegistryEntryRaw = null; + + public MsoHeatEnvironmentEntry() { + super(); + } + + public MsoHeatEnvironmentEntry(StringBuilder sb) { + this(); + this.rawEntry = sb; + this.processRawEntry(); + } + + private void processRawEntry() { + try { + if (this.rawEntry == null || this.rawEntry.equals("")) + 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) { + 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<MsoHeatEnvironmentParameter>(); + } + this.parameters.add(hep); + } + public void addResource(MsoHeatEnvironmentResource her) { + if (this.resources == null) { + this.resources = new HashSet<MsoHeatEnvironmentResource>(); + } + 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; + } + + 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; + } + + 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"); + } +// 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 StringBuilder getRawEntry() { + return this.rawEntry; + } + + private StringBuilder getResourceRegistryRawEntry() { + + if (this.rawEntry == null) { + return 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/MsoHeatEnvironmentParameter.java b/adapters/mso-adapter-utils/src/main/java/org/openecomp/mso/openstack/utils/MsoHeatEnvironmentParameter.java new file mode 100644 index 0000000000..4cf9023b7c --- /dev/null +++ b/adapters/mso-adapter-utils/src/main/java/org/openecomp/mso/openstack/utils/MsoHeatEnvironmentParameter.java @@ -0,0 +1,86 @@ +/*- + * ============LICENSE_START======================================================= + * OPENECOMP - MSO + * ================================================================================ + * 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.utils; + + + +public class MsoHeatEnvironmentParameter { + + private String name; + private String value; + + public MsoHeatEnvironmentParameter(String name, String value) { + super(); + this.name = name; + this.value = value; + } + public MsoHeatEnvironmentParameter(String name) { + // Allow to initialize with a null value + this(name, null); + } + public MsoHeatEnvironmentParameter() { + this(null, null); + } + + public String getName() { + return this.name; + } + public void setName(String name) { + this.name = name; + } + + public String getValue() { + return this.value; + } + public void setValue(String value) { + this.value = value; + } + public String toString() { + return this.name + ": " + this.value; + } + + public boolean equals(Object o) { + if (!(o instanceof MsoHeatEnvironmentParameter)) { + return false; + } + if (this == o) { + return true; + } + MsoHeatEnvironmentParameter hep = (MsoHeatEnvironmentParameter) o; + // If the name of the parameter is the same, then they're equal + if (hep.getName().equals(this.getName())) { + return true; + } + return false; + } + + public int hashCode() { + int result = 0; + try { + result = this.name.hashCode(); + } catch (Exception e) { + // in case it's null - return zero + } + return result; + } + + +} diff --git a/adapters/mso-adapter-utils/src/main/java/org/openecomp/mso/openstack/utils/MsoHeatEnvironmentResource.java b/adapters/mso-adapter-utils/src/main/java/org/openecomp/mso/openstack/utils/MsoHeatEnvironmentResource.java new file mode 100644 index 0000000000..202a084f45 --- /dev/null +++ b/adapters/mso-adapter-utils/src/main/java/org/openecomp/mso/openstack/utils/MsoHeatEnvironmentResource.java @@ -0,0 +1,86 @@ +/*- + * ============LICENSE_START======================================================= + * OPENECOMP - MSO + * ================================================================================ + * 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.utils; + + + +public class MsoHeatEnvironmentResource { + + private String name; + private String value; + + public MsoHeatEnvironmentResource(String name, String value) { + super(); + this.name = name; + this.value = value; + } + public MsoHeatEnvironmentResource(String name) { + // Allow to initialize with a null value + this(name, null); + } + public MsoHeatEnvironmentResource() { + this(null, null); + } + + public String getName() { + return this.name; + } + public void setName(String name) { + this.name = name; + } + + public String getValue() { + return this.value; + } + public void setValue(String value) { + this.value = value; + } + public String toString() { + return "\"" + this.name + "\": " + this.value; + } + + public boolean equals(Object o) { + if (!(o instanceof MsoHeatEnvironmentResource)) { + return false; + } + if (this == o) { + return true; + } + MsoHeatEnvironmentResource her = (MsoHeatEnvironmentResource) o; + // If the name of the parameter is the same, then they're equal + if (her.getName().equals(this.getName())) { + return true; + } + return false; + } + + public int hashCode() { + int result = 0; + try { + result = this.name.hashCode(); + } catch (Exception e) { + // in case it's null - return zero + } + return result; + } + + +} 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 new file mode 100644 index 0000000000..8d66505c6a --- /dev/null +++ b/adapters/mso-adapter-utils/src/main/java/org/openecomp/mso/openstack/utils/MsoHeatUtils.java @@ -0,0 +1,1229 @@ +/*- + * ============LICENSE_START======================================================= + * OPENECOMP - MSO + * ================================================================================ + * 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.utils; + +import java.io.Serializable; +import java.util.ArrayList; +import java.util.Calendar; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +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; +import org.openecomp.mso.cloud.CloudSite; +import org.openecomp.mso.db.catalog.beans.HeatTemplate; +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.beans.HeatStatus; +import org.openecomp.mso.openstack.beans.StackInfo; +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.MsoIOException; +import org.openecomp.mso.openstack.exceptions.MsoOpenstackException; +import org.openecomp.mso.openstack.exceptions.MsoStackAlreadyExists; +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.woorea.openstack.base.client.OpenStackConnectException; +import com.woorea.openstack.base.client.OpenStackRequest; +import com.woorea.openstack.base.client.OpenStackResponseException; +import com.woorea.openstack.heat.Heat; +import com.woorea.openstack.heat.model.CreateStackParam; +import com.woorea.openstack.heat.model.Stack; +import com.woorea.openstack.heat.model.Stacks; +import com.woorea.openstack.keystone.Keystone; +import com.woorea.openstack.keystone.model.Access; +import com.woorea.openstack.keystone.model.Authentication; +import com.woorea.openstack.keystone.utils.KeystoneUtils; + +public class MsoHeatUtils extends MsoCommonUtils { + + private MsoPropertiesFactory msoPropertiesFactory; + + private CloudConfigFactory cloudConfigFactory; + + private static final String TOKEN_AUTH = "TokenAuth"; + + private static final String QUERY_ALL_STACKS = "QueryAllStacks"; + + private static final String DELETE_STACK = "DeleteStack"; + + private static final String HEAT_ERROR = "HeatError"; + + private static final String CREATE_STACK = "CreateStack"; + + // Cache Heat Clients statically. Since there is just one MSO user, there is no + // benefit to re-authentication on every request (or across different flows). The + // token will be used until it expires. + // + // The cache key is "tenantId:cloudId" + private static Map <String, HeatCacheEntry> heatClientCache = new HashMap <String, HeatCacheEntry> (); + + // 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"; + private String deletePollTimeoutProp = "ecomp.mso.adapters.heat.delete.pollTimeout"; + + protected int createPollIntervalDefault = 15; + private int deletePollIntervalDefault = 15; + private int deletePollTimeoutDefault = 300; + private String msoPropID; + + 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 MsoHeatUtils (String msoPropID, MsoPropertiesFactory msoPropFactory, CloudConfigFactory cloudConfFactory) { + msoPropertiesFactory = msoPropFactory; + cloudConfigFactory = cloudConfFactory; + this.msoPropID = msoPropID; + // 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("MsoHeatUtils:" + msoPropID); + + } + + + /** + * keep this old method signature here to maintain backwards compatibility. keep others as well. + * this method does not include environment, files, or heatFiles + */ + public StackInfo createStack (String cloudSiteId, + String tenantId, + String stackName, + String heatTemplate, + Map <String, ? extends Object> stackInputs, + boolean pollForCompletion, + int timeoutMinutes) throws MsoException { + // Just call the new method with the environment & files variable set to null + return this.createStack (cloudSiteId, + tenantId, + stackName, + heatTemplate, + stackInputs, + pollForCompletion, + timeoutMinutes, + null, + null, + null, + true); + } + + // This method has environment, but not files or heatFiles + public StackInfo createStack (String cloudSiteId, + String tenantId, + String stackName, + String heatTemplate, + Map <String, ? extends Object> stackInputs, + boolean pollForCompletion, + int timeoutMinutes, + String environment) throws MsoException { + // Just call the new method with the files/heatFiles variables set to null + return this.createStack (cloudSiteId, + tenantId, + stackName, + heatTemplate, + stackInputs, + pollForCompletion, + timeoutMinutes, + environment, + null, + null, + true); + } + + // This method has environment and files, but not heatFiles. + public StackInfo createStack (String cloudSiteId, + String tenantId, + String stackName, + String heatTemplate, + Map <String, ? extends Object> stackInputs, + boolean pollForCompletion, + int timeoutMinutes, + String environment, + Map <String, Object> files) throws MsoException { + return this.createStack (cloudSiteId, + tenantId, + stackName, + heatTemplate, + stackInputs, + pollForCompletion, + timeoutMinutes, + environment, + files, + null, + true); + } + + // This method has environment, files, heatfiles + public StackInfo createStack (String cloudSiteId, + String tenantId, + String stackName, + String heatTemplate, + Map <String, ? extends Object> stackInputs, + boolean pollForCompletion, + int timeoutMinutes, + String environment, + Map <String, Object> files, + Map <String, Object> heatFiles) throws MsoException { + return this.createStack (cloudSiteId, + tenantId, + stackName, + heatTemplate, + stackInputs, + pollForCompletion, + timeoutMinutes, + environment, + files, + heatFiles, + true); + } + + /** + * Create a new Stack in the specified cloud location and tenant. The Heat template + * and parameter map are passed in as arguments, along with the cloud access credentials. + * 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 Stack name supplied by the caller must be unique in the scope of this 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. + * + * The caller may choose to let this function poll Openstack for completion of the + * stack creation, or may handle polling itself via separate calls to query the status. + * In either case, a StackInfo object will be returned containing the current status. + * When polling is enabled, a status of CREATED is expected. When not polling, a + * status of BUILDING is expected. + * + * An error will be thrown if the requested Stack already exists in the specified + * Tenant and Cloud. + * + * For 1510 - add "environment", "files" (nested templates), and "heatFiles" (get_files) as + * parameters for createStack. If environment is non-null, it will be added to the stack. + * The nested templates and get_file entries both end up being added to the "files" on the + * stack. We must combine them before we add them to the stack if they're both non-null. + * + * @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 stackName The name of the stack to create + * @param stackTemplate The Heat template + * @param stackInputs A map of key/value inputs + * @param pollForCompletion Indicator that polling should be handled in Java vs. in the client + * @param environment An optional yaml-format string to specify environmental parameters + * @param files a Map<String, Object> that lists the child template IDs (file is the string, object is an int of + * Template id) + * @param heatFiles a Map<String, Object> that lists the get_file entries (fileName, fileBody) + * @param backout Donot delete stack on create Failure - defaulted to True + * @return A StackInfo object + * @throws MsoOpenstackException Thrown if the Openstack API call returns an exception. + */ + + @SuppressWarnings("unchecked") + public StackInfo createStack (String cloudSiteId, + String tenantId, + String stackName, + String heatTemplate, + Map <String, ? extends Object> stackInputs, + boolean pollForCompletion, + int timeoutMinutes, + String environment, + Map <String, Object> files, + Map <String, Object> heatFiles, + boolean backout) throws MsoException { + // Create local variables checking to see if we have an environment, nested, get_files + // Could later add some checks to see if it's valid. + boolean haveEnvtVariable = true; + if (environment == null || "".equalsIgnoreCase (environment.trim ())) { + haveEnvtVariable = false; + LOGGER.debug ("createStack called with no environment variable"); + } else { + LOGGER.debug ("createStack called with an environment variable: " + environment); + } + + boolean haveFiles = true; + if (files == null || files.isEmpty ()) { + haveFiles = false; + LOGGER.debug ("createStack called with no files / child template ids"); + } else { + LOGGER.debug ("createStack called with " + files.size () + " files / child template ids"); + } + + boolean haveHeatFiles = true; + if (heatFiles == null || heatFiles.isEmpty ()) { + haveHeatFiles = false; + LOGGER.debug ("createStack called with no heatFiles"); + } else { + LOGGER.debug ("createStack called with " + heatFiles.size () + " heatFiles"); + } + + // Obtain the cloud site information where we will create the stack + CloudSite cloudSite = cloudConfig.getCloudSite (cloudSiteId); + if (cloudSite == null) { + throw new MsoCloudSiteNotFound (cloudSiteId); + } + // Get a Heat client. They are cached between calls (keyed by tenantId:cloudId) + // This could throw MsoTenantNotFound or MsoOpenstackException (both propagated) + Heat heatClient = getHeatClient (cloudSite, tenantId); + + LOGGER.debug ("Ready to Create Stack (" + heatTemplate + ") with input params: " + stackInputs); + + // Build up the stack to create + // Disable auto-rollback, because error reason is lost. Always rollback in the code. + CreateStackParam stack = new CreateStackParam (); + stack.setStackName (stackName); + stack.setTimeoutMinutes (timeoutMinutes); + stack.setParameters ((Map <String, Object>) stackInputs); + stack.setTemplate (heatTemplate); + stack.setDisableRollback (true); + // TJM New for PO Adapter - add envt variable + if (haveEnvtVariable) { + LOGGER.debug ("Found an environment variable - value: " + environment); + stack.setEnvironment (environment); + } + // Now handle nested templates or get_files - have to combine if we have both + // as they're both treated as "files:" on the stack. + if (haveFiles && haveHeatFiles) { + // Let's do this here - not in the bean + LOGGER.debug ("Found files AND heatFiles - combine and add!"); + Map <String, Object> combinedFiles = new HashMap <String, Object> (); + for (String keyString : files.keySet ()) { + combinedFiles.put (keyString, files.get (keyString)); + } + for (String keyString : heatFiles.keySet ()) { + combinedFiles.put (keyString, heatFiles.get (keyString)); + } + stack.setFiles (combinedFiles); + } else { + // Handle if we only have one or neither: + if (haveFiles) { + LOGGER.debug ("Found files - adding to stack"); + stack.setFiles (files); + } + if (haveHeatFiles) { + LOGGER.debug ("Found heatFiles - adding to stack"); + // the setFiles was modified to handle adding the entries + stack.setFiles (heatFiles); + } + } + + Stack heatStack = null; + try { + // Execute the actual Openstack command to create the Heat stack + OpenStackRequest <Stack> request = heatClient.getStacks ().create (stack); + // Begin X-Auth-User + // Obtain an MSO token for the tenant + CloudIdentity cloudIdentity = cloudSite.getIdentityService (); + // cloudIdentity.getMsoId(), cloudIdentity.getMsoPass() + //req + 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()); + // END - try to fix X-Auth-User + heatStack = executeAndRecordOpenstackRequest (request, msoProps); + } catch (OpenStackResponseException e) { + // Since this came on the 'Create Stack' command, nothing was changed + // in the cloud. Return the error as an exception. + if (e.getStatus () == 409) { + // Stack already exists. Return a specific error for this case + MsoStackAlreadyExists me = new MsoStackAlreadyExists (stackName, tenantId, cloudSiteId); + me.addContext (CREATE_STACK); + throw me; + } else { + // Convert the OpenStackResponseException to an MsoOpenstackException + LOGGER.debug("ERROR STATUS = " + e.getStatus() + ",\n" + e.getMessage() + "\n" + e.getLocalizedMessage()); + throw heatExceptionToMsoException (e, CREATE_STACK); + } + } catch (OpenStackConnectException e) { + // Error connecting to Openstack instance. Convert to an MsoException + throw heatExceptionToMsoException (e, CREATE_STACK); + } catch (RuntimeException e) { + // Catch-all + throw runtimeExceptionToMsoException (e, CREATE_STACK); + } + + // Subsequent access by the canonical name "<stack name>/<stack-id>". + // Otherwise, simple query by name returns a 302 redirect. + // NOTE: This is specific to the v1 Orchestration API. + String canonicalName = stackName + "/" + heatStack.getId (); + + // If client has requested a final response, poll for stack completion + if (pollForCompletion) { + // Set a time limit on overall polling. + // Use the resource (template) timeout for Openstack (expressed in minutes) + // and add one poll interval to give Openstack a chance to fail on its own. + int createPollInterval = msoProps.getIntProperty (createPollIntervalProp, createPollIntervalDefault); + int pollTimeout = (timeoutMinutes * 60) + createPollInterval; + // New 1610 - poll on delete if we rollback - use same values for now + int deletePollInterval = createPollInterval; + int deletePollTimeout = pollTimeout; + boolean createTimedOut = false; + StringBuilder stackErrorStatusReason = new StringBuilder(""); + LOGGER.debug("createPollInterval=" + createPollInterval + ", pollTimeout=" + pollTimeout); + + while (true) { + try { + heatStack = queryHeatStack (heatClient, canonicalName); + LOGGER.debug (heatStack.getStackStatus () + " (" + canonicalName + ")"); + + if ("CREATE_IN_PROGRESS".equals (heatStack.getStackStatus ())) { + // Stack creation is still running. + // Sleep and try again unless timeout has been reached + if (pollTimeout <= 0) { + // Note that this should not occur, since there is a timeout specified + // in the Openstack call. + LOGGER.error (MessageEnum.RA_CREATE_STACK_TIMEOUT, cloudSiteId, tenantId, stackName, heatStack.getStackStatus (), "", "", MsoLogger.ErrorCode.AvailabilityError, "Create stack timeout"); + createTimedOut = true; + break; + } + try { + Thread.sleep (createPollInterval * 1000L); + } catch (InterruptedException e) { + LOGGER.debug ("Thread interrupted while sleeping", e); + } + + pollTimeout -= createPollInterval; + LOGGER.debug("pollTimeout remaining: " + pollTimeout); + } else { + //save off the status & reason msg before we attempt delete + stackErrorStatusReason.append("Stack error (" + heatStack.getStackStatus() + "): " + heatStack.getStackStatusReason()); + break; + } + } catch (MsoException me) { + // Cannot query the stack status. Something is wrong. + // Try to roll back the stack + if (!backout) + { + LOGGER.warn(MessageEnum.RA_CREATE_STACK_ERR, "Create Stack errored, stack deletion suppressed", "", "", MsoLogger.ErrorCode.BusinessProcesssError, "Exception in Create Stack, stack deletion suppressed"); + } + else + { + try { + LOGGER.debug("Create Stack error - unable to query for stack status - attempting to delete stack: " + canonicalName + " - This will likely fail and/or we won't be able to query to see if delete worked"); + OpenStackRequest <Void> request = heatClient.getStacks ().deleteByName (canonicalName); + executeAndRecordOpenstackRequest (request, msoProps); + // this may be a waste of time - if we just got an exception trying to query the stack - we'll just + // get another one, n'est-ce pas? + boolean deleted = false; + while (!deleted) { + try { + heatStack = queryHeatStack(heatClient, canonicalName); + if (heatStack != null) { + LOGGER.debug(heatStack.getStackStatus()); + if ("DELETE_IN_PROGRESS".equals(heatStack.getStackStatus())) { + if (deletePollTimeout <= 0) { + LOGGER.error (MessageEnum.RA_CREATE_STACK_TIMEOUT, cloudSiteId, tenantId, stackName, + heatStack.getStackStatus (), "", "", MsoLogger.ErrorCode.AvailabilityError, + "Rollback: DELETE stack timeout"); + break; + } else { + try { + Thread.sleep(deletePollInterval * 1000L); + } catch (InterruptedException ie) { + LOGGER.debug("Thread interrupted while sleeping", ie); + } + deletePollTimeout -= deletePollInterval; + } + } else if ("DELETE_COMPLETE".equals(heatStack.getStackStatus())){ + LOGGER.debug("DELETE_COMPLETE for " + canonicalName); + deleted = true; + continue; + } else { + //got a status other than DELETE_IN_PROGRESS or DELETE_COMPLETE - so break and evaluate + break; + } + } else { + // assume if we can't find it - it's deleted + LOGGER.debug("heatStack returned null - assume the stack " + canonicalName + " has been deleted"); + deleted = true; + continue; + } + + } catch (Exception e3) { + // Just log this one. We will report the original exception. + LOGGER.error (MessageEnum.RA_CREATE_STACK_ERR, "Create Stack: Nested exception rolling back stack: " + e3, "", "", MsoLogger.ErrorCode.BusinessProcesssError, "Create Stack: Nested exception rolling back stack on error on query"); + + } + } + } catch (Exception e2) { + // Just log this one. We will report the original exception. + LOGGER.error (MessageEnum.RA_CREATE_STACK_ERR, "Create Stack: Nested exception rolling back stack: " + e2, "", "", MsoLogger.ErrorCode.BusinessProcesssError, "Create Stack: Nested exception rolling back stack"); + } + } + + // Propagate the original exception from Stack Query. + me.addContext (CREATE_STACK); + throw me; + } + } + + if (!"CREATE_COMPLETE".equals (heatStack.getStackStatus ())) { + LOGGER.error (MessageEnum.RA_CREATE_STACK_ERR, "Create Stack error: Polling complete with non-success status: " + + heatStack.getStackStatus () + ", " + heatStack.getStackStatusReason (), "", "", MsoLogger.ErrorCode.BusinessProcesssError, "Create Stack error"); + + // Rollback the stack creation, since it is in an indeterminate state. + if (!backout) + { + LOGGER.warn(MessageEnum.RA_CREATE_STACK_ERR, "Create Stack errored, stack deletion suppressed", "", "", MsoLogger.ErrorCode.BusinessProcesssError, "Create Stack error, stack deletion suppressed"); + } + else + { + try { + LOGGER.debug("Create Stack errored - attempting to DELETE stack: " + canonicalName); + LOGGER.debug("deletePollInterval=" + deletePollInterval + ", deletePollTimeout=" + deletePollTimeout); + OpenStackRequest <Void> request = heatClient.getStacks ().deleteByName (canonicalName); + executeAndRecordOpenstackRequest (request, msoProps); + boolean deleted = false; + while (!deleted) { + try { + heatStack = queryHeatStack(heatClient, canonicalName); + if (heatStack != null) { + LOGGER.debug(heatStack.getStackStatus() + " (" + canonicalName + ")"); + if ("DELETE_IN_PROGRESS".equals(heatStack.getStackStatus())) { + if (deletePollTimeout <= 0) { + LOGGER.error (MessageEnum.RA_CREATE_STACK_TIMEOUT, cloudSiteId, tenantId, stackName, + heatStack.getStackStatus (), "", "", MsoLogger.ErrorCode.AvailabilityError, + "Rollback: DELETE stack timeout"); + break; + } else { + try { + Thread.sleep(deletePollInterval * 1000L); + } catch (InterruptedException ie) { + LOGGER.debug("Thread interrupted while sleeping", ie); + } + deletePollTimeout -= deletePollInterval; + LOGGER.debug("deletePollTimeout remaining: " + deletePollTimeout); + } + } else if ("DELETE_COMPLETE".equals(heatStack.getStackStatus())){ + LOGGER.debug("DELETE_COMPLETE for " + canonicalName); + deleted = true; + continue; + } else if ("DELETE_FAILED".equals(heatStack.getStackStatus())) { + // Warn about this (?) - but still throw the original exception + LOGGER.warn(MessageEnum.RA_CREATE_STACK_ERR, "Create Stack errored, stack deletion FAILED", "", "", MsoLogger.ErrorCode.BusinessProcesssError, "Create Stack error, stack deletion FAILED"); + LOGGER.debug("Stack deletion FAILED on a rollback of a create - " + canonicalName + ", status=" + heatStack.getStackStatus() + ", reason=" + heatStack.getStackStatusReason()); + break; + } else { + //got a status other than DELETE_IN_PROGRESS or DELETE_COMPLETE - so break and evaluate + break; + } + } else { + // assume if we can't find it - it's deleted + LOGGER.debug("heatStack returned null - assume the stack " + canonicalName + " has been deleted"); + deleted = true; + continue; + } + + } catch (MsoException me2) { + // We got an exception on the delete - don't throw this exception - throw the original - just log. + LOGGER.debug("Exception thrown trying to delete " + canonicalName + " on a create->rollback: " + me2.getContextMessage()); + LOGGER.warn(MessageEnum.RA_CREATE_STACK_ERR, "Create Stack errored, then stack deletion FAILED - exception thrown", "", "", MsoLogger.ErrorCode.BusinessProcesssError, me2.getContextMessage()); + } + + } // end while !deleted + StringBuilder errorContextMessage = null; + if (createTimedOut) { + errorContextMessage = new StringBuilder("Stack Creation Timeout"); + } else { + errorContextMessage = stackErrorStatusReason; + } + if (deleted) { + errorContextMessage.append(" - stack successfully deleted"); + } else { + errorContextMessage.append(" - encountered an error trying to delete the stack"); + } +// MsoOpenstackException me = new MsoOpenstackException(0, "", stackErrorStatusReason.toString()); + // me.addContext(CREATE_STACK); + // alarmLogger.sendAlarm(HEAT_ERROR, MsoAlarmLogger.CRITICAL, me.getContextMessage()); + // throw me; + } catch (Exception e2) { + // shouldn't happen - but handle + LOGGER.error (MessageEnum.RA_CREATE_STACK_ERR, "Create Stack: Nested exception rolling back stack: " + e2, "", "", MsoLogger.ErrorCode.BusinessProcesssError, "Exception in Create Stack: rolling back stack"); + } + } + MsoOpenstackException me = new MsoOpenstackException(0, "", stackErrorStatusReason.toString()); + me.addContext(CREATE_STACK); + alarmLogger.sendAlarm(HEAT_ERROR, MsoAlarmLogger.CRITICAL, me.getContextMessage()); + throw me; + } + + } else { + // Get initial status, since it will have been null after the create. + heatStack = queryHeatStack (heatClient, canonicalName); + LOGGER.debug (heatStack.getStackStatus ()); + } + + return new StackInfo (heatStack); + } + + /** + * Query for a single stack (by Name) in a tenant. This call will always return a + * StackInfo object. If the stack does not exist, an "empty" StackInfo will be + * returned - containing only the stack name and a 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 StackInfo queryStack (String cloudSiteId, String tenantId, String stackName) throws MsoException { + LOGGER.debug ("Query HEAT stack: " + stackName + " in tenant " + tenantId); + + // Obtain the cloud site information where we will create the stack + CloudSite cloudSite = cloudConfig.getCloudSite (cloudSiteId); + if (cloudSite == null) { + throw new MsoCloudSiteNotFound (cloudSiteId); + } + + // Get a Heat client. They are cached between calls (keyed by tenantId:cloudId) + Heat heatClient = null; + try { + heatClient = getHeatClient (cloudSite, tenantId); + } catch (MsoTenantNotFound e) { + // Tenant doesn't exist, so stack doesn't either + LOGGER.debug ("Tenant with id " + tenantId + "not found.", e); + return new StackInfo (stackName, HeatStatus.NOTFOUND, null, null); + } catch (MsoException me) { + // Got an Openstack error. Propagate it + LOGGER.error (MessageEnum.RA_CONNECTION_EXCEPTION, "OpenStack", "Openstack Exception on Token request: " + me, "Openstack", "", MsoLogger.ErrorCode.AvailabilityError, "Connection Exception"); + me.addContext ("QueryStack"); + throw me; + } + + // Query the Stack. + // An MsoException will propagate transparently to the caller. + Stack heatStack = queryHeatStack (heatClient, stackName); + + if (heatStack == null) { + // Stack does not exist. Return a StackInfo with status NOTFOUND + StackInfo stackInfo = new StackInfo (stackName, HeatStatus.NOTFOUND, null, null); + return stackInfo; + } + + return new StackInfo (heatStack); + } + + /** + * Delete a stack (by Name/ID) in a tenant. If the stack is not found, it will be + * considered a successful deletion. The return value is a StackInfo object which + * contains the current stack status. + * + * The client may choose to let the adapter poll Openstack for completion of the + * stack deletion, or may handle polling itself via separate query calls. In either + * case, a StackInfo object will be returned. When polling is enabled, a final + * status of NOTFOUND is expected. When not polling, a status of DELETING is expected. + * + * There is no rollback from a successful stack deletion. A deletion failure will + * also result in an undefined stack state - the components may or may not have been + * all or partially deleted, so the resulting stack 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 StackInfo deleteStack (String tenantId, + String cloudSiteId, + String stackName, + boolean pollForCompletion) throws MsoException { + // Obtain the cloud site information where we will create the stack + CloudSite cloudSite = cloudConfig.getCloudSite (cloudSiteId); + if (cloudSite == null) { + throw new MsoCloudSiteNotFound (cloudSiteId); + } + + // Get a Heat client. They are cached between calls (keyed by tenantId:cloudId) + Heat heatClient = null; + try { + heatClient = getHeatClient (cloudSite, tenantId); + } catch (MsoTenantNotFound e) { + // Tenant doesn't exist, so stack doesn't either + LOGGER.debug ("Tenant with id " + tenantId + "not found.", e); + return new StackInfo (stackName, HeatStatus.NOTFOUND, null, null); + } catch (MsoException me) { + // Got an Openstack error. Propagate it + LOGGER.error (MessageEnum.RA_CONNECTION_EXCEPTION, "Openstack", "Openstack Exception on Token request: " + me, "Openstack", "", MsoLogger.ErrorCode.AvailabilityError, "Connection Exception"); + me.addContext (DELETE_STACK); + throw me; + } + + // OK if stack not found, perform a query first + Stack heatStack = queryHeatStack (heatClient, stackName); + if (heatStack == null || "DELETE_COMPLETE".equals (heatStack.getStackStatus ())) { + // Not found. Return a StackInfo with status NOTFOUND + return new StackInfo (stackName, HeatStatus.NOTFOUND, null, null); + } + + // Delete the stack. + + // Use canonical name "<stack name>/<stack-id>" to delete. + // Otherwise, deletion by name returns a 302 redirect. + // NOTE: This is specific to the v1 Orchestration API. + String canonicalName = heatStack.getStackName () + "/" + heatStack.getId (); + + try { + OpenStackRequest <Void> request = heatClient.getStacks ().deleteByName (canonicalName); + executeAndRecordOpenstackRequest (request, msoProps); + } catch (OpenStackResponseException e) { + if (e.getStatus () == 404) { + // Not found. We are OK with this. Return a StackInfo with status NOTFOUND + return new StackInfo (stackName, HeatStatus.NOTFOUND, null, null); + } else { + // Convert the OpenStackResponseException to an MsoOpenstackException + throw heatExceptionToMsoException (e, DELETE_STACK); + } + } catch (OpenStackConnectException e) { + // Error connecting to Openstack instance. Convert to an MsoException + throw heatExceptionToMsoException (e, DELETE_STACK); + } catch (RuntimeException e) { + // Catch-all + throw runtimeExceptionToMsoException (e, DELETE_STACK); + } + + // Requery the stack for current status. + // It will probably still exist with "DELETE_IN_PROGRESS" status. + heatStack = queryHeatStack (heatClient, canonicalName); + + if (pollForCompletion) { + // Set a timeout on polling + int pollInterval = msoProps.getIntProperty (deletePollIntervalProp, deletePollIntervalDefault); + int pollTimeout = msoProps.getIntProperty (deletePollTimeoutProp, deletePollTimeoutDefault); + + // When querying by canonical name, Openstack returns DELETE_COMPLETE status + // instead of "404" (which would result from query by stack name). + while (heatStack != null && !"DELETE_COMPLETE".equals (heatStack.getStackStatus ())) { + LOGGER.debug ("Stack status: " + heatStack.getStackStatus ()); + + if ("DELETE_FAILED".equals (heatStack.getStackStatus ())) { + // Throw a 'special case' of MsoOpenstackException to report the Heat status + String error = "Stack delete error (" + heatStack.getStackStatus () + + "): " + + heatStack.getStackStatusReason (); + MsoOpenstackException me = new MsoOpenstackException (0, "", error); + me.addContext (DELETE_STACK); + + // Alarm this condition, stack deletion failed + alarmLogger.sendAlarm (HEAT_ERROR, MsoAlarmLogger.CRITICAL, me.getContextMessage ()); + + throw me; + } + + if (pollTimeout <= 0) { + LOGGER.error (MessageEnum.RA_DELETE_STACK_TIMEOUT, cloudSiteId, tenantId, stackName, heatStack.getStackStatus (), "", "", MsoLogger.ErrorCode.AvailabilityError, "Delete Stack Timeout"); + + // Throw a 'special case' of MsoOpenstackException to report the Heat status + MsoOpenstackException me = new MsoOpenstackException (0, "", "Stack Deletion Timeout"); + me.addContext (DELETE_STACK); + + // Alarm this condition, stack deletion failed + alarmLogger.sendAlarm (HEAT_ERROR, MsoAlarmLogger.CRITICAL, me.getContextMessage ()); + + throw me; + } + + try { + Thread.sleep (pollInterval * 1000L); + } catch (InterruptedException e) { + LOGGER.debug ("Thread interrupted while sleeping", e); + } + + pollTimeout -= pollInterval; + + heatStack = queryHeatStack (heatClient, canonicalName); + } + + // The stack is gone when this point is reached + return new StackInfo (stackName, HeatStatus.NOTFOUND, null, null); + } + + // Return the current status (if not polling, the delete may still be in progress) + StackInfo stackInfo = new StackInfo (heatStack); + stackInfo.setName (stackName); + + return stackInfo; + } + + /** + * Query for all stacks in a tenant site. This call will return a List of StackInfo + * objects, one for each deployed stack. + * + * Note that this is limited to a single site. To ensure that a tenant is truly + * empty would require looping across all tenant endpoints. + * + * @param tenantId The Openstack ID of the tenant to query + * @param cloudSiteId The cloud identifier (may be a region) in which to query. + * @return A List of StackInfo objects + * @throws MsoOpenstackException Thrown if the Openstack API call returns an exception. + * @throws MsoCloudSiteNotFound + */ + public List <StackInfo> queryAllStacks (String tenantId, String cloudSiteId) throws MsoException { + // Obtain the cloud site information where we will create the stack + CloudSite cloudSite = cloudConfig.getCloudSite (cloudSiteId); + if (cloudSite == null) { + throw new MsoCloudSiteNotFound (cloudSiteId); + } + + // Get a Heat client. They are cached between calls (keyed by tenantId:cloudId) + Heat heatClient = getHeatClient (cloudSite, tenantId); + + try { + OpenStackRequest <Stacks> request = heatClient.getStacks ().list (); + Stacks stacks = executeAndRecordOpenstackRequest (request, msoProps); + + List <StackInfo> stackList = new ArrayList <StackInfo> (); + + // Not sure if returns an empty list or null if no stacks exist + if (stacks != null) { + for (Stack stack : stacks) { + stackList.add (new StackInfo (stack)); + } + } + + return stackList; + } catch (OpenStackResponseException e) { + if (e.getStatus () == 404) { + // Not sure if this can happen, but return an empty list + LOGGER.debug ("queryAllStacks - stack not found: "); + return new ArrayList <StackInfo> (); + } else { + // Convert the OpenStackResponseException to an MsoOpenstackException + throw heatExceptionToMsoException (e, QUERY_ALL_STACKS); + } + } catch (OpenStackConnectException e) { + // Error connecting to Openstack instance. Convert to an MsoException + throw heatExceptionToMsoException (e, QUERY_ALL_STACKS); + } catch (RuntimeException e) { + // Catch-all + throw runtimeExceptionToMsoException (e, QUERY_ALL_STACKS); + } + } + + /** + * Validate parameters to be passed to Heat template. This method performs + * three functions: + * 1. Apply default values to parameters which have them defined + * 2. Report any required parameters that are missing. This will generate an + * exception in the caller, since stack create/update operations would fail. + * 3. Report and remove any extraneous parameters. This will allow clients to + * pass supersets of parameters and not get errors. + * + * These functions depend on the HeatTemplate definition from the MSO Catalog DB, + * along with the input parameter Map. The output is an updated parameter map. + * If the parameters are invalid for the template, an IllegalArgumentException + * is thrown. + */ + public Map <String, Object> validateStackParams (Map <String, Object> inputParams, + HeatTemplate heatTemplate) throws IllegalArgumentException { + // Check that required parameters have been supplied for this template type + String missingParams = null; + List <String> paramList = new ArrayList <String> (); + + // TODO: Enhance DB to support defaults for Heat Template parameters + + for (HeatTemplateParam parm : heatTemplate.getParameters ()) { + if (parm.isRequired () && !inputParams.containsKey (parm.getParamName ())) { + if (missingParams == null) { + missingParams = parm.getParamName (); + } else { + missingParams += "," + parm.getParamName (); + } + } + paramList.add (parm.getParamName ()); + } + if (missingParams != null) { + // Problem - missing one or more required parameters + String error = "Missing Required inputs for HEAT Template: " + missingParams; + LOGGER.error (MessageEnum.RA_MISSING_PARAM, missingParams + " for HEAT Template", "", "", MsoLogger.ErrorCode.SchemaError, "Missing Required inputs for HEAT Template: " + missingParams); + throw new IllegalArgumentException (error); + } + + // Remove any extraneous parameters (don't throw an error) + Map <String, Object> updatedParams = new HashMap <String, Object> (); + List <String> extraParams = new ArrayList <String> (); + for (String key : inputParams.keySet ()) { + if (!paramList.contains (key)) { + // This is not a valid parameter for this template + extraParams.add (key); + } else { + updatedParams.put (key, inputParams.get (key)); + } + } + if (!extraParams.isEmpty ()) { + LOGGER.warn (MessageEnum.RA_GENERAL_WARNING, "Heat Stack (" + heatTemplate.getTemplateName () + + ") extra input params received: " + + extraParams, "", "", MsoLogger.ErrorCode.DataError, "Heat Stack (" + heatTemplate.getTemplateName () + ") extra input params received: "+ extraParams); + } + + return updatedParams; + } + + // --------------------------------------------------------------- + // PRIVATE FUNCTIONS FOR USE WITHIN THIS CLASS + + /** + * Get a Heat client for the Openstack Identity service. + * This requires a 'member'-level userId + password, which will be retrieved from + * properties based on the specified cloud Id. The tenant in which to operate + * must also be provided. + * <p> + * On successful authentication, the Heat object will be cached for the + * tenantID + cloudId so that it can be reused without reauthenticating with + * Openstack every time. + * + * @param tenantName + * @param cloudId + * @return an authenticated Heat object + */ + public Heat getHeatClient (CloudSite cloudSite, String tenantId) throws MsoException { + String cloudId = cloudSite.getId (); + + // Check first in the cache of previously authorized clients + String cacheKey = cloudId + ":" + tenantId; + if (heatClientCache.containsKey (cacheKey)) { + if (!heatClientCache.get (cacheKey).isExpired ()) { + LOGGER.debug ("Using Cached HEAT Client for " + cacheKey); + return heatClientCache.get (cacheKey).getHeatClient (); + } else { + // Token is expired. Remove it from cache. + heatClientCache.remove (cacheKey); + LOGGER.debug ("Expired Cached HEAT Client for " + cacheKey); + } + } + + // Obtain an MSO token for the tenant + CloudIdentity cloudIdentity = cloudSite.getIdentityService (); + String keystoneUrl = cloudIdentity.getKeystoneUrl (cloudId, msoPropID); + Keystone keystoneTenantClient = new Keystone (keystoneUrl); + Access access = null; + try { + Authentication credentials = cloudIdentity.getAuthentication (); + + OpenStackRequest <Access> request = keystoneTenantClient.tokens () + .authenticate (credentials).withTenantId (tenantId); + + access = executeAndRecordOpenstackRequest (request, msoProps); + } catch (OpenStackResponseException e) { + if (e.getStatus () == 401) { + // Authentication error. + String error = "Authentication Failure: tenant=" + tenantId + ",cloud=" + cloudIdentity.getId (); + alarmLogger.sendAlarm ("MsoAuthenticationError", MsoAlarmLogger.CRITICAL, error); + throw new MsoAdapterException (error); + } else { + throw keystoneErrorToMsoException (e, TOKEN_AUTH); + } + } catch (OpenStackConnectException e) { + // Connection to Openstack failed + MsoIOException me = new MsoIOException (e.getMessage (), e); + me.addContext (TOKEN_AUTH); + throw me; + } catch (RuntimeException e) { + // Catch-all + throw runtimeExceptionToMsoException (e, TOKEN_AUTH); + } + + // For DCP/LCP, the region should be the cloudId. + String region = cloudSite.getRegionId (); + String heatUrl = null; + try { + heatUrl = KeystoneUtils.findEndpointURL (access.getServiceCatalog (), "orchestration", region, "public"); + } catch (RuntimeException e) { + // This comes back for not found (probably an incorrect region ID) + String error = "Orchestration service not found: region=" + region + ",cloud=" + cloudIdentity.getId (); + alarmLogger.sendAlarm ("MsoConfigurationError", MsoAlarmLogger.CRITICAL, error); + throw new MsoAdapterException (error, e); + } + // This is needed for testing in the MT cloud + if ("MT".equals (cloudId)) { + heatUrl = heatUrl.replace ("controller", "mtdnj02bh01wt.bvoip.labs.att.com"); + } + + Heat heatClient = new Heat (heatUrl); + heatClient.token (access.getToken ().getId ()); + + heatClientCache.put (cacheKey, + new HeatCacheEntry (heatUrl, + access.getToken ().getId (), + access.getToken ().getExpires ())); + LOGGER.debug ("Caching HEAT Client for " + cacheKey); + + return heatClient; + } + + /** + * Forcibly expire a HEAT client from the cache. This call is for use by + * the KeystoneClient in case where a tenant is deleted. In that case, + * all cached credentials must be purged so that fresh authentication is + * done if a similarly named tenant is re-created. + * <p> + * Note: This is probably only applicable to dev/test environments where + * the same Tenant Name is repeatedly used for creation/deletion. + * <p> + * + * @param tenantName + * @param cloudId + */ + public static void expireHeatClient (String tenantId, String cloudId) { + String cacheKey = cloudId + ":" + tenantId; + if (heatClientCache.containsKey (cacheKey)) { + heatClientCache.remove (cacheKey); + LOGGER.debug ("Deleted Cached HEAT Client for " + cacheKey); + } + } + + /* + * Query for a Heat Stack. This function is needed in several places, so + * a common method is useful. This method takes an authenticated Heat Client + * (which internally identifies the cloud & tenant to search), and returns + * a Stack object if found, Null if not found, or an MsoOpenstackException + * if the Openstack API call fails. + * + * The stack name may be a simple name or a canonical name ("{name}/{id}"). + * When simple name is used, Openstack always returns a 302 redirect which + * results in a 2nd request (to the canonical name). Note that query by + * canonical name for a deleted stack returns a Stack object with status + * "DELETE_COMPLETE" while query by simple name for a deleted stack returns + * HTTP 404. + * + * @param heatClient an authenticated Heat client + * + * @param stackName the stack name to query + * + * @return a Stack object that describes the current stack or null if the + * requested stack doesn't exist. + * + * @throws MsoOpenstackException Thrown if the Openstack API call returns an exception + */ + protected Stack queryHeatStack (Heat heatClient, String stackName) throws MsoException { + if (stackName == null) { + return null; + } + try { + OpenStackRequest <Stack> request = heatClient.getStacks ().byName (stackName); + return executeAndRecordOpenstackRequest (request, msoProps); + } catch (OpenStackResponseException e) { + if (e.getStatus () == 404) { + LOGGER.debug ("queryHeatStack - stack not found: " + stackName); + return null; + } else { + // Convert the OpenStackResponseException to an MsoOpenstackException + throw heatExceptionToMsoException (e, "QueryStack"); + } + } catch (OpenStackConnectException e) { + // Connection to Openstack failed + throw heatExceptionToMsoException (e, "QueryAllStack"); + } + } + + /* + * An entry in the Heat Client Cache. It saves the Heat client object + * along with the token expiration. After this interval, this cache + * item will no longer be used. + */ + private static class HeatCacheEntry implements Serializable { + + private static final long serialVersionUID = 1L; + + private String heatUrl; + private String token; + private Calendar expires; + + public HeatCacheEntry (String heatUrl, String token, Calendar expires) { + this.heatUrl = heatUrl; + this.token = token; + this.expires = expires; + } + + public Heat getHeatClient () { + Heat heatClient = new Heat (heatUrl); + heatClient.token (token); + return heatClient; + } + + public boolean isExpired () { + if (expires == null) { + return true; + } + + Calendar now = Calendar.getInstance (); + if (now.after (expires)) { + return true; + } + + return false; + } + } + + /** + * Clean up the Heat client cache to remove expired entries. + */ + public static void heatCacheCleanup () { + for (String cacheKey : heatClientCache.keySet ()) { + if (heatClientCache.get (cacheKey).isExpired ()) { + heatClientCache.remove (cacheKey); + LOGGER.debug ("Cleaned Up Cached Heat Client for " + cacheKey); + } + } + } + + /** + * Reset the Heat client cache. + * This may be useful if cached credentials get out of sync. + */ + public static void heatCacheReset () { + heatClientCache = new HashMap <String, HeatCacheEntry> (); + } + + public Map<String, Object> queryStackForOutputs(String cloudSiteId, + String tenantId, String stackName) throws MsoException { + LOGGER.debug("MsoHeatUtils.queryStackForOutputs)"); + StackInfo heatStack = this.queryStack(cloudSiteId, tenantId, stackName); + if (heatStack == null || heatStack.getStatus() == HeatStatus.NOTFOUND) { + return null; + } + Map<String, Object> outputs = heatStack.getOutputs(); + return outputs; + } + + public void queryAndCopyOutputsToInputs(String cloudSiteId, + String tenantId, String stackName, Map<String, String> inputs, + boolean overWrite) throws MsoException { + LOGGER.debug("MsoHeatUtils.queryAndCopyOutputsToInputs"); + Map<String, Object> outputs = this.queryStackForOutputs(cloudSiteId, + tenantId, stackName); + this.copyStringOutputsToInputs(inputs, outputs, overWrite); + return; + } + + 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("DANGER WILL ROBINSON: unable to convert 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("DANGER WILL ROBINSON: unable to convert 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("DANGER WILL ROBINSON: unable to convert value for "+ key); + //effect here is this value will not have been copied to the inputs - and therefore will error out downstream + } + } + } + } + return; + } + public StringBuilder requestToStringBuilder(CreateStackParam stack) { + StringBuilder sb = new StringBuilder(); + sb.append("Stack:\n"); + sb.append("\tStackName: " + stack.getStackName()); + sb.append("\tTemplateUrl: " + stack.getTemplateUrl()); + sb.append("\tTemplate: " + stack.getTemplate()); + sb.append("\tEnvironment: " + stack.getEnvironment()); + sb.append("\tTimeout: " + stack.getTimeoutMinutes()); + sb.append("\tParameters:\n"); + Map<String, Object> params = stack.getParameters(); + if (params == null || params.size() < 1) { + sb.append("\tNONE"); + } else { + for (String key : params.keySet()) { + if (params.get(key) instanceof String) { + sb.append("\t" + key + "=" + (String) params.get(key)); + } else if (params.get(key) instanceof JsonNode) { + String jsonStringOut = this.convertNode((JsonNode)params.get(key)); + sb.append("\t" + key + "=" + jsonStringOut); + } else { + sb.append("\t" + key + "= [some non-string/non-json]"); + } + } + } + return sb; + } + + 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]"; + } +} 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 new file mode 100644 index 0000000000..04dfa12796 --- /dev/null +++ b/adapters/mso-adapter-utils/src/main/java/org/openecomp/mso/openstack/utils/MsoHeatUtilsWithUpdate.java @@ -0,0 +1,333 @@ +/*- + * ============LICENSE_START======================================================= + * OPENECOMP - MSO + * ================================================================================ + * 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.utils; + + +import java.util.HashMap; +import java.util.Map; + +import org.openecomp.mso.cloud.CloudConfigFactory; +import org.openecomp.mso.cloud.CloudSite; +import org.openecomp.mso.logger.MessageEnum; +import org.openecomp.mso.logger.MsoLogger; +import org.openecomp.mso.openstack.beans.StackInfo; +import org.openecomp.mso.openstack.exceptions.MsoCloudSiteNotFound; +import org.openecomp.mso.openstack.exceptions.MsoException; +import org.openecomp.mso.openstack.exceptions.MsoOpenstackException; +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.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; + +public class MsoHeatUtilsWithUpdate extends MsoHeatUtils { + + private static final String UPDATE_STACK = "UpdateStack"; + private static MsoLogger LOGGER = MsoLogger.getMsoLogger (MsoLogger.Catalog.RA); + + protected MsoJavaProperties msoProps = null; + + public MsoHeatUtilsWithUpdate (String msoPropID, MsoPropertiesFactory msoPropertiesFactory, CloudConfigFactory cloudConfFactory) { + super (msoPropID,msoPropertiesFactory,cloudConfFactory); + + 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.AvailabilityError, "Exception Mso Properties ID not found in cache: " + msoPropID, e); + } + } + + /* + * Keep these methods around for backward compatibility + */ + + public StackInfo updateStack (String cloudSiteId, + String tenantId, + String stackName, + String heatTemplate, + Map <String, Object> stackInputs, + boolean pollForCompletion, + int timeoutMinutes) throws MsoException { + // Keeping this method to allow compatibility with no environment or files variable sent. In this case, + // simply return the new method with the environment variable set to null. + return this.updateStack (cloudSiteId, + tenantId, + stackName, + heatTemplate, + stackInputs, + pollForCompletion, + timeoutMinutes, + null, + null, + null); + } + + public StackInfo updateStack (String cloudSiteId, + String tenantId, + String stackName, + String heatTemplate, + Map <String, Object> stackInputs, + boolean pollForCompletion, + int timeoutMinutes, + String environment) throws MsoException { + // Keeping this method to allow compatibility with no environment variable sent. In this case, + // simply return the new method with the files variable set to null. + return this.updateStack (cloudSiteId, + tenantId, + stackName, + heatTemplate, + stackInputs, + pollForCompletion, + timeoutMinutes, + environment, + null, + null); + } + + public StackInfo updateStack (String cloudSiteId, + String tenantId, + String stackName, + String heatTemplate, + Map <String, Object> stackInputs, + boolean pollForCompletion, + int timeoutMinutes, + String environment, + Map <String, Object> files) throws MsoException { + return this.updateStack (cloudSiteId, + tenantId, + stackName, + heatTemplate, + stackInputs, + pollForCompletion, + timeoutMinutes, + environment, + files, + null); + } + + /** + * Update a Stack in the specified cloud location and tenant. The Heat template + * and parameter map are passed in as arguments, along with the cloud access credentials. + * 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 Stack name supplied by the caller must be unique in the scope of this 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. + * + * The caller may choose to let this function poll Openstack for completion of the + * stack creation, or may handle polling itself via separate calls to query the status. + * In either case, a StackInfo object will be returned containing the current status. + * When polling is enabled, a status of CREATED is expected. When not polling, a + * status of BUILDING is expected. + * + * An error will be thrown if the requested Stack already exists in the specified + * Tenant and Cloud. + * + * @param tenantId The Openstack ID of the tenant in which to create the Stack + * @param cloudSiteId The cloud identifier (may be a region) in which to create the tenant. + * @param stackName The name of the stack to update + * @param stackTemplate The Heat template + * @param stackInputs A map of key/value inputs + * @param pollForCompletion Indicator that polling should be handled in Java vs. in the client + * @param environment An optional yaml-format string to specify environmental parameters + * @param files a Map<String, Object> for listing child template IDs + * @param heatFiles a Map<String, Object> for listing get_file entries (fileName, fileBody) + * @return A StackInfo object + * @throws MsoException Thrown if the Openstack API call returns an exception. + */ + + public StackInfo updateStack (String cloudSiteId, + String tenantId, + String stackName, + String heatTemplate, + Map <String, Object> stackInputs, + boolean pollForCompletion, + int timeoutMinutes, + String environment, + Map <String, Object> files, + Map <String, Object> heatFiles) throws MsoException { + boolean heatEnvtVariable = true; + if (environment == null || "".equalsIgnoreCase (environment.trim ())) { + heatEnvtVariable = false; + } + boolean haveFiles = true; + if (files == null || files.isEmpty ()) { + haveFiles = false; + } + boolean haveHeatFiles = true; + if (heatFiles == null || heatFiles.isEmpty ()) { + haveHeatFiles = false; + } + + // Obtain the cloud site information where we will create the stack + CloudSite cloudSite = cloudConfig.getCloudSite (cloudSiteId); + if (cloudSite == null) { + throw new MsoCloudSiteNotFound (cloudSiteId); + } + // Get a Heat client. They are cached between calls (keyed by tenantId:cloudId) + // This could throw MsoTenantNotFound or MsoOpenstackException (both propagated) + Heat heatClient = getHeatClient (cloudSite, tenantId); + + // Perform a query first to get the current status + Stack heatStack = queryHeatStack (heatClient, stackName); + if (heatStack == null || "DELETE_COMPLETE".equals (heatStack.getStackStatus ())) { + // Not found. Return a StackInfo with status NOTFOUND + throw new MsoStackNotFound (stackName, tenantId, cloudSiteId); + } + + // Use canonical name "<stack name>/<stack-id>" to update the stack. + // Otherwise, update by name returns a 302 redirect. + // NOTE: This is specific to the v1 Orchestration API. + String canonicalName = heatStack.getStackName () + "/" + heatStack.getId (); + + LOGGER.debug ("Ready to Update Stack (" + canonicalName + ") with input params: " + stackInputs); + + // Build up the stack update parameters + // Disable auto-rollback, because error reason is lost. Always rollback in the code. + UpdateStackParam stack = new UpdateStackParam (); + stack.setTimeoutMinutes (timeoutMinutes); + stack.setParameters (stackInputs); + stack.setTemplate (heatTemplate); + stack.setDisableRollback (true); + // TJM add envt to stack + if (heatEnvtVariable) { + stack.setEnvironment (environment); + } + + // Handle nested templates & get_files here. if we have both - must combine + // and then add to stack (both are part of "files:" being added to stack) + if (haveFiles && haveHeatFiles) { + // Let's do this here - not in the bean + LOGGER.debug ("Found files AND heatFiles - combine and add!"); + Map <String, Object> combinedFiles = new HashMap <String, Object> (); + for (String keyString : files.keySet ()) { + combinedFiles.put (keyString, files.get (keyString)); + } + for (String keyString : heatFiles.keySet ()) { + combinedFiles.put (keyString, heatFiles.get (keyString)); + } + stack.setFiles (combinedFiles); + } else { + // Handle case where we have one or neither + if (haveFiles) { + stack.setFiles (files); + } + if (haveHeatFiles) { + // setFiles method modified to handle adding a map. + stack.setFiles (heatFiles); + } + } + + try { + // Execute the actual Openstack command to update the Heat stack + OpenStackRequest <Void> request = heatClient.getStacks ().update (canonicalName, stack); + executeAndRecordOpenstackRequest (request, msoProps); + } catch (OpenStackBaseException e) { + // Since this came on the 'Update Stack' command, nothing was changed + // in the cloud. Rethrow the error as an MSO exception. + throw heatExceptionToMsoException (e, UPDATE_STACK); + } catch (RuntimeException e) { + // Catch-all + throw runtimeExceptionToMsoException (e, UPDATE_STACK); + } + + // If client has requested a final response, poll for stack completion + Stack updateStack = null; + if (pollForCompletion) { + // Set a time limit on overall polling. + // Use the resource (template) timeout for Openstack (expressed in minutes) + // and add one poll interval to give Openstack a chance to fail on its own. + int createPollInterval = msoProps.getIntProperty (createPollIntervalProp, createPollIntervalDefault); + int pollTimeout = (timeoutMinutes * 60) + createPollInterval; + + boolean loopAgain = true; + while (loopAgain) { + try { + updateStack = queryHeatStack (heatClient, canonicalName); + LOGGER.debug (updateStack.getStackStatus ()); + + if ("UPDATE_IN_PROGRESS".equals (updateStack.getStackStatus ())) { + // Stack update is still running. + // Sleep and try again unless timeout has been reached + if (pollTimeout <= 0) { + // Note that this should not occur, since there is a timeout specified + // in the Openstack call. + LOGGER.error (MessageEnum.RA_UPDATE_STACK_TIMEOUT, cloudSiteId, tenantId, stackName, updateStack.getStackStatus(), "", "", MsoLogger.ErrorCode.AvailabilityError, "Update stack timeout"); + loopAgain = false; + } else { + try { + Thread.sleep (createPollInterval * 1000L); + } catch (InterruptedException e) { + // If we are interrupted, we should stop ASAP. + loopAgain = false; + // Set again the interrupted flag + Thread.currentThread().interrupt(); + } + } + pollTimeout -= createPollInterval; + } else { + loopAgain = false; + } + } catch (MsoException e) { + // Cannot query the stack. Something is wrong. + + // TODO: No way to roll back the stack at this point. What to do? + e.addContext (UPDATE_STACK); + throw e; + } + } + + if (!"UPDATE_COMPLETE".equals (updateStack.getStackStatus ())) { + LOGGER.error (MessageEnum.RA_UPDATE_STACK_ERR, updateStack.getStackStatus(), updateStack.getStackStatusReason(), "", "", MsoLogger.ErrorCode.DataError, "Update Stack error"); + + // TODO: No way to roll back the stack at this point. What to do? + // Throw a 'special case' of MsoOpenstackException to report the Heat status + MsoOpenstackException me = null; + if ("UPDATE_IN_PROGRESS".equals (updateStack.getStackStatus ())) { + me = new MsoOpenstackException (0, "", "Stack Update Timeout"); + } else { + String error = "Stack error (" + updateStack.getStackStatus () + + "): " + + updateStack.getStackStatusReason (); + me = new MsoOpenstackException (0, "", error); + } + me.addContext (UPDATE_STACK); + throw me; + } + + } else { + // Return the current status. + updateStack = queryHeatStack (heatClient, canonicalName); + if (updateStack != null) { + LOGGER.debug ("UpdateStack, status = " + updateStack.getStackStatus ()); + } else { + LOGGER.debug ("UpdateStack, stack not found"); + } + } + return new StackInfo (updateStack); + } +} 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 new file mode 100644 index 0000000000..82203d044c --- /dev/null +++ b/adapters/mso-adapter-utils/src/main/java/org/openecomp/mso/openstack/utils/MsoKeystoneUtils.java @@ -0,0 +1,684 @@ +/*- + * ============LICENSE_START======================================================= + * OPENECOMP - MSO + * ================================================================================ + * 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.utils; + + +import java.io.Serializable; +import java.util.Calendar; +import java.util.HashMap; +import java.util.Map; + +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 org.openecomp.mso.logger.MsoAlarmLogger; +import org.openecomp.mso.logger.MsoLogger; +import org.openecomp.mso.logger.MessageEnum; +import org.openecomp.mso.openstack.beans.MsoTenant; +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.MsoOpenstackException; +import org.openecomp.mso.openstack.exceptions.MsoTenantAlreadyExists; +import org.openecomp.mso.properties.MsoJavaProperties; +import org.openecomp.mso.properties.MsoPropertiesException; +import org.openecomp.mso.properties.MsoPropertiesFactory; +import com.woorea.openstack.base.client.OpenStackBaseException; +import com.woorea.openstack.base.client.OpenStackConnectException; +import com.woorea.openstack.base.client.OpenStackRequest; +import com.woorea.openstack.base.client.OpenStackResponseException; +import com.woorea.openstack.keystone.Keystone; +import com.woorea.openstack.keystone.model.Access; +import com.woorea.openstack.keystone.model.Metadata; +import com.woorea.openstack.keystone.model.Role; +import com.woorea.openstack.keystone.model.Roles; +import com.woorea.openstack.keystone.model.Tenant; +import com.woorea.openstack.keystone.model.User; +import com.woorea.openstack.keystone.utils.KeystoneUtils; +import com.woorea.openstack.keystone.model.Authentication; + +public class MsoKeystoneUtils extends MsoTenantUtils { + + // Cache the Keystone Clients statically. Since there is just one MSO user, there is no + // benefit to re-authentication on every request (or across different flows). The + // token will be used until it expires. + // + // The cache key is "cloudId" + private static Map <String, KeystoneCacheEntry> adminClientCache = new HashMap <String, KeystoneCacheEntry> (); + + private static MsoLogger LOGGER = MsoLogger.getMsoLogger (MsoLogger.Catalog.RA); + String msoPropID; + + public MsoKeystoneUtils (String msoPropID) { + super(msoPropID); + this.msoPropID = msoPropID; + LOGGER.debug("MsoKeyStoneUtils:" + msoPropID); + } + + /** + * Create a tenant with the specified name in the given cloud. If the tenant already exists, + * an Exception will be thrown. The MSO User will also be added to the "member" list of + * the new tenant to perform subsequent Nova/Heat commands in the tenant. If the MSO User + * association fails, the entire transaction will be rolled back. + * <p> + * For the AIC Cloud (DCP/LCP): it is not clear that cloudId is needed, as all admin + * requests go to the centralized identity service in DCP. However, if some artifact + * must exist in each local LCP instance as well, then it will be needed to access the + * correct region. + * <p> + * + * @param tenantName The tenant name to create + * @param cloudId The cloud identifier (may be a region) in which to create the tenant. + * @return the tenant ID of the newly created tenant + * @throws MsoTenantAlreadyExists Thrown if the requested tenant already exists + * @throws MsoOpenstackException Thrown if the Openstack API call returns an exception + */ + public String createTenant (String tenantName, + String cloudSiteId, + Map <String, String> metadata, + boolean backout) throws MsoException { + // Obtain the cloud site information where we will create the tenant + CloudSite cloudSite = cloudConfig.getCloudSite (cloudSiteId); + if (cloudSite == null) { + LOGGER.error(MessageEnum.RA_CREATE_TENANT_ERR, "MSOCloudSite not found", "", "", MsoLogger.ErrorCode.DataError, "MSOCloudSite not found"); + throw new MsoCloudSiteNotFound (cloudSiteId); + } + Keystone keystoneAdminClient = getKeystoneAdminClient (cloudSite); + + Tenant tenant = null; + try { + // Check if the tenant already exists + tenant = findTenantByName (keystoneAdminClient, tenantName); + + if (tenant != null) { + // Tenant already exists. Throw an exception + LOGGER.error(MessageEnum.RA_TENANT_ALREADY_EXIST, tenantName, cloudSiteId, "", "", MsoLogger.ErrorCode.DataError, "Tenant already exists"); + throw new MsoTenantAlreadyExists (tenantName, cloudSiteId); + } + + // Does not exist, create a new one + tenant = new Tenant (); + tenant.setName (tenantName); + tenant.setDescription ("SDN Tenant (via MSO)"); + tenant.setEnabled (true); + + OpenStackRequest <Tenant> request = keystoneAdminClient.tenants ().create (tenant); + tenant = executeAndRecordOpenstackRequest (request, msoProps); + } catch (OpenStackBaseException e) { + // Convert Keystone OpenStackResponseException to MsoOpenstackException + throw keystoneErrorToMsoException (e, "CreateTenant"); + } catch (RuntimeException e) { + // Catch-all + throw runtimeExceptionToMsoException (e, "CreateTenant"); + } + + // Add MSO User to the tenant as a member and + // apply tenant metadata if supported by the cloud site + try { + CloudIdentity cloudIdentity = cloudSite.getIdentityService (); + + User msoUser = findUserByNameOrId (keystoneAdminClient, cloudIdentity.getMsoId ()); + Role memberRole = findRoleByNameOrId (keystoneAdminClient, cloudIdentity.getMemberRole ()); + + OpenStackRequest <Void> request = keystoneAdminClient.tenants ().addUser (tenant.getId (), + msoUser.getId (), + memberRole.getId ()); + executeAndRecordOpenstackRequest (request, msoProps); + + if (cloudIdentity.hasTenantMetadata () && metadata != null && !metadata.isEmpty ()) { + Metadata tenantMetadata = new Metadata (); + tenantMetadata.setMetadata (metadata); + + OpenStackRequest <Metadata> metaRequest = keystoneAdminClient.tenants () + .createOrUpdateMetadata (tenant.getId (), + tenantMetadata); + executeAndRecordOpenstackRequest (metaRequest, msoProps); + } + } catch (Exception e) { + // Failed to attach MSO User to the new tenant. Can't operate without access, + // so roll back the tenant. + if (!backout) + { + LOGGER.warn(MessageEnum.RA_CREATE_TENANT_ERR, "Create Tenant errored, Tenant deletion suppressed", "Openstack", "", MsoLogger.ErrorCode.DataError, "Create Tenant error, Tenant deletion suppressed"); + } + else + { + try { + OpenStackRequest <Void> request = keystoneAdminClient.tenants ().delete (tenant.getId ()); + executeAndRecordOpenstackRequest (request, msoProps); + } catch (Exception e2) { + // Just log this one. We will report the original exception. + LOGGER.error (MessageEnum.RA_CREATE_TENANT_ERR, "Nested exception rolling back tenant", "Openstack", "", MsoLogger.ErrorCode.DataError, "Create Tenant error, Nested exception rolling back tenant", e2); + } + } + + + // Propagate the original exception on user/role/tenant mapping + if (e instanceof OpenStackBaseException) { + // Convert Keystone Exception to MsoOpenstackException + throw keystoneErrorToMsoException ((OpenStackBaseException) e, "CreateTenantUser"); + } else { + MsoAdapterException me = new MsoAdapterException (e.getMessage (), e); + me.addContext ("CreateTenantUser"); + throw me; + } + } + return tenant.getId (); + } + + /** + * Query for a tenant by ID in the given cloud. If the tenant exists, + * return an MsoTenant object. If not, return null. + * <p> + * For the AIC Cloud (DCP/LCP): it is not clear that cloudId is needed, as all admin + * requests go to the centralized identity service in DCP. However, if some artifact + * must exist in each local LCP instance as well, then it will be needed to access the + * correct region. + * <p> + * + * @param tenantId The Openstack ID of the tenant to query + * @param cloudSiteId The cloud identifier (may be a region) in which to query the tenant. + * @return the tenant properties of the queried tenant, or null if not found + * @throws MsoOpenstackException Thrown if the Openstack API call returns an exception + */ + public MsoTenant queryTenant (String tenantId, String cloudSiteId) throws MsoException, MsoCloudSiteNotFound { + // Obtain the cloud site information where we will query the tenant + CloudSite cloudSite = cloudConfig.getCloudSite (cloudSiteId); + if (cloudSite == null) { + throw new MsoCloudSiteNotFound (cloudSiteId); + } + + Keystone keystoneAdminClient = getKeystoneAdminClient (cloudSite); + + // Check if the tenant exists and return its Tenant Id + try { + Tenant tenant = findTenantById (keystoneAdminClient, tenantId); + if (tenant == null) { + return null; + } + + Map <String, String> metadata = new HashMap <String, String> (); + if (cloudSite.getIdentityService ().hasTenantMetadata ()) { + OpenStackRequest <Metadata> request = keystoneAdminClient.tenants ().showMetadata (tenant.getId ()); + Metadata tenantMetadata = executeAndRecordOpenstackRequest (request, msoProps); + if (tenantMetadata != null) { + metadata = tenantMetadata.getMetadata (); + } + } + return new MsoTenant (tenant.getId (), tenant.getName (), metadata); + } catch (OpenStackBaseException e) { + // Convert Keystone OpenStackResponseException to MsoOpenstackException + throw keystoneErrorToMsoException (e, "QueryTenant"); + } catch (RuntimeException e) { + // Catch-all + throw runtimeExceptionToMsoException (e, "QueryTenant"); + } + } + + /** + * Query for a tenant with the specified name in the given cloud. If the tenant exists, + * return an MsoTenant object. If not, return null. This query is useful if the client + * knows it has the tenant name, skipping an initial lookup by ID that would always fail. + * <p> + * For the AIC Cloud (DCP/LCP): it is not clear that cloudId is needed, as all admin + * requests go to the centralized identity service in DCP. However, if some artifact + * must exist in each local LCP instance as well, then it will be needed to access the + * correct region. + * <p> + * + * @param tenantName The name of the tenant to query + * @param cloudSiteId The cloud identifier (may be a region) in which to query the tenant. + * @return the tenant properties of the queried tenant, or null if not found + * @throws MsoOpenstackException Thrown if the Openstack API call returns an exception + */ + public MsoTenant queryTenantByName (String tenantName, String cloudSiteId) throws MsoException { + // Obtain the cloud site information where we will query the tenant + CloudSite cloudSite = cloudConfig.getCloudSite (cloudSiteId); + if (cloudSite == null) { + throw new MsoCloudSiteNotFound (cloudSiteId); + } + Keystone keystoneAdminClient = getKeystoneAdminClient (cloudSite); + + try { + Tenant tenant = findTenantByName (keystoneAdminClient, tenantName); + if (tenant == null) { + return null; + } + + Map <String, String> metadata = new HashMap <String, String> (); + if (cloudSite.getIdentityService ().hasTenantMetadata ()) { + OpenStackRequest <Metadata> request = keystoneAdminClient.tenants ().showMetadata (tenant.getId ()); + Metadata tenantMetadata = executeAndRecordOpenstackRequest (request, msoProps); + if (tenantMetadata != null) { + metadata = tenantMetadata.getMetadata (); + } + } + return new MsoTenant (tenant.getId (), tenant.getName (), metadata); + } catch (OpenStackBaseException e) { + // Convert Keystone OpenStackResponseException to MsoOpenstackException + throw keystoneErrorToMsoException (e, "QueryTenantName"); + } catch (RuntimeException e) { + // Catch-all + throw runtimeExceptionToMsoException (e, "QueryTenantName"); + } + } + + /** + * Delete the specified Tenant (by ID) in the given cloud. This method returns true or + * false, depending on whether the tenant existed and was successfully deleted, or if + * the tenant already did not exist. Both cases are treated as success (no Exceptions). + * <p> + * Note for the AIC Cloud (DCP/LCP): all admin requests go to the centralized identity + * service in DCP. So deleting a tenant from one cloudSiteId will remove it from all + * sites managed by that identity service. + * <p> + * + * @param tenantId The Openstack ID of the tenant to delete + * @param cloudSiteId The cloud identifier from which to delete the tenant. + * @return true if the tenant was deleted, false if the tenant did not exist. + * @throws MsoOpenstackException If the Openstack API call returns an exception. + */ + public boolean deleteTenant (String tenantId, String cloudSiteId) throws MsoException { + // Obtain the cloud site information where we will query the tenant + CloudSite cloudSite = cloudConfig.getCloudSite (cloudSiteId); + if (cloudSite == null) { + throw new MsoCloudSiteNotFound (cloudSiteId); + } + Keystone keystoneAdminClient = getKeystoneAdminClient (cloudSite); + + try { + // Check that the tenant exists. Also, need the ID to delete + Tenant tenant = findTenantById (keystoneAdminClient, tenantId); + if (tenant == null) { + LOGGER.error(MessageEnum.RA_TENANT_NOT_FOUND, tenantId, cloudSiteId, "", "", MsoLogger.ErrorCode.DataError, "Tenant not found"); + return false; + } + + OpenStackRequest <Void> request = keystoneAdminClient.tenants ().delete (tenant.getId ()); + executeAndRecordOpenstackRequest (request, msoProps); + LOGGER.debug ("Deleted Tenant " + tenant.getId () + " (" + tenant.getName () + ")"); + + // Clear any cached clients. Not really needed, ID will not be reused. + MsoHeatUtils.expireHeatClient (tenant.getId (), cloudSiteId); + MsoNeutronUtils.expireNeutronClient (tenant.getId (), cloudSiteId); + } catch (OpenStackBaseException e) { + // Convert Keystone OpenStackResponseException to MsoOpenstackException + throw keystoneErrorToMsoException (e, "Delete Tenant"); + } catch (RuntimeException e) { + // Catch-all + throw runtimeExceptionToMsoException (e, "DeleteTenant"); + } + + return true; + } + + /** + * Delete the specified Tenant (by Name) in the given cloud. This method returns true or + * false, depending on whether the tenant existed and was successfully deleted, or if + * the tenant already did not exist. Both cases are treated as success (no Exceptions). + * <p> + * Note for the AIC Cloud (DCP/LCP): all admin requests go to the centralized identity + * service in DCP. So deleting a tenant from one cloudSiteId will remove it from all + * sites managed by that identity service. + * <p> + * + * @param tenantName The name of the tenant to delete + * @param cloudSiteId The cloud identifier from which to delete the tenant. + * @return true if the tenant was deleted, false if the tenant did not exist. + * @throws MsoOpenstackException If the Openstack API call returns an exception. + */ + public boolean deleteTenantByName (String tenantName, String cloudSiteId) throws MsoException { + // Obtain the cloud site information where we will query the tenant + CloudSite cloudSite = cloudConfig.getCloudSite (cloudSiteId); + if (cloudSite == null) { + throw new MsoCloudSiteNotFound (cloudSiteId); + } + Keystone keystoneAdminClient = getKeystoneAdminClient (cloudSite); + + try { + // Need the Tenant ID to delete (can't directly delete by name) + Tenant tenant = findTenantByName (keystoneAdminClient, tenantName); + if (tenant == null) { + // OK if tenant already doesn't exist. + LOGGER.error(MessageEnum.RA_TENANT_NOT_FOUND, tenantName, cloudSiteId, "", "", MsoLogger.ErrorCode.DataError, "Tenant not found"); + return false; + } + + // Execute the Delete. It has no return value. + OpenStackRequest <Void> request = keystoneAdminClient.tenants ().delete (tenant.getId ()); + executeAndRecordOpenstackRequest (request, msoProps); + + LOGGER.debug ("Deleted Tenant " + tenant.getId () + " (" + tenant.getName () + ")"); + + // Clear any cached clients. Not really needed, ID will not be reused. + MsoHeatUtils.expireHeatClient (tenant.getId (), cloudSiteId); + MsoNeutronUtils.expireNeutronClient (tenant.getId (), cloudSiteId); + } catch (OpenStackBaseException e) { + // Note: It doesn't seem to matter if tenant doesn't exist, no exception is thrown. + // Convert Keystone OpenStackResponseException to MsoOpenstackException + throw keystoneErrorToMsoException (e, "DeleteTenant"); + } catch (RuntimeException e) { + // Catch-all + throw runtimeExceptionToMsoException (e, "DeleteTenant"); + } + + return true; + } + + // ------------------------------------------------------------------- + // PRIVATE UTILITY FUNCTIONS FOR USE WITHIN THIS CLASS + + /* + * Get a Keystone Admin client for the Openstack Identity service. + * This requires an 'admin'-level userId + password along with an 'admin' tenant + * in the target cloud. These values will be retrieved from properties based + * on the specified cloud ID. + * <p> + * On successful authentication, the Keystone object will be cached for the cloudId + * so that it can be reused without going back to Openstack every time. + * + * @param cloudId + * + * @return an authenticated Keystone object + */ + public Keystone getKeystoneAdminClient (CloudSite cloudSite) throws MsoException { + CloudIdentity cloudIdentity = cloudSite.getIdentityService (); + + String cloudId = cloudIdentity.getId (); + String adminTenantName = cloudIdentity.getAdminTenant (); + String region = cloudSite.getRegionId (); + + // Check first in the cache of previously authorized clients + KeystoneCacheEntry entry = adminClientCache.get (cloudId); + if (entry != null) { + if (!entry.isExpired ()) { + return entry.getKeystoneClient (); + } else { + // Token is expired. Remove it from cache. + adminClientCache.remove (cloudId); + } + } + + Keystone keystone = new Keystone (cloudIdentity.getKeystoneUrl (region, msoPropID)); + + // Must authenticate against the 'admin' tenant to get the services endpoints + Access access = null; + String token = null; + try { + Authentication credentials = cloudIdentity.getAuthentication (); + OpenStackRequest <Access> request = keystone.tokens () + .authenticate (credentials) + .withTenantName (adminTenantName); + access = executeAndRecordOpenstackRequest (request, msoProps); + token = access.getToken ().getId (); + } catch (OpenStackResponseException e) { + if (e.getStatus () == 401) { + // Authentication error. Can't access admin tenant - something is mis-configured + String error = "MSO Authentication Failed for " + cloudIdentity.getId (); + alarmLogger.sendAlarm ("MsoAuthenticationError", MsoAlarmLogger.CRITICAL, error); + throw new MsoAdapterException (error); + } else { + throw keystoneErrorToMsoException (e, "TokenAuth"); + } + } catch (OpenStackConnectException e) { + // Connection to Openstack failed + throw keystoneErrorToMsoException (e, "TokenAuth"); + } + + // 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"); + } catch (RuntimeException e) { + String error = "Identity service not found: region=" + region + ",cloud=" + cloudIdentity.getId (); + alarmLogger.sendAlarm ("MsoConfigurationError", MsoAlarmLogger.CRITICAL, error); + LOGGER.error(MessageEnum.IDENTITY_SERVICE_NOT_FOUND, region, cloudIdentity.getId(), "Openstack", "", MsoLogger.ErrorCode.DataError, "Exception in findEndpointURL"); + throw new MsoAdapterException (error, e); + } + // The following is needed for the MT lab. + if ("MT".equals (cloudSite.getId ())) { + adminUrl = adminUrl.replace ("controller", "mtdnj02bh01wt.bvoip.labs.att.com"); + } + + // A new Keystone object is required for the new URL. Use the auth token from above. + // Note: this doesn't go back to Openstack, it's just a local object. + keystone = new Keystone (adminUrl); + keystone.token (token); + + // Cache to avoid re-authentication for every call. + KeystoneCacheEntry cacheEntry = new KeystoneCacheEntry (adminUrl, token, access.getToken ().getExpires ()); + adminClientCache.put (cloudId, cacheEntry); + + return keystone; + } + + /* + * Find a tenant (or query its existance) by its Name or Id. Check first against the + * ID. If that fails, then try by name. + * + * @param adminClient an authenticated Keystone object + * + * @param tenantName the tenant name or ID to query + * + * @return a Tenant object or null if not found + */ + public Tenant findTenantByNameOrId (Keystone adminClient, String tenantNameOrId) { + if (tenantNameOrId == null) { + return null; + } + + Tenant tenant = findTenantById (adminClient, tenantNameOrId); + if (tenant == null) { + tenant = findTenantByName (adminClient, tenantNameOrId); + } + + return tenant; + } + + /* + * Find a tenant (or query its existance) by its Id. + * + * @param adminClient an authenticated Keystone object + * + * @param tenantName the tenant ID to query + * + * @return a Tenant object or null if not found + */ + private Tenant findTenantById (Keystone adminClient, String tenantId) { + if (tenantId == null) { + return null; + } + + try { + OpenStackRequest <Tenant> request = adminClient.tenants ().show (tenantId); + return executeAndRecordOpenstackRequest (request, msoProps); + } catch (OpenStackResponseException e) { + if (e.getStatus () == 404) { + return null; + } else { + LOGGER.error(MessageEnum.RA_CONNECTION_EXCEPTION, "Openstack Error, GET Tenant by Id (" + tenantId + "): " + e, "Openstack", "", MsoLogger.ErrorCode.DataError, "Exception in Openstack GET tenant by Id"); + throw e; + } + } + } + + /* + * Find a tenant (or query its existance) by its Name. This method avoids an + * initial lookup by ID when it's known that we have the tenant Name. + * + * @param adminClient an authenticated Keystone object + * + * @param tenantName the tenant name to query + * + * @return a Tenant object or null if not found + */ + public Tenant findTenantByName (Keystone adminClient, String tenantName) { + if (tenantName == null) { + return null; + } + + try { + OpenStackRequest <Tenant> request = adminClient.tenants ().show ("").queryParam ("name", tenantName); + return executeAndRecordOpenstackRequest (request, msoProps); + } catch (OpenStackResponseException e) { + if (e.getStatus () == 404) { + return null; + } else { + LOGGER.error (MessageEnum.RA_CONNECTION_EXCEPTION, "Openstack Error, GET Tenant By Name (" + tenantName + "): " + e, "Openstack", "", MsoLogger.ErrorCode.DataError, "Exception in Openstack GET Tenant By Name"); + throw e; + } + } + } + + /* + * Look up an Openstack User by Name or Openstack ID. Check the ID first, and if that + * fails, try the Name. + * + * @param adminClient an authenticated Keystone object + * + * @param userName the user name or ID to query + * + * @return a User object or null if not found + */ + private User findUserByNameOrId (Keystone adminClient, String userNameOrId) { + if (userNameOrId == null) { + return null; + } + + try { + OpenStackRequest <User> request = adminClient.users ().show (userNameOrId); + return executeAndRecordOpenstackRequest (request, msoProps); + } catch (OpenStackResponseException e) { + if (e.getStatus () == 404) { + // Not found by ID. Search for name + return findUserByName (adminClient, userNameOrId); + } else { + LOGGER.error (MessageEnum.RA_CONNECTION_EXCEPTION, "Openstack Error, GET User (" + userNameOrId + "): " + e, "Openstack", "", MsoLogger.ErrorCode.DataError, "Exception in Openstack GET User"); + throw e; + } + } + } + + /* + * Look up an Openstack User by Name. This avoids initial Openstack query by ID + * if we know we have the User Name. + * + * @param adminClient an authenticated Keystone object + * + * @param userName the user name to query + * + * @return a User object or null if not found + */ + public User findUserByName (Keystone adminClient, String userName) { + if (userName == null) { + return null; + } + + try { + OpenStackRequest <User> request = adminClient.users ().show ("").queryParam ("name", userName); + return executeAndRecordOpenstackRequest (request, msoProps); + } catch (OpenStackResponseException e) { + if (e.getStatus () == 404) { + return null; + } else { + LOGGER.error (MessageEnum.RA_CONNECTION_EXCEPTION, "Openstack Error, GET User By Name (" + userName + "): " + e, "Openstack", "", MsoLogger.ErrorCode.DataError, "Exception in Openstack GET User By Name"); + throw e; + } + } + } + + /* + * Look up an Openstack Role by Name or Id. There is no direct query for Roles, so + * need to retrieve a full list from Openstack and look for a match. By default, + * Openstack should have a "_member_" role for normal VM-level privileges and an + * "admin" role for expanded privileges (e.g. administer tenants, users, and roles). + * <p> + * + * @param adminClient an authenticated Keystone object + * + * @param roleNameOrId the Role name or ID to look up + * + * @return a Role object + */ + private Role findRoleByNameOrId (Keystone adminClient, String roleNameOrId) { + if (roleNameOrId == null) { + return null; + } + + // Search by name or ID. Must search in list + OpenStackRequest <Roles> request = adminClient.roles ().list (); + Roles roles = executeAndRecordOpenstackRequest (request, msoProps); + + for (Role role : roles) { + if (roleNameOrId.equals (role.getName ()) || roleNameOrId.equals (role.getId ())) { + return role; + } + } + + return null; + } + + private static class KeystoneCacheEntry implements Serializable { + + private static final long serialVersionUID = 1L; + + private String keystoneUrl; + private String token; + private Calendar expires; + + public KeystoneCacheEntry (String url, String token, Calendar expires) { + this.keystoneUrl = url; + this.token = token; + this.expires = expires; + } + + public Keystone getKeystoneClient () { + Keystone keystone = new Keystone (keystoneUrl); + keystone.token (token); + return keystone; + } + + public boolean isExpired () { + return Calendar.getInstance ().after (expires); + } + } + + /** + * Clean up the Admin client cache to remove expired entries. + */ + public static void adminCacheCleanup () { + for (String cacheKey : adminClientCache.keySet ()) { + if (adminClientCache.get (cacheKey).isExpired ()) { + adminClientCache.remove (cacheKey); + LOGGER.debug ("Cleaned Up Cached Admin Client for " + cacheKey); + } + } + } + + /** + * Reset the Admin client cache. + * This may be useful if cached credentials get out of sync. + */ + public static void adminCacheReset () { + adminClientCache = new HashMap <String, KeystoneCacheEntry> (); + } +} diff --git a/adapters/mso-adapter-utils/src/main/java/org/openecomp/mso/openstack/utils/MsoNeutronUtils.java b/adapters/mso-adapter-utils/src/main/java/org/openecomp/mso/openstack/utils/MsoNeutronUtils.java new file mode 100644 index 0000000000..7e388a5ef8 --- /dev/null +++ b/adapters/mso-adapter-utils/src/main/java/org/openecomp/mso/openstack/utils/MsoNeutronUtils.java @@ -0,0 +1,616 @@ +/*- + * ============LICENSE_START======================================================= + * OPENECOMP - MSO + * ================================================================================ + * 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.utils; + + +import java.io.Serializable; +import java.util.ArrayList; +import java.util.Calendar; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +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 org.openecomp.mso.logger.MessageEnum; +import org.openecomp.mso.logger.MsoAlarmLogger; +import org.openecomp.mso.logger.MsoLogger; +import org.openecomp.mso.openstack.beans.NetworkInfo; +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.MsoIOException; +import org.openecomp.mso.openstack.exceptions.MsoNetworkAlreadyExists; +import org.openecomp.mso.openstack.exceptions.MsoNetworkNotFound; +import org.openecomp.mso.openstack.exceptions.MsoOpenstackException; +import org.openecomp.mso.openstack.exceptions.MsoTenantNotFound; +import com.woorea.openstack.base.client.OpenStackBaseException; +import com.woorea.openstack.base.client.OpenStackConnectException; +import com.woorea.openstack.base.client.OpenStackRequest; +import com.woorea.openstack.base.client.OpenStackResponseException; +import com.woorea.openstack.keystone.Keystone; +import com.woorea.openstack.keystone.model.Access; +import com.woorea.openstack.keystone.utils.KeystoneUtils; +import com.woorea.openstack.quantum.Quantum; +import com.woorea.openstack.quantum.model.Network; +import com.woorea.openstack.quantum.model.Networks; +import com.woorea.openstack.quantum.model.Segment; +import com.woorea.openstack.keystone.model.Authentication; + +public class MsoNeutronUtils extends MsoCommonUtils +{ + // Cache Neutron Clients statically. Since there is just one MSO user, there is no + // benefit to re-authentication on every request (or across different flows). The + // token will be used until it expires. + // + // The cache key is "tenantId:cloudId" + private static Map<String,NeutronCacheEntry> neutronClientCache = new HashMap<String,NeutronCacheEntry>(); + + // Fetch cloud configuration each time (may be cached in CloudConfig class) + private CloudConfig cloudConfig; + + private static MsoLogger LOGGER = MsoLogger.getMsoLogger (MsoLogger.Catalog.RA); + private String msoPropID; + + public enum NetworkType { + BASIC, PROVIDER, MULTI_PROVIDER + }; + + public MsoNeutronUtils(String msoPropID, CloudConfigFactory cloudConfigFactory) { + cloudConfig = cloudConfigFactory.getCloudConfig(); + this.msoPropID = msoPropID; + } + + /** + * Create a network with the specified parameters in the given cloud/tenant. + * + * If a network already exists with the same name, an exception will be thrown. Note that + * this is an MSO-imposed restriction. Openstack does not require uniqueness on network names. + * <p> + * @param cloudSiteId The cloud identifier (may be a region) in which to create the network. + * @param tenantId The tenant in which to create the network + * @param type The type of network to create (Basic, Provider, Multi-Provider) + * @param networkName The network name to create + * @param provider The provider network name (for Provider or Multi-Provider networks) + * @param vlans A list of VLAN segments for the network (for Provider or Multi-Provider networks) + * @return a NetworkInfo object which describes the newly created network + * @throws MsoNetworkAlreadyExists Thrown if a network with the same name already exists + * @throws MsoOpenstackException Thrown if the Openstack API call returns an exception + * @throws MsoCloudSiteNotFound Thrown if the cloudSite is invalid or unknown + */ + public NetworkInfo createNetwork (String cloudSiteId, String tenantId, NetworkType type, String networkName, String provider, List<Integer> vlans) + throws MsoException, MsoNetworkAlreadyExists, MsoCloudSiteNotFound + { + // Obtain the cloud site information where we will create the stack + CloudSite cloudSite = cloudConfig.getCloudSite(cloudSiteId); + if (cloudSite == null) { + throw new MsoCloudSiteNotFound(cloudSiteId); + } + + Quantum neutronClient = getNeutronClient (cloudSite, tenantId); + + // Check if a network already exists with this name + // Openstack will allow duplicate name, so require explicit check + Network network = findNetworkByName (neutronClient, networkName); + + if (network != null) { + // Network already exists. Throw an exception + LOGGER.error(MessageEnum.RA_NETWORK_ALREADY_EXIST, networkName, cloudSiteId, tenantId, "Openstack", "", MsoLogger.ErrorCode.DataError, "Network already exists"); + throw new MsoNetworkAlreadyExists (networkName, tenantId, cloudSiteId); + } + + // Does not exist, create a new one + network = new Network(); + network.setName(networkName); + network.setAdminStateUp(true); + + if (type == NetworkType.PROVIDER) { + if (provider != null && vlans != null && vlans.size() > 0) { + network.setProviderPhysicalNetwork (provider); + network.setProviderNetworkType("vlan"); + network.setProviderSegmentationId (vlans.get(0)); + } + } else if (type == NetworkType.MULTI_PROVIDER) { + if (provider != null && vlans != null && vlans.size() > 0) { + List<Segment> segments = new ArrayList<Segment>(vlans.size()); + for (int vlan : vlans) { + Segment segment = new Segment(); + segment.setProviderPhysicalNetwork (provider); + segment.setProviderNetworkType("vlan"); + segment.setProviderSegmentationId (vlan); + + segments.add(segment); + } + network.setSegments(segments); + } + } + + try { + OpenStackRequest<Network> request = neutronClient.networks().create(network); + Network newNetwork = executeAndRecordOpenstackRequest(request); + return new NetworkInfo(newNetwork); + } + catch (OpenStackBaseException e) { + // Convert Neutron exception to an MsoOpenstackException + MsoException me = neutronExceptionToMsoException (e, "CreateNetwork"); + throw me; + } + catch (RuntimeException e) { + // Catch-all + MsoException me = runtimeExceptionToMsoException(e, "CreateNetwork"); + throw me; + } + } + + + /** + * Query for a network with the specified name or ID in the given cloud. If the network exists, + * return an NetworkInfo object. If not, return null. + * <p> + * Whenever possible, the network ID should be used as it is much more efficient. Query by + * name requires retrieval of all networks for the tenant and search for matching name. + * <p> + * @param networkNameOrId The network to query + * @param tenantId The Openstack tenant to look in for the network + * @param cloudSiteId The cloud identifier (may be a region) in which to query the network. + * @return a NetworkInfo object describing the queried network, or null if not found + * @throws MsoOpenstackException Thrown if the Openstack API call returns an exception + * @throws MsoCloudSiteNotFound + */ + public NetworkInfo queryNetwork (String networkNameOrId, String tenantId, String cloudSiteId) + throws MsoException, MsoCloudSiteNotFound + { + LOGGER.debug("In queryNetwork"); + + // Obtain the cloud site information + CloudSite cloudSite = cloudConfig.getCloudSite(cloudSiteId); + if (cloudSite == null) { + throw new MsoCloudSiteNotFound(cloudSiteId); + } + + Quantum neutronClient = getNeutronClient (cloudSite, tenantId); + + // Check if the network exists and return its info + try { + Network network = findNetworkByNameOrId (neutronClient, networkNameOrId); + if (network == null) { + LOGGER.debug ("Query Network: " + networkNameOrId + " not found in tenant " + tenantId); + return null; + } + return new NetworkInfo(network); + } + catch (OpenStackBaseException e) { + // Convert Neutron exception to an MsoOpenstackException + MsoException me = neutronExceptionToMsoException (e, "QueryNetwork"); + throw me; + } + catch (RuntimeException e) { + // Catch-all + MsoException me = runtimeExceptionToMsoException(e, "QueryNetwork"); + throw me; + } + } + + /** + * Delete the specified Network (by ID) in the given cloud. + * If the network does not exist, success is returned. + * <p> + * @param networkNameOrId The name or Openstack ID of the network to delete + * @param cloudId The cloud identifier (may be a region) from which to delete the network. + * @return true if the network was deleted, false if the network did not exist + * @throws MsoOpenstackException If the Openstack API call returns an exception, this local + * exception will be thrown. + * @throws MsoCloudSiteNotFound + */ + public boolean deleteNetwork (String networkId, String tenantId, String cloudSiteId) + throws MsoException, MsoCloudSiteNotFound + { + // Obtain the cloud site information where we will create the stack + CloudSite cloudSite = cloudConfig.getCloudSite(cloudSiteId); + if (cloudSite == null) { + throw new MsoCloudSiteNotFound(cloudSiteId); + } + + Quantum neutronClient = getNeutronClient (cloudSite, tenantId); + + try { + // Check that the network exists. + Network network = findNetworkById (neutronClient, networkId); + if (network == null) { + LOGGER.info(MessageEnum.RA_DELETE_NETWORK_EXC, networkId, cloudSiteId, tenantId, "Openstack", ""); + return false; + } + + OpenStackRequest<Void> request = neutronClient.networks().delete(network.getId()); + executeAndRecordOpenstackRequest(request); + + LOGGER.debug ("Deleted Network " + network.getId() + " (" + network.getName() + ")"); + } + catch (OpenStackBaseException e) { + // Convert Neutron exception to an MsoOpenstackException + MsoException me = neutronExceptionToMsoException (e, "Delete Network"); + throw me; + } + catch (RuntimeException e) { + // Catch-all + MsoException me = runtimeExceptionToMsoException(e, "DeleteNetwork"); + throw me; + } + + return true; + } + + + /** + * Update a network with the specified parameters in the given cloud/tenant. + * + * Specifically, this call is intended to update the VLAN segments on a + * multi-provider network. The provider segments will be replaced with the + * supplied list of VLANs. + * <p> + * Note that updating the 'segments' array is not normally supported by Neutron. + * This method relies on a Platform Orchestration extension (using SDN controller + * to manage the virtual networking). + * + * @param cloudSiteId The cloud site ID (may be a region) in which to update the network. + * @param the Openstack ID of the tenant in which to update the network + * @param networkId The unique Openstack ID of the network to be updated + * @param type The network type (Basic, Provider, Multi-Provider) + * @param provider The provider network name. This should not change. + * @param vlans The list of VLAN segments to replace + * @return a NetworkInfo object which describes the updated network + * @throws MsoNetworkNotFound Thrown if the requested network does not exist + * @throws MsoOpenstackException Thrown if the Openstack API call returns an exception + * @throws MsoCloudSiteNotFound + */ + public NetworkInfo updateNetwork (String cloudSiteId, String tenantId, String networkId, NetworkType type, String provider, List<Integer> vlans) + throws MsoException, MsoNetworkNotFound, MsoCloudSiteNotFound + { + // Obtain the cloud site information where we will create the stack + CloudSite cloudSite = cloudConfig.getCloudSite(cloudSiteId); + if (cloudSite == null) { + throw new MsoCloudSiteNotFound(cloudSiteId); + } + Quantum neutronClient = getNeutronClient (cloudSite, tenantId); + + // Check that the network exists + Network network = findNetworkById (neutronClient, networkId); + + if (network == null) { + // Network not found. Throw an exception + LOGGER.error(MessageEnum.RA_NETWORK_NOT_FOUND, networkId, cloudSiteId, tenantId, "Openstack", "", MsoLogger.ErrorCode.DataError, "Network not found"); + throw new MsoNetworkNotFound (networkId, tenantId, cloudSiteId); + } + + // Overwrite the properties to be updated + if (type == NetworkType.PROVIDER) { + if (provider != null && vlans != null && vlans.size() > 0) { + network.setProviderPhysicalNetwork (provider); + network.setProviderNetworkType("vlan"); + network.setProviderSegmentationId (vlans.get(0)); + } + } else if (type == NetworkType.MULTI_PROVIDER) { + if (provider != null && vlans != null && vlans.size() > 0) { + List<Segment> segments = new ArrayList<Segment>(vlans.size()); + for (int vlan : vlans) { + Segment segment = new Segment(); + segment.setProviderPhysicalNetwork (provider); + segment.setProviderNetworkType("vlan"); + segment.setProviderSegmentationId (vlan); + + segments.add(segment); + } + network.setSegments(segments); + } + } + + try { + OpenStackRequest<Network> request = neutronClient.networks().update(network); + Network newNetwork = executeAndRecordOpenstackRequest(request); + return new NetworkInfo(newNetwork); + } + catch (OpenStackBaseException e) { + // Convert Neutron exception to an MsoOpenstackException + MsoException me = neutronExceptionToMsoException (e, "UpdateNetwork"); + throw me; + } + catch (RuntimeException e) { + // Catch-all + MsoException me = runtimeExceptionToMsoException(e, "UpdateNetwork"); + throw me; + } + } + + + // ------------------------------------------------------------------- + // PRIVATE UTILITY FUNCTIONS FOR USE WITHIN THIS CLASS + + /** + * Get a Neutron (Quantum) client for the Openstack Network service. + * This requires a 'member'-level userId + password, which will be retrieved from + * properties based on the specified cloud Id. The tenant in which to operate + * must also be provided. + * <p> + * On successful authentication, the Quantum object will be cached for the + * tenantID + cloudId so that it can be reused without reauthenticating with + * Openstack every time. + * + * @param cloudSite - a cloud site definition + * @param tenantId - Openstack tenant ID + * @return an authenticated Quantum object + */ + private Quantum getNeutronClient (CloudSite cloudSite, String tenantId) + throws MsoTenantNotFound, MsoException + { + String cloudId = cloudSite.getId(); + + // Check first in the cache of previously authorized clients + String cacheKey = cloudId + ":" + tenantId; + if (neutronClientCache.containsKey(cacheKey)) { + if (! neutronClientCache.get(cacheKey).isExpired()) { + LOGGER.debug ("Using Cached HEAT Client for " + cacheKey); + Quantum neutronClient = neutronClientCache.get(cacheKey).getNeutronClient(); + return neutronClient; + } + else { + // Token is expired. Remove it from cache. + neutronClientCache.remove(cacheKey); + LOGGER.debug ("Expired Cached Neutron Client for " + cacheKey); + } + } + + // Obtain an MSO token for the tenant from the identity service + CloudIdentity cloudIdentity = cloudSite.getIdentityService(); + Keystone keystoneTenantClient = new Keystone (cloudIdentity.getKeystoneUrl(cloudId, msoPropID)); + Access access = null; + try { + Authentication credentials = cloudIdentity.getAuthentication (); + OpenStackRequest<Access> request = keystoneTenantClient.tokens().authenticate(credentials).withTenantId(tenantId); + access = executeAndRecordOpenstackRequest(request); + } + catch (OpenStackResponseException e) { + if (e.getStatus() == 401) { + // Authentication error. + String error = "Authentication Failure: tenant=" + tenantId + ",cloud=" + cloudIdentity.getId(); + alarmLogger .sendAlarm("MsoAuthenticationError", MsoAlarmLogger.CRITICAL, error); + throw new MsoAdapterException(error); + } + else { + MsoException me = keystoneErrorToMsoException(e, "TokenAuth"); + throw me; + } + } + catch (OpenStackConnectException e) { + // Connection to Openstack failed + MsoIOException me = new MsoIOException (e.getMessage(), e); + me.addContext("TokenAuth"); + throw me; + } + catch (RuntimeException e) { + // Catch-all + MsoException me = runtimeExceptionToMsoException(e, "TokenAuth"); + throw me; + } + + String region = cloudSite.getRegionId(); + String neutronUrl = null; + try { + neutronUrl = KeystoneUtils.findEndpointURL(access.getServiceCatalog(), "network", region, "public"); + if (! neutronUrl.endsWith("/")) { + neutronUrl += "/v2.0/"; + } + } catch (RuntimeException e) { + // This comes back for not found (probably an incorrect region ID) + String error = "Network service not found: region=" + region + ",cloud=" + cloudIdentity.getId(); + alarmLogger.sendAlarm("MsoConfigurationError", MsoAlarmLogger.CRITICAL, error); + throw new MsoAdapterException (error, e); + } + // This is needed for testing in the MT cloud + if (cloudId.equals("MT")) { + neutronUrl = neutronUrl.replace("controller", "mtdnj02bh01wt.bvoip.labs.att.com"); + } + + Quantum neutronClient = new Quantum(neutronUrl); + neutronClient.token(access.getToken().getId()); + + neutronClientCache.put(cacheKey, new NeutronCacheEntry(neutronUrl, access.getToken().getId(), access.getToken().getExpires())); + LOGGER.debug ("Caching Neutron Client for " + cacheKey); + + return neutronClient; + } + + /** + * Forcibly expire a Neutron client from the cache. This call is for use by + * the KeystoneClient in case where a tenant is deleted. In that case, + * all cached credentials must be purged so that fresh authentication is + * done on subsequent calls. + * <p> + * @param tenantName + * @param cloudId + */ + public static void expireNeutronClient (String tenantId, String cloudId) { + String cacheKey = cloudId + ":" + tenantId; + if (neutronClientCache.containsKey(cacheKey)) { + neutronClientCache.remove(cacheKey); + LOGGER.debug ("Deleted Cached Neutron Client for " + cacheKey); + } + } + + + /* + * Find a tenant (or query its existence) by its Name or Id. Check first against the + * ID. If that fails, then try by name. + * + * @param adminClient an authenticated Keystone object + * @param tenantName the tenant name or ID to query + * @return a Tenant object or null if not found + */ + public Network findNetworkByNameOrId (Quantum neutronClient, String networkNameOrId) + { + if (networkNameOrId == null) { + return null; + } + + Network network = findNetworkById(neutronClient, networkNameOrId); + + if (network == null) { + network = findNetworkByName(neutronClient, networkNameOrId); + } + + return network; + } + + /* + * Find a network (or query its existence) by its Id. + * + * @param neutronClient an authenticated Quantum object + * @param networkId the network ID to query + * @return a Network object or null if not found + */ + private static Network findNetworkById (Quantum neutronClient, String networkId) + { + if (networkId == null) { + return null; + } + + try { + OpenStackRequest<Network> request = neutronClient.networks().show(networkId); + Network network = executeAndRecordOpenstackRequest(request); + return network; + } + catch (OpenStackResponseException e) { + if (e.getStatus() == 404) { + return null; + } else { + LOGGER.error (MessageEnum.RA_CONNECTION_EXCEPTION, "OpenStack", "Openstack Error, GET Network By ID (" + networkId + "): " + e, "Openstack", "", MsoLogger.ErrorCode.DataError, "Exception in Openstack"); + throw e; + } + } + } + + /* + * Find a network (or query its existence) by its Name. This method avoids an + * initial lookup by ID when it's known that we have the network Name. + * + * Neutron does not support 'name=*' query parameter for Network query (show). + * The only way to query by name is to retrieve all networks and look for the + * match. While inefficient, this capability will be provided as it is needed + * by MSO, but should be avoided in favor of ID whenever possible. + * + * TODO: + * Network names are not required to be unique, though MSO will attempt to enforce + * uniqueness. This call probably needs to return an error (instead of returning + * the first match). + * + * @param neutronClient an authenticated Quantum object + * @param networkName the network name to query + * @return a Network object or null if not found + */ + public Network findNetworkByName (Quantum neutronClient, String networkName) + { + if (networkName == null) { + return null; + } + + try { + OpenStackRequest<Networks> request = neutronClient.networks().list(); + Networks networks = executeAndRecordOpenstackRequest(request); + for (Network network : networks.getList()) { + if (network.getName().equals(networkName)) { + LOGGER.debug ("Found match on network name: " + networkName); + return network; + } + } + LOGGER.debug ("findNetworkByName - no match found for " + networkName); + return null; + } + catch (OpenStackResponseException e) { + if (e.getStatus() == 404) { + return null; + } else { + LOGGER.error (MessageEnum.RA_CONNECTION_EXCEPTION, "OpenStack", "Openstack Error, GET Network By Name (" + networkName + "): " + e, "OpenStack", "", MsoLogger.ErrorCode.DataError, "Exception in OpenStack"); + throw e; + } + } + } + + + /* + * An entry in the Neutron Client Cache. It saves the Neutron client object + * along with the token expiration. After this interval, this cache + * item will no longer be used. + */ + private static class NeutronCacheEntry implements Serializable + { + private static final long serialVersionUID = 1L; + + private String neutronUrl; + private String token; + private Calendar expires; + + public NeutronCacheEntry (String neutronUrl, String token, Calendar expires) { + this.neutronUrl = neutronUrl; + this.token = token; + this.expires = expires; + } + + public Quantum getNeutronClient () { + Quantum neutronClient = new Quantum(neutronUrl); + neutronClient.token(token); + return neutronClient; + } + + public boolean isExpired() { + if (expires == null) { + return true; + } + + Calendar now = Calendar.getInstance(); + if (now.after(expires)) { + return true; + } + + return false; + } + } + + /** + * Clean up the Neutron client cache to remove expired entries. + */ + public static void neutronCacheCleanup () { + for (String cacheKey : neutronClientCache.keySet()) { + if (neutronClientCache.get(cacheKey).isExpired()) { + neutronClientCache.remove(cacheKey); + LOGGER.debug ("Cleaned Up Cached Neutron Client for " + cacheKey); + } + } + } + + /** + * Reset the Neutron client cache. + * This may be useful if cached credentials get out of sync. + */ + public static void neutronCacheReset () { + neutronClientCache = new HashMap<String,NeutronCacheEntry>(); + } +} diff --git a/adapters/mso-adapter-utils/src/main/java/org/openecomp/mso/openstack/utils/MsoTenantUtils.java b/adapters/mso-adapter-utils/src/main/java/org/openecomp/mso/openstack/utils/MsoTenantUtils.java new file mode 100644 index 0000000000..41104707cb --- /dev/null +++ b/adapters/mso-adapter-utils/src/main/java/org/openecomp/mso/openstack/utils/MsoTenantUtils.java @@ -0,0 +1,79 @@ +/*- + * ============LICENSE_START======================================================= + * OPENECOMP - MSO + * ================================================================================ + * 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.utils; + + +import java.io.Serializable; +import java.util.Calendar; +import java.util.HashMap; +import java.util.Map; + +import org.openecomp.mso.cloud.CloudConfig; +import org.openecomp.mso.cloud.CloudConfigFactory; +import org.openecomp.mso.logger.MsoAlarmLogger; +import org.openecomp.mso.logger.MsoLogger; +import org.openecomp.mso.logger.MessageEnum; +import org.openecomp.mso.openstack.beans.MsoTenant; +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.MsoOpenstackException; +import org.openecomp.mso.openstack.exceptions.MsoTenantAlreadyExists; +import org.openecomp.mso.properties.MsoJavaProperties; +import org.openecomp.mso.properties.MsoPropertiesException; +import org.openecomp.mso.properties.MsoPropertiesFactory; +import com.woorea.openstack.keystone.Keystone; + +public abstract class MsoTenantUtils extends MsoCommonUtils { + + protected CloudConfigFactory cloudConfigFactory; + protected MsoPropertiesFactory msoPropFactory; + protected static MsoLogger LOGGER = MsoLogger.getMsoLogger (MsoLogger.Catalog.RA); + protected MsoJavaProperties msoProps; + protected CloudConfig cloudConfig; + + public MsoTenantUtils (String msoPropID) { + cloudConfigFactory = new CloudConfigFactory(); + msoPropFactory = new MsoPropertiesFactory(); + cloudConfig = cloudConfigFactory.getCloudConfig (); + + LOGGER.debug("msoTenantUtils:" + msoPropID); + + try { + msoProps = msoPropFactory.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); + } + } + + public abstract String createTenant (String tenantName, String cloudSiteId, Map <String, String> metadata, boolean backout) + throws MsoException; + + public abstract MsoTenant queryTenant (String tenantId, String cloudSiteId) + throws MsoException, MsoCloudSiteNotFound; + + public abstract MsoTenant queryTenantByName (String tenantName, String cloudSiteId) + throws MsoException, MsoCloudSiteNotFound; + + public abstract boolean deleteTenant (String tenantId, String cloudSiteId) + throws MsoException; + +} 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 new file mode 100644 index 0000000000..6fd7a6364a --- /dev/null +++ b/adapters/mso-adapter-utils/src/main/java/org/openecomp/mso/openstack/utils/MsoTenantUtilsFactory.java @@ -0,0 +1,58 @@ +/*- + * ============LICENSE_START======================================================= + * OPENECOMP - MSO + * ================================================================================ + * 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.utils; + +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 org.openecomp.mso.logger.MsoLogger; +import org.openecomp.mso.properties.MsoJavaProperties; +import org.openecomp.mso.openstack.utils.MsoKeystoneUtils; + + +public class MsoTenantUtilsFactory { + + private static MsoLogger LOGGER = MsoLogger.getMsoLogger (MsoLogger.Catalog.RA); + private CloudConfigFactory cloudConfigFactory= new CloudConfigFactory(); + protected CloudConfig cloudConfig; + protected MsoJavaProperties msoProps = null; + private String msoPropID; + + public MsoTenantUtilsFactory (String msoPropID) { + this.msoPropID = msoPropID; + } + + //based on Cloud IdentityServerType returns ORM or KEYSTONE Utils + public MsoTenantUtils getTenantUtils(String cloudSiteId) { + + // Obtain the cloud site information + cloudConfig = cloudConfigFactory.getCloudConfig(); + CloudSite cloudSite = cloudConfig.getCloudSite (cloudSiteId); + + MsoTenantUtils tenantU = null; + if (cloudSite.getIdentityService().getIdentityServerType() == CloudIdentity.IdentityServerType.KEYSTONE) + { + tenantU = new MsoKeystoneUtils (msoPropID); + } + return tenantU; + } +} 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 new file mode 100644 index 0000000000..d1246580b2 --- /dev/null +++ b/adapters/mso-adapter-utils/src/main/java/org/openecomp/mso/openstack/utils/MsoYamlEditorWithEnvt.java @@ -0,0 +1,163 @@ +/*- + * ============LICENSE_START======================================================= + * OPENECOMP - MSO + * ================================================================================ + * 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.utils; + + + +import java.io.ByteArrayInputStream; +import java.io.InputStream; +import java.util.HashSet; +import java.util.Iterator; +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 java.util.LinkedHashMap; + +import org.yaml.snakeyaml.Yaml; + + +public class MsoYamlEditorWithEnvt { + + private Map <String, Object> yml; + private Yaml yaml = new Yaml (); + private static final ObjectMapper JSON_MAPPER = new ObjectMapper(); + + public MsoYamlEditorWithEnvt() { + super(); + } + public MsoYamlEditorWithEnvt(byte[] b) { + init(b); + } + + @SuppressWarnings("unchecked") + private synchronized void init (byte[] body) { + InputStream input = new ByteArrayInputStream (body); + yml = (Map <String, Object>) yaml.load (input); + } + + @SuppressWarnings("unchecked") + public synchronized Set <MsoHeatEnvironmentParameter> getParameterListFromEnvt() { + // In an environment entry, the parameters section can only contain the name:value - + // not other attributes. + Set <MsoHeatEnvironmentParameter> paramSet = new HashSet<MsoHeatEnvironmentParameter>(); + Map<String, Object> resourceMap = null; + try { + resourceMap = (Map<String,Object>) yml.get("parameters"); + } catch (Exception e) { + return paramSet; + } + if (resourceMap == null) { + return paramSet; + } + Iterator <Entry <String, Object>> it = resourceMap.entrySet().iterator(); + + while (it.hasNext()) { + MsoHeatEnvironmentParameter hep = new MsoHeatEnvironmentParameter(); + Map.Entry <String, Object> pair = it.next(); + //Map<String, String> resourceEntry = (Map <String, String>) pair.getValue(); + //String value = null; + String value = null; + Object obj = pair.getValue(); + if (obj instanceof java.lang.String) { + //value = (String) pair.getValue(); + // handle block scalar - literals and folded: + value = yaml.dump(obj); + // but this adds an extra '\n' at the end - which won't hurt - but we don't need it + value = value.substring(0, value.length() - 1); + } else if (obj instanceof java.util.LinkedHashMap) { + //Handle that it's json + try { + value = JSON_MAPPER.writeValueAsString(obj); + } catch (Exception e) { + value = "_BAD_JSON_MAPPING"; + } + } else { + //this handles integers/longs/floats/etc. + value = String.valueOf(obj); + } + hep.setName((String) pair.getKey()); + hep.setValue(value); + paramSet.add(hep); + } + return paramSet; + } + public synchronized Set <MsoHeatEnvironmentResource> getResourceListFromEnvt() { + try { + Set<MsoHeatEnvironmentResource> resourceList = new HashSet<MsoHeatEnvironmentResource>(); + @SuppressWarnings("unchecked") + Map<String, Object> resourceMap = (Map<String,Object>) yml.get("resource_registry"); + Iterator<Entry <String,Object>> it = resourceMap.entrySet().iterator(); + + while (it.hasNext()) { + MsoHeatEnvironmentResource her = new MsoHeatEnvironmentResource(); + Map.Entry<String, Object> pair = it.next(); + her.setName((String) pair.getKey()); + her.setValue((String) pair.getValue()); + resourceList.add(her); + } + return resourceList; + } catch (Exception e) { + + } + return null; + } + public synchronized Set <HeatTemplateParam> getParameterList () { + Set <HeatTemplateParam> paramSet = new HashSet <HeatTemplateParam> (); + @SuppressWarnings("unchecked") + Map <String, Object> resourceMap = (Map <String, Object>) yml.get ("parameters"); + Iterator <Entry <String, Object>> it = resourceMap.entrySet ().iterator (); + + while (it.hasNext ()) { + HeatTemplateParam param = new HeatTemplateParam (); + Map.Entry <String, Object> pair = it.next (); + @SuppressWarnings("unchecked") + Map <String, String> resourceEntry = (Map <String, String>) pair.getValue (); + String value = null; + try { + value = resourceEntry.get ("default"); + } catch (java.lang.ClassCastException cce) { + // This exception only - the value is an integer. For what we're doing + // here - we don't care - so set value to something - and it will + // get marked as not being required - which is correct. + //System.out.println("cce exception!"); + value = "300"; + // okay + } + param.setParamName ((String) pair.getKey ()); + if (value != null) { + param.setRequired (false); + } else { + param.setRequired (true); + } + value = resourceEntry.get ("type"); + param.setParamType (value); + + paramSet.add (param); + + } + return paramSet; + + } + + +} diff --git a/adapters/mso-adapter-utils/src/test/java/org/openecomp/mso/adapter_utils/tests/CloudConfigTest.java b/adapters/mso-adapter-utils/src/test/java/org/openecomp/mso/adapter_utils/tests/CloudConfigTest.java new file mode 100644 index 0000000000..8632d02164 --- /dev/null +++ b/adapters/mso-adapter-utils/src/test/java/org/openecomp/mso/adapter_utils/tests/CloudConfigTest.java @@ -0,0 +1,173 @@ +/*- + * ============LICENSE_START======================================================= + * OPENECOMP - MSO + * ================================================================================ + * 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.adapter_utils.tests; + + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertNull; +import org.junit.BeforeClass; +import org.junit.Test; +import java.util.Map; +import org.openecomp.mso.cloud.CloudConfig; +import org.openecomp.mso.cloud.CloudConfigFactory; +import org.openecomp.mso.cloud.CloudIdentity; +import org.openecomp.mso.cloud.CloudSite; + + +/** + * This class implements test methods of the CloudConfig features. + * + * + */ +public class CloudConfigTest { + + private static CloudConfig con; + private static CloudConfigFactory cloudConfigFactory= new CloudConfigFactory(); + + public CloudConfigTest () { + + } + + /** + * This method is called before any test occurs. + * It creates a fake tree from scratch + */ + @BeforeClass + public static final void prepare () { + ClassLoader classLoader = CloudConfigTest.class.getClassLoader(); + String config = classLoader.getResource("cloud_config.json").toString().substring(5); + + cloudConfigFactory.initializeCloudConfig(config,1); + con = cloudConfigFactory.getCloudConfig(); + } + + /** + * This method implements a test for the getCloudConfig method. + */ + @Test + public final void testGetCloudConfig () { + assertNotNull(con); + } + + /** + * This method implements a test for the getCloudSites method. + */ + @Test + public final void testGetCloudSites () { + Map<String,CloudSite> siteMap = con.getCloudSites(); + assertNotNull(siteMap); + + CloudSite site1 = siteMap.get("MT"); + CloudSite site2 = siteMap.get("DAN"); + CloudSite site3 = siteMap.get("MTINJVCC101"); + + assertEquals (site1.getRegionId(), "regionOne"); + assertEquals (site1.getIdentityServiceId(), "MT_KEYSTONE"); + assertEquals (site2.getRegionId(), "RegionOne"); + assertEquals (site2.getIdentityServiceId(), "DAN_KEYSTONE"); + assertEquals (site3.getRegionId(), "regionTwo"); + assertEquals (site3.getIdentityServiceId(), "MTINJVCC101_DCP"); + + } + + + /** + * This method implements a test for the getIdentityServices method. + */ + @Test + public final void testGetIdentityServices () { + Map<String,CloudIdentity> identityMap = con.getIdentityServices (); + assertNotNull(identityMap); + + CloudIdentity identity1 = identityMap.get("MT_KEYSTONE"); + CloudIdentity identity2 = identityMap.get("DAN_KEYSTONE"); + CloudIdentity identity3 = identityMap.get("MTINJVCC101_DCP"); + CloudIdentity identity4 = identityMap.get("MTSNJA3DCP1"); + +// assertEquals (identity1.getKeystoneUrl(), "http://localhost:5000/v2.0"); +// assertEquals (identity1.getIdentityUrl(), "http://localhost:5000/v2.0"); + assertEquals (identity1.getMsoId(), "john"); + assertEquals (identity1.getMsoPass(), "changeme"); + assertEquals (identity1.getAdminTenant(), "admin"); + assertEquals (identity1.getMemberRole(), "_member_"); + assertEquals (identity1.hasTenantMetadata(), false); + +// assertEquals (identity2.getKeystoneUrl(), "http://localhost:5000/v2.0"); +// assertEquals (identity2.getIdentityUrl(), "http://localhost:5000/v2.0"); + assertEquals (identity2.getMsoId(), "mockId"); + assertEquals (identity2.getMsoPass(), "stack123"); + assertEquals (identity2.getAdminTenant(), "service"); + assertEquals (identity2.getMemberRole(), "_member_"); + assertEquals (identity2.hasTenantMetadata(), false); + +// assertEquals (identity3.getKeystoneUrl(), "http://localhost:5000/v2.0"); +// assertEquals (identity3.getIdentityUrl(), "http://localhost:5000/v2.0"); + assertEquals (identity3.getMsoId(), "mockIdToo"); + assertEquals (identity3.getMsoPass(), "AICG@mm@@2015"); + assertEquals (identity3.getAdminTenant(), "service"); + assertEquals (identity3.getMemberRole(), "admin"); + assertEquals (identity3.hasTenantMetadata(), true); + +// assertEquals (identity4.getKeystoneUrl(), "https://localhost:5000/v2.0"); +// assertEquals (identity4.getIdentityUrl(), "https://localhost:5000/v2.0"); + assertEquals (identity4.getMsoId(), "mockIdToo"); + assertEquals (identity4.getMsoPass(), "2315QRS2015srq"); + assertEquals (identity4.getAdminTenant(), "service"); + assertEquals (identity4.getMemberRole(), "admin"); + assertEquals (identity4.hasTenantMetadata(), true); + + } + + /** + * This method implements a test for the getCloudSite method. + */ + @Test + public final void testGetCloudSite () { + CloudSite site1 = con.getCloudSite("MT"); + assertNotNull(site1); + assertEquals (site1.getRegionId(), "regionOne"); + assertEquals (site1.getIdentityServiceId(), "MT_KEYSTONE"); + + + + } + + /** + * This method implements a test for the getIdentityService method. + */ + @Test + public final void testGetIdentityService () { + CloudIdentity identity1 = con.getIdentityService("MT_KEYSTONE"); + assertNotNull(identity1); +// assertEquals (identity1.getKeystoneUrl(), "http://localhost:5000/v2.0"); +// assertEquals (identity1.getIdentityUrl(), "http://localhost:5000/v2.0"); + assertEquals (identity1.getMsoId(), "john"); + assertEquals (identity1.getMsoPass(), "changeme"); + assertEquals (identity1.getAdminTenant(), "admin"); + assertEquals (identity1.getMemberRole(), "_member_"); + assertEquals (identity1.hasTenantMetadata(), false); + + CloudIdentity identity2 = con.getIdentityService("Test"); + assertNull(identity2); + } + +} diff --git a/adapters/mso-adapter-utils/src/test/java/org/openecomp/mso/adapter_utils/tests/MsoCommonUtilsTest.java b/adapters/mso-adapter-utils/src/test/java/org/openecomp/mso/adapter_utils/tests/MsoCommonUtilsTest.java new file mode 100644 index 0000000000..9f17283786 --- /dev/null +++ b/adapters/mso-adapter-utils/src/test/java/org/openecomp/mso/adapter_utils/tests/MsoCommonUtilsTest.java @@ -0,0 +1,130 @@ +/*- + * ============LICENSE_START======================================================= + * OPENECOMP - MSO + * ================================================================================ + * 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.adapter_utils.tests; + + +import static org.junit.Assert.assertNull; +import static org.junit.Assert.assertTrue; + +import org.junit.AfterClass; +import org.junit.BeforeClass; +import org.junit.Test; +import org.mockito.Mockito; + +import org.openecomp.mso.logger.MsoAlarmLogger; +import org.openecomp.mso.openstack.exceptions.MsoAdapterException; +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.woorea.openstack.base.client.OpenStackBaseException; +import com.woorea.openstack.base.client.OpenStackConnectException; +import com.woorea.openstack.base.client.OpenStackRequest; +import com.woorea.openstack.base.client.OpenStackResponseException; + + +/** + * This class implements test methods of the MsoCommonUtils + * + * + */ +public class MsoCommonUtilsTest extends MsoCommonUtils { + + public static MsoPropertiesFactory msoPropertiesFactory = new MsoPropertiesFactory(); + + @Test + public final void testExecuteAndRecordOpenstackRequest () { + OpenStackRequest openstackRequest = Mockito.mock(OpenStackRequest.class); + Mockito.when(openstackRequest.endpoint()).thenReturn("localhost"); + Mockito.when(openstackRequest.path()).thenReturn("/test"); + //TODO:Must try a real connection + assertNull(super.executeAndRecordOpenstackRequest (openstackRequest)); + + } + + @Test + public final void testKeystoneErrorToMsoException () { + OpenStackBaseException openStackConnectException = new OpenStackConnectException("connect"); + + OpenStackBaseException openStackResponseException = new OpenStackResponseException("response",1); + + MsoException me = super.keystoneErrorToMsoException (openStackConnectException,"ContextError"); + + assertTrue(me instanceof MsoIOException); + assertTrue("connect".equals(me.getMessage())); + + + MsoException me2 = super.keystoneErrorToMsoException (openStackResponseException,"ContextError"); + assertTrue(me2 instanceof MsoOpenstackException); + assertTrue("ContextError".equals(me2.getContext())); + assertTrue(MsoExceptionCategory.OPENSTACK.equals(me2.getCategory())); + + } + + @Test + public final void testHeatExceptionToMsoException () { + OpenStackBaseException openStackConnectException = new OpenStackConnectException("connect"); + + OpenStackBaseException openStackResponseException = new OpenStackResponseException("response",1); + + MsoException me = super.heatExceptionToMsoException (openStackConnectException,"ContextError"); + + assertTrue(me instanceof MsoIOException); + assertTrue("connect".equals(me.getMessage())); + + + MsoException me2 = super.heatExceptionToMsoException (openStackResponseException,"ContextError"); + assertTrue(me2 instanceof MsoOpenstackException); + assertTrue("ContextError".equals(me2.getContext())); + assertTrue(MsoExceptionCategory.OPENSTACK.equals(me2.getCategory())); + } + + @Test + public final void testNeutronExceptionToMsoException () { + OpenStackBaseException openStackConnectException = new OpenStackConnectException("connect"); + + OpenStackBaseException openStackResponseException = new OpenStackResponseException("response",1); + + MsoException me = super.neutronExceptionToMsoException (openStackConnectException,"ContextError"); + + assertTrue(me instanceof MsoIOException); + assertTrue("connect".equals(me.getMessage())); + + MsoException me2 = super.neutronExceptionToMsoException (openStackResponseException,"ContextError"); + assertTrue(me2 instanceof MsoOpenstackException); + assertTrue("ContextError".equals(me2.getContext())); + assertTrue(MsoExceptionCategory.OPENSTACK.equals(me2.getCategory())); + } + + @Test + public final void testRuntimeExceptionToMsoException () { + RuntimeException re = new RuntimeException ("runtime"); + MsoException me = super.runtimeExceptionToMsoException (re, "ContextError"); + + assertTrue (me instanceof MsoAdapterException); + assertTrue("ContextError".equals(me.getContext())); + assertTrue(MsoExceptionCategory.INTERNAL.equals(me.getCategory())); + } +} diff --git a/adapters/mso-adapter-utils/src/test/java/org/openecomp/mso/adapter_utils/tests/MsoHeatUtilsTest.java b/adapters/mso-adapter-utils/src/test/java/org/openecomp/mso/adapter_utils/tests/MsoHeatUtilsTest.java new file mode 100644 index 0000000000..6f8a6e93d8 --- /dev/null +++ b/adapters/mso-adapter-utils/src/test/java/org/openecomp/mso/adapter_utils/tests/MsoHeatUtilsTest.java @@ -0,0 +1,91 @@ +/*- + * ============LICENSE_START======================================================= + * OPENECOMP - MSO + * ================================================================================ + * 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.adapter_utils.tests; + +import java.util.HashMap; + +import org.junit.BeforeClass; +import org.junit.Test; + +import org.openecomp.mso.cloud.CloudConfigFactory; +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.MsoIOException; +import org.openecomp.mso.openstack.exceptions.MsoStackAlreadyExists; +import org.openecomp.mso.openstack.exceptions.MsoTenantNotFound; +import org.openecomp.mso.openstack.utils.MsoCommonUtils; +import org.openecomp.mso.openstack.utils.MsoHeatUtils; +import org.openecomp.mso.properties.MsoPropertiesFactory; + + + +/** + * This class implements test methods of the MsoHeatUtils + * + * + */ +public class MsoHeatUtilsTest extends MsoCommonUtils { + public static MsoPropertiesFactory msoPropertiesFactory = new MsoPropertiesFactory(); + public static CloudConfigFactory cloudConfigFactory = new CloudConfigFactory(); + public static MsoHeatUtils msoHeatUtils; + + @BeforeClass + public static final void loadClasses() { + ClassLoader classLoader = CloudConfigTest.class.getClassLoader(); + String config = classLoader.getResource("cloud_config.json").toString().substring(5); + cloudConfigFactory.initializeCloudConfig(config, 1); + msoHeatUtils = new MsoHeatUtils("NO_PROP",msoPropertiesFactory,cloudConfigFactory); + } + + @Test + public final void testCreateStackBadCloudConfig () { + try { + msoHeatUtils.createStack ("DOESNOTEXIST", "test", "stackName", "test", new HashMap<String,Object> (), Boolean.TRUE, 10); + } catch (MsoException e) { + + } + + } + + @Test + public final void testCreateStackFailedConnectionHeatClient () throws MsoStackAlreadyExists, MsoTenantNotFound, MsoException, MsoCloudSiteNotFound { + try { + msoHeatUtils.createStack ("MT", "test", "stackName", "test", new HashMap<String,Object> (), Boolean.TRUE, 10); + } catch (MsoIOException e) { + + } + + } + + @Test + public final void testCreateStackFailedConnection () throws MsoStackAlreadyExists, MsoTenantNotFound, MsoException, MsoCloudSiteNotFound { + try { + msoHeatUtils.createStack ("MT", "test", "stackName", "test", new HashMap<String,Object> (), Boolean.TRUE, 10); + } catch (MsoIOException e) { + + } + + } + + + +} diff --git a/adapters/mso-adapter-utils/src/test/java/org/openecomp/mso/adapter_utils/tests/MsoHeatUtilsWithUpdateTest.java b/adapters/mso-adapter-utils/src/test/java/org/openecomp/mso/adapter_utils/tests/MsoHeatUtilsWithUpdateTest.java new file mode 100644 index 0000000000..a5d46da614 --- /dev/null +++ b/adapters/mso-adapter-utils/src/test/java/org/openecomp/mso/adapter_utils/tests/MsoHeatUtilsWithUpdateTest.java @@ -0,0 +1,132 @@ +/*- + * ============LICENSE_START======================================================= + * OPENECOMP - MSO + * ================================================================================ + * 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.adapter_utils.tests; + +import static org.junit.Assert.fail; +import static org.mockito.Mockito.when; + +import java.util.HashMap; +import java.util.Map; + +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.InjectMocks; +import org.mockito.Mock; +import org.mockito.runners.MockitoJUnitRunner; + +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 org.openecomp.mso.openstack.exceptions.MsoCloudSiteNotFound; +import org.openecomp.mso.openstack.exceptions.MsoException; +import org.openecomp.mso.openstack.exceptions.MsoIOException; +import org.openecomp.mso.openstack.utils.MsoHeatUtilsWithUpdate; +import org.openecomp.mso.properties.MsoPropertiesFactory; +import com.woorea.openstack.base.client.OpenStackConnectException; + +@RunWith(MockitoJUnitRunner.class) +public class MsoHeatUtilsWithUpdateTest { + + public static MsoPropertiesFactory msoPropertiesFactory = new MsoPropertiesFactory(); + public static CloudConfigFactory cloudConfigFactory = new CloudConfigFactory(); + + @Mock + CloudConfig cloudConfig; + @InjectMocks + MsoHeatUtilsWithUpdate util=new MsoHeatUtilsWithUpdate("NO_PROP",msoPropertiesFactory,cloudConfigFactory); + + private CloudSite cloudSite; + + @Before + public void init () { + cloudSite = new CloudSite (); + cloudSite.setId ("cloud"); + CloudIdentity cloudIdentity = new CloudIdentity (); + cloudSite.setIdentityService (cloudIdentity); + cloudIdentity.setKeystoneUrl ("toto"); + cloudIdentity.setMsoPass (CloudIdentity.encryptPassword ("mockId")); + + when (cloudConfig.getCloudSite ("cloud")).thenReturn (cloudSite); + when (cloudConfig.getCloudSite ("none")).thenReturn (null); + } + + @Test + public void testUpdateStack () { + // Heat heat = Mockito.mock (Heat.class); + Map <String, Object> stackInputs = new HashMap <> (); + try { + util.updateStack ("none", "tenantId", "stackName", "heatTemplate", stackInputs, false, 1); + } catch (MsoException e) { + if (e instanceof MsoCloudSiteNotFound) { + // Ok + } else { + e.printStackTrace (); + fail ("Exception caught"); + } + } + try { + util.updateStack ("cloud", "tenantId", "stackName", "heatTemplate", stackInputs, false, 1); + } catch (MsoException e) { + if (e instanceof MsoIOException && e.getCause () != null + && e.getCause () instanceof OpenStackConnectException) { + // Ok, we were able to go up to the connection to OpenStack + } else { + e.printStackTrace (); + fail ("Exception caught"); + } + } + try { + util.updateStack ("cloud", "tenantId", "stackName", "heatTemplate", stackInputs, false, 1, "environment"); + } catch (MsoException e) { + if (e instanceof MsoIOException && e.getCause () != null + && e.getCause () instanceof OpenStackConnectException) { + // Ok, we were able to go up to the connection to OpenStack + } else { + e.printStackTrace (); + fail ("Exception caught"); + } + } + try { + util.updateStack ("cloud", "tenantId", "stackName", "heatTemplate", stackInputs, false, 1, "environment", null); + } catch (MsoException e) { + if (e instanceof MsoIOException && e.getCause () != null + && e.getCause () instanceof OpenStackConnectException) { + // Ok, we were able to go up to the connection to OpenStack + } else { + e.printStackTrace (); + fail ("Exception caught"); + } + } + try { + util.updateStack ("cloud", "tenantId", "stackName", "heatTemplate", stackInputs, false, 1, "environment", null, null); + } catch (MsoException e) { + if (e instanceof MsoIOException && e.getCause () != null + && e.getCause () instanceof OpenStackConnectException) { + // Ok, we were able to go up to the connection to OpenStack + } else { + e.printStackTrace (); + fail ("Exception caught"); + } + } + } +} diff --git a/adapters/mso-adapter-utils/src/test/java/org/openecomp/mso/cloud/CloudIdentityESTest.java b/adapters/mso-adapter-utils/src/test/java/org/openecomp/mso/cloud/CloudIdentityESTest.java new file mode 100644 index 0000000000..69fbb2625d --- /dev/null +++ b/adapters/mso-adapter-utils/src/test/java/org/openecomp/mso/cloud/CloudIdentityESTest.java @@ -0,0 +1,400 @@ +/* + * This file was automatically generated by EvoSuite + * Mon Nov 14 08:37:20 GMT 2016 + */ + +package org.openecomp.mso.cloud; + +import org.junit.Test; +import static org.junit.Assert.*; +import static org.evosuite.runtime.EvoAssertions.*; + +import org.evosuite.runtime.EvoRunner; +import org.evosuite.runtime.EvoRunnerParameters; +import org.evosuite.runtime.PrivateAccess; +import org.junit.runner.RunWith; + +@RunWith(EvoRunner.class) @EvoRunnerParameters(mockJVMNonDeterminism = true, useVFS = true, useVNET = true, resetStaticState = true, useJEE = true) +public class CloudIdentityESTest { + + @Test(timeout = 4000) + public void test00() throws Throwable { + CloudIdentity cloudIdentity0 = new CloudIdentity(); + cloudIdentity0.setMsoId("ga-cj*/"); + cloudIdentity0.hashCode(); + } + + @Test(timeout = 4000) + public void test01() throws Throwable { + CloudIdentity cloudIdentity0 = new CloudIdentity(); + cloudIdentity0.setTenantMetadata(true); + boolean boolean0 = cloudIdentity0.hasTenantMetadata(); + assertTrue(boolean0); + } + + @Test(timeout = 4000) + public void test02() throws Throwable { + CloudIdentity cloudIdentity0 = new CloudIdentity(); + cloudIdentity0.setMsoPass(""); + String string0 = cloudIdentity0.getMsoPass(); + assertEquals("", string0); + } + + @Test(timeout = 4000) + public void test03() throws Throwable { + CloudIdentity cloudIdentity0 = new CloudIdentity(); + cloudIdentity0.setMsoId("hz4IjQ&in.t^IC|"); + String string0 = cloudIdentity0.getMsoId(); + assertEquals("hz4IjQ&in.t^IC|", string0); + } + + @Test(timeout = 4000) + public void test04() throws Throwable { + CloudIdentity cloudIdentity0 = new CloudIdentity(); + cloudIdentity0.setMemberRole("Exception in encryptPassword"); + String string0 = cloudIdentity0.getMemberRole(); + assertEquals("Exception in encryptPassword", string0); + } + + @Test(timeout = 4000) + public void test05() throws Throwable { + CloudIdentity cloudIdentity0 = new CloudIdentity(); + cloudIdentity0.setIdentityUrl("ASDC_ARTIFACT_ALREADY_DEPLOYED"); + String string0 = cloudIdentity0.getIdentityUrl(); + assertEquals("ASDC_ARTIFACT_ALREADY_DEPLOYED", string0); + } + + @Test(timeout = 4000) + public void test06() throws Throwable { + CloudIdentity cloudIdentity0 = new CloudIdentity(); + CloudIdentity.IdentityServerType cloudIdentity_IdentityServerType0 = CloudIdentity.IdentityServerType.KEYSTONE; + PrivateAccess.setVariable((Class<CloudIdentity>) CloudIdentity.class, cloudIdentity0, "identityServerType", (Object) cloudIdentity_IdentityServerType0); + String string0 = cloudIdentity0.getIdentityServerTypeAsString(); + assertEquals("KEYSTONE", string0); + } + + @Test(timeout = 4000) + public void test07() throws Throwable { + CloudIdentity cloudIdentity0 = new CloudIdentity(); + cloudIdentity0.setId(""); + String string0 = cloudIdentity0.getId(); + assertEquals("", string0); + } + + @Test(timeout = 4000) + public void test08() throws Throwable { + CloudIdentity cloudIdentity0 = new CloudIdentity(); + cloudIdentity0.setAdminTenant("0hh5nz?kd3N,FTKBX"); + String string0 = cloudIdentity0.getAdminTenant(); + assertEquals("0hh5nz?kd3N,FTKBX", string0); + } + + @Test(timeout = 4000) + public void test09() throws Throwable { + CloudIdentity cloudIdentity0 = new CloudIdentity(); + cloudIdentity0.setTenantMetadata(true); + CloudIdentity cloudIdentity1 = cloudIdentity0.clone(); + assertTrue(cloudIdentity1.equals((Object)cloudIdentity0)); + assertTrue(cloudIdentity1.hasTenantMetadata()); + assertNotSame(cloudIdentity1, cloudIdentity0); + } + + @Test(timeout = 4000) + public void test10() throws Throwable { + CloudIdentity cloudIdentity0 = new CloudIdentity(); + cloudIdentity0.setTenantMetadata(false); + CloudIdentity cloudIdentity1 = cloudIdentity0.clone(); + assertFalse(cloudIdentity1.hasTenantMetadata()); + assertTrue(cloudIdentity1.equals((Object)cloudIdentity0)); + assertNotSame(cloudIdentity1, cloudIdentity0); + } + + @Test(timeout = 4000) + public void test11() throws Throwable { + CloudIdentity cloudIdentity0 = new CloudIdentity(); + cloudIdentity0.setMsoPass("0LAxuQ0#K,Ma"); + // Undeclared exception! + try { + cloudIdentity0.getMsoPass(); + fail("Expecting exception: NumberFormatException"); + + } catch(NumberFormatException e) { + // + // For input string: \"0L\" + // + verifyException("java.lang.NumberFormatException", e); + } + } + + @Test(timeout = 4000) + public void test12() throws Throwable { + CloudIdentity cloudIdentity0 = new CloudIdentity(); + // Undeclared exception! + try { + cloudIdentity0.getKeystoneUrl(); + fail("Expecting exception: NullPointerException"); + + } catch(NullPointerException e) { + // + // no message in exception (getMessage() returned null) + // + verifyException("org.openecomp.mso.cloud.CloudIdentity", e); + } + } + + @Test(timeout = 4000) + public void test13() throws Throwable { + // Undeclared exception! + try { + CloudIdentity.encryptPassword((String) null); + fail("Expecting exception: NullPointerException"); + + } catch(NullPointerException e) { + // + // no message in exception (getMessage() returned null) + // + verifyException("org.openecomp.mso.utils.CryptoUtils", e); + } + } + + @Test(timeout = 4000) + public void test14() throws Throwable { + CloudIdentity cloudIdentity0 = new CloudIdentity(); + CloudIdentity cloudIdentity1 = cloudIdentity0.clone(); + assertTrue(cloudIdentity1.equals((Object)cloudIdentity0)); + + PrivateAccess.setVariable((Class<CloudIdentity>) CloudIdentity.class, cloudIdentity1, "msoPass", (Object) "0~=?Wm,~42b4:K"); + boolean boolean0 = cloudIdentity0.equals(cloudIdentity1); + assertFalse(boolean0); + } + + @Test(timeout = 4000) + public void test15() throws Throwable { + CloudIdentity cloudIdentity0 = new CloudIdentity(); + cloudIdentity0.setMemberRole("r"); + CloudIdentity cloudIdentity1 = new CloudIdentity(); + boolean boolean0 = cloudIdentity0.equals(cloudIdentity1); + assertFalse(boolean0); + } + + @Test(timeout = 4000) + public void test16() throws Throwable { + CloudIdentity cloudIdentity0 = new CloudIdentity(); + CloudIdentity cloudIdentity1 = cloudIdentity0.clone(); + assertTrue(cloudIdentity1.equals((Object)cloudIdentity0)); + + cloudIdentity1.setMemberRole("RA_SET_CALLBACK_AUTH_EXC"); + boolean boolean0 = cloudIdentity0.equals(cloudIdentity1); + assertFalse(boolean0); + } + + @Test(timeout = 4000) + public void test17() throws Throwable { + CloudIdentity cloudIdentity0 = new CloudIdentity(); + cloudIdentity0.setMemberRole("r"); + CloudIdentity cloudIdentity1 = cloudIdentity0.clone(); + boolean boolean0 = cloudIdentity0.equals(cloudIdentity1); + assertNotSame(cloudIdentity1, cloudIdentity0); + assertTrue(boolean0); + } + + @Test(timeout = 4000) + public void test18() throws Throwable { + CloudIdentity cloudIdentity0 = new CloudIdentity(); + Object object0 = new Object(); + boolean boolean0 = cloudIdentity0.equals(object0); + assertFalse(boolean0); + } + + @Test(timeout = 4000) + public void test19() throws Throwable { + CloudIdentity cloudIdentity0 = new CloudIdentity(); + boolean boolean0 = cloudIdentity0.equals((Object) null); + assertFalse(boolean0); + } + + @Test(timeout = 4000) + public void test20() throws Throwable { + CloudIdentity cloudIdentity0 = new CloudIdentity(); + boolean boolean0 = cloudIdentity0.equals(cloudIdentity0); + assertTrue(boolean0); + } + + @Test(timeout = 4000) + public void test22() throws Throwable { + CloudIdentity cloudIdentity0 = new CloudIdentity(); + cloudIdentity0.setMsoPass("9Y#4-v1Fu27keLW"); + cloudIdentity0.hashCode(); + } + + @Test(timeout = 4000) + public void test23() throws Throwable { + CloudIdentity cloudIdentity0 = new CloudIdentity(); + cloudIdentity0.setMemberRole("ASDC_GENERAL_METRICS"); + cloudIdentity0.hashCode(); + } + + @Test(timeout = 4000) + public void test24() throws Throwable { + CloudIdentity cloudIdentity0 = new CloudIdentity(); + cloudIdentity0.setIdentityUrl("g9+j0@{H}S|"); + cloudIdentity0.hashCode(); + } + + @Test(timeout = 4000) + public void test25() throws Throwable { + CloudIdentity cloudIdentity0 = new CloudIdentity(); + cloudIdentity0.setId("FSmZDF:2*!OtMq!i"); + cloudIdentity0.hashCode(); + } + + @Test(timeout = 4000) + public void test26() throws Throwable { + CloudIdentity cloudIdentity0 = new CloudIdentity(); + cloudIdentity0.setKeystoneUrl("VdON&(o*x/W!"); + assertNull(cloudIdentity0.getMemberRole()); + } + + @Test(timeout = 4000) + public void test27() throws Throwable { + CloudIdentity cloudIdentity0 = new CloudIdentity(); + String string0 = cloudIdentity0.getKeystoneUrl("A9Z Ol `I1^y]F[EC0", ""); + assertNull(string0); + } + + @Test(timeout = 4000) + public void test28() throws Throwable { + CloudIdentity cloudIdentity0 = new CloudIdentity(); + String string0 = cloudIdentity0.getMemberRole(); + assertNull(string0); + } + + @Test(timeout = 4000) + public void test29() throws Throwable { + CloudIdentity cloudIdentity0 = new CloudIdentity(); + // Undeclared exception! + try { + cloudIdentity0.getIdentityServerTypeAsString(); + fail("Expecting exception: NullPointerException"); + + } catch(NullPointerException e) { + // + // no message in exception (getMessage() returned null) + // + verifyException("org.openecomp.mso.cloud.CloudIdentity", e); + } + } + + @Test(timeout = 4000) + public void test30() throws Throwable { + CloudIdentity cloudIdentity0 = new CloudIdentity(); + cloudIdentity0.setIdentityUrl("com.att.eelf.i18n.EELFResourceManager$RESOURCE_TYPES"); + CloudIdentity cloudIdentity1 = new CloudIdentity(); + boolean boolean0 = cloudIdentity0.equals(cloudIdentity1); + assertFalse(boolean0); + } + + @Test(timeout = 4000) + public void test31() throws Throwable { + CloudIdentity cloudIdentity0 = new CloudIdentity(); + String string0 = cloudIdentity0.getId(); + assertNull(string0); + } + + @Test(timeout = 4000) + public void test32() throws Throwable { + CloudIdentity cloudIdentity0 = new CloudIdentity(); + cloudIdentity0.setTenantMetadata(false); + cloudIdentity0.hashCode(); + assertFalse(cloudIdentity0.hasTenantMetadata()); + } + + @Test(timeout = 4000) + public void test34() throws Throwable { + CloudIdentity cloudIdentity0 = new CloudIdentity(); + cloudIdentity0.setAdminTenant("0hh5nz?kd3N,FTKBX"); + cloudIdentity0.hashCode(); + } + + @Test(timeout = 4000) + public void test35() throws Throwable { + CloudIdentity cloudIdentity0 = new CloudIdentity(); + String string0 = cloudIdentity0.getAdminTenant(); + assertNull(string0); + + } + + @Test(timeout = 4000) + public void test37() throws Throwable { + CloudIdentity cloudIdentity0 = new CloudIdentity(); + String string0 = cloudIdentity0.getMsoId(); + assertNull(string0); + } + + @Test(timeout = 4000) + public void test38() throws Throwable { + CloudIdentity cloudIdentity0 = new CloudIdentity(); + cloudIdentity0.getIdentityServerType(); + } + + @Test(timeout = 4000) + public void test39() throws Throwable { + CloudIdentity cloudIdentity0 = new CloudIdentity(); + // Undeclared exception! + try { + cloudIdentity0.getMsoPass(); + fail("Expecting exception: NullPointerException"); + + } catch(NullPointerException e) { + // + // no message in exception (getMessage() returned null) + // + verifyException("org.openecomp.mso.utils.CryptoUtils", e); + } + } + + @Test(timeout = 4000) + public void test40() throws Throwable { + CloudIdentity cloudIdentity0 = new CloudIdentity(); + // Undeclared exception! + try { + cloudIdentity0.toString(); + fail("Expecting exception: NullPointerException"); + + } catch(NullPointerException e) { + // + // no message in exception (getMessage() returned null) + // + verifyException("org.openecomp.mso.cloud.CloudIdentity", e); + } + } + + @Test(timeout = 4000) + public void test41() throws Throwable { + CloudIdentity cloudIdentity0 = new CloudIdentity(); + // Undeclared exception! + try { + cloudIdentity0.hasTenantMetadata(); + fail("Expecting exception: NullPointerException"); + + } catch(NullPointerException e) { + // + // no message in exception (getMessage() returned null) + // + verifyException("org.openecomp.mso.cloud.CloudIdentity", e); + } + } + + @Test(timeout = 4000) + public void test42() throws Throwable { + CloudIdentity cloudIdentity0 = new CloudIdentity(); + String string0 = cloudIdentity0.getIdentityUrl(); + assertNull(string0); + } + + @Test(timeout = 4000) + public void test43() throws Throwable { + String string0 = CloudIdentity.encryptPassword("jaR\"aJmqpa>(&"); + assertEquals("718A16EDF9EA61E9350A07703082D5B5", string0); + } +} diff --git a/adapters/mso-adapter-utils/src/test/java/org/openecomp/mso/cloud/CloudIdentityTest.java b/adapters/mso-adapter-utils/src/test/java/org/openecomp/mso/cloud/CloudIdentityTest.java new file mode 100644 index 0000000000..377a7243ca --- /dev/null +++ b/adapters/mso-adapter-utils/src/test/java/org/openecomp/mso/cloud/CloudIdentityTest.java @@ -0,0 +1,59 @@ +/*- + * ============LICENSE_START======================================================= + * OPENECOMP - MSO + * ================================================================================ + * 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 static org.junit.Assert.assertTrue; + +import org.junit.Test; + + +public class CloudIdentityTest { + + @Test + public final void testCloudIdentity () { + CloudIdentity id = new CloudIdentity (); + id.setAdminTenant ("AdminTenant"); + id.setId ("id"); +// id.setKeystoneUrl ("keystone"); + id.setIdentityUrl ("keystone"); + id.setMemberRole ("member"); + id.setMsoId ("msoId"); + id.setMsoPass (CloudIdentity.encryptPassword ("password")); + id.setTenantMetadata (true); + + assertTrue (id.getAdminTenant ().equals ("AdminTenant")); + assertTrue (id.getId ().equals ("id")); +// assertTrue (id.getKeystoneUrl ().equals ("keystone")); + assertTrue (id.getMemberRole ().equals ("member")); + assertTrue (id.getMsoId ().equals ("msoId")); + assertTrue (id.getMsoPass ().equals ("password")); + assertTrue (id.hasTenantMetadata ()); +// assertTrue (id.toString ().contains ("keystone")); + } + + @Test + public final void testEncryption () { + String encrypted = CloudIdentity.encryptPassword ("password"); + assertTrue (encrypted != null); + assertTrue (!encrypted.equals ("password")); + } +} diff --git a/adapters/mso-adapter-utils/src/test/java/org/openecomp/mso/cloud/CloudSiteESTest.java b/adapters/mso-adapter-utils/src/test/java/org/openecomp/mso/cloud/CloudSiteESTest.java new file mode 100644 index 0000000000..68bccfcc1b --- /dev/null +++ b/adapters/mso-adapter-utils/src/test/java/org/openecomp/mso/cloud/CloudSiteESTest.java @@ -0,0 +1,315 @@ +/* + * This file was automatically generated by EvoSuite + * Mon Nov 14 08:42:36 GMT 2016 + */ + +package org.openecomp.mso.cloud; + +import org.junit.Test; +import static org.junit.Assert.*; +import static org.evosuite.shaded.org.mockito.Mockito.*; +import static org.evosuite.runtime.EvoAssertions.*; + +import org.evosuite.runtime.EvoRunner; +import org.evosuite.runtime.EvoRunnerParameters; +import org.evosuite.runtime.PrivateAccess; +import org.evosuite.runtime.ViolatedAssumptionAnswer; +import org.junit.runner.RunWith; + +@RunWith(EvoRunner.class) @EvoRunnerParameters(mockJVMNonDeterminism = true, useVFS = true, useVNET = true, resetStaticState = true, useJEE = true) +public class CloudSiteESTest extends CloudSiteESTestscaffolding { + + @Test(timeout = 4000) + public void test00() throws Throwable { + CloudSite cloudSite0 = new CloudSite(); + cloudSite0.setAic_version("-t"); + cloudSite0.hashCode(); + } + + @Test(timeout = 4000) + public void test01() throws Throwable { + CloudSite cloudSite0 = new CloudSite(); + cloudSite0.setRegionId("CloudSite: id="); + String string0 = cloudSite0.getRegionId(); + assertEquals("CloudSite: id=", string0); + } + + @Test(timeout = 4000) + public void test02() throws Throwable { + CloudSite cloudSite0 = new CloudSite(); + cloudSite0.setRegionId(""); + String string0 = cloudSite0.getRegionId(); + assertEquals("", string0); + } + + @Test(timeout = 4000) + public void test03() throws Throwable { + CloudSite cloudSite0 = new CloudSite(); + PrivateAccess.setVariable((Class<CloudSite>) CloudSite.class, cloudSite0, "identityServiceId", (Object) "PUBLIC"); + String string0 = cloudSite0.getIdentityServiceId(); + assertEquals("PUBLIC", string0); + } + + @Test(timeout = 4000) + public void test04() throws Throwable { + CloudSite cloudSite0 = new CloudSite(); + CloudIdentity cloudIdentity0 = new CloudIdentity(); + cloudSite0.setIdentityService(cloudIdentity0); + cloudIdentity0.setTenantMetadata(false); + CloudIdentity cloudIdentity1 = cloudSite0.getIdentityService(); + assertNull(cloudIdentity1.getAdminTenant()); + } + + @Test(timeout = 4000) + public void test05() throws Throwable { + CloudSite cloudSite0 = new CloudSite(); + cloudSite0.setId(""); + String string0 = cloudSite0.getId(); + assertEquals("", string0); + } + + @Test(timeout = 4000) + public void test06() throws Throwable { + CloudSite cloudSite0 = new CloudSite(); + cloudSite0.setClli("N;w7*-)9\"t|T/jCa"); + String string0 = cloudSite0.getClli(); + assertEquals("N;w7*-)9\"t|T/jCa", string0); + } + + @Test(timeout = 4000) + public void test07() throws Throwable { + CloudSite cloudSite0 = new CloudSite(); + cloudSite0.setClli(""); + String string0 = cloudSite0.getClli(); + assertEquals("", string0); + } + + @Test(timeout = 4000) + public void test08() throws Throwable { + CloudSite cloudSite0 = new CloudSite(); + cloudSite0.setAic_version("v&K[by0"); + String string0 = cloudSite0.getAic_version(); + assertEquals("v&K[by0", string0); + } + + @Test(timeout = 4000) + public void test09() throws Throwable { + CloudSite cloudSite0 = new CloudSite(); + cloudSite0.setAic_version(""); + String string0 = cloudSite0.getAic_version(); + assertEquals("", string0); + } + + @Test(timeout = 4000) + public void test10() throws Throwable { + CloudSite cloudSite0 = new CloudSite(); + CloudIdentity cloudIdentity0 = mock(CloudIdentity.class, new ViolatedAssumptionAnswer()); + doReturn((CloudIdentity) null).when(cloudIdentity0).clone(); + cloudSite0.setIdentityService(cloudIdentity0); + CloudSite cloudSite1 = cloudSite0.clone(); + boolean boolean0 = cloudSite0.equals(cloudSite1); + assertFalse(boolean0); + assertFalse(cloudSite1.equals((Object)cloudSite0)); + } + + @Test(timeout = 4000) + public void test11() throws Throwable { + CloudSite cloudSite0 = new CloudSite(); + CloudSite cloudSite1 = new CloudSite(); + assertTrue(cloudSite1.equals((Object)cloudSite0)); + + cloudSite1.setClli("CloudSite: id=null, regionId=null, identityServiceId=null, aic_version=null, clli=null"); + boolean boolean0 = cloudSite0.equals(cloudSite1); + assertFalse(boolean0); + } + + @Test(timeout = 4000) + public void test12() throws Throwable { + CloudSite cloudSite0 = new CloudSite(); + CloudIdentity cloudIdentity0 = new CloudIdentity(); + cloudSite0.setIdentityService(cloudIdentity0); + CloudSite cloudSite1 = cloudSite0.clone(); + assertTrue(cloudSite1.equals((Object)cloudSite0)); + + cloudSite1.setAic_version(""); + boolean boolean0 = cloudSite0.equals(cloudSite1); + assertFalse(cloudSite1.equals((Object)cloudSite0)); + assertFalse(boolean0); + } + + @Test(timeout = 4000) + public void test13() throws Throwable { + CloudSite cloudSite0 = new CloudSite(); + CloudIdentity cloudIdentity0 = new CloudIdentity(); + cloudSite0.setIdentityService(cloudIdentity0); + CloudSite cloudSite1 = cloudSite0.clone(); + boolean boolean0 = cloudSite0.equals(cloudSite1); + assertNotSame(cloudSite1, cloudSite0); + assertTrue(boolean0); + } + + @Test(timeout = 4000) + public void test14() throws Throwable { + CloudSite cloudSite0 = new CloudSite(); + cloudSite0.setRegionId("CloudSite: id=null, regionId=null, identityServiceId=null, aic_version=null, clli=null"); + CloudSite cloudSite1 = new CloudSite(); + boolean boolean0 = cloudSite0.equals(cloudSite1); + assertFalse(cloudSite1.equals((Object)cloudSite0)); + assertFalse(boolean0); + } + + @Test(timeout = 4000) + public void test15() throws Throwable { + CloudSite cloudSite0 = new CloudSite(); + CloudIdentity cloudIdentity0 = new CloudIdentity(); + cloudSite0.setIdentityService(cloudIdentity0); + CloudSite cloudSite1 = cloudSite0.clone(); + assertTrue(cloudSite1.equals((Object)cloudSite0)); + + cloudSite1.setId("Tx;$hjj"); + boolean boolean0 = cloudSite1.equals(cloudSite0); + assertFalse(boolean0); + assertFalse(cloudSite1.equals((Object)cloudSite0)); + } + + @Test(timeout = 4000) + public void test16() throws Throwable { + CloudSite cloudSite0 = new CloudSite(); + Object object0 = new Object(); + boolean boolean0 = cloudSite0.equals(object0); + assertFalse(boolean0); + } + + @Test(timeout = 4000) + public void test17() throws Throwable { + CloudSite cloudSite0 = new CloudSite(); + boolean boolean0 = cloudSite0.equals((Object) null); + assertFalse(boolean0); + } + + @Test(timeout = 4000) + public void test18() throws Throwable { + CloudSite cloudSite0 = new CloudSite(); + boolean boolean0 = cloudSite0.equals(cloudSite0); + assertTrue(boolean0); + } + + @Test(timeout = 4000) + public void test19() throws Throwable { + CloudSite cloudSite0 = new CloudSite(); + PrivateAccess.setVariable((Class<CloudSite>) CloudSite.class, cloudSite0, "identityServiceId", (Object) ""); + CloudSite cloudSite1 = new CloudSite(); + boolean boolean0 = cloudSite0.equals(cloudSite1); + assertFalse(boolean0); + assertFalse(cloudSite1.equals((Object)cloudSite0)); + } + + @Test(timeout = 4000) + public void test20() throws Throwable { + CloudSite cloudSite0 = new CloudSite(); + PrivateAccess.setVariable((Class<CloudSite>) CloudSite.class, cloudSite0, "clli", (Object) "AgBkO0S\"V'R'"); + cloudSite0.hashCode(); + } + + @Test(timeout = 4000) + public void test21() throws Throwable { + CloudSite cloudSite0 = new CloudSite(); + PrivateAccess.setVariable((Class<CloudSite>) CloudSite.class, cloudSite0, "regionId", (Object) "`V+.b PU'3:EbS"); + cloudSite0.hashCode(); + } + + @Test(timeout = 4000) + public void test22() throws Throwable { + CloudSite cloudSite0 = new CloudSite(); + PrivateAccess.setVariable((Class<CloudSite>) CloudSite.class, cloudSite0, "identityServiceId", (Object) "PUBLIC"); + cloudSite0.hashCode(); + } + + @Test(timeout = 4000) + public void test23() throws Throwable { + CloudSite cloudSite0 = new CloudSite(); + PrivateAccess.setVariable((Class<CloudSite>) CloudSite.class, cloudSite0, "id", (Object) "PUBLIC"); + cloudSite0.hashCode(); + } + + @Test(timeout = 4000) + public void test24() throws Throwable { + CloudSite cloudSite0 = new CloudSite(); + String string0 = cloudSite0.getIdentityServiceId(); + assertNull(string0); + } + + @Test(timeout = 4000) + public void test25() throws Throwable { + CloudSite cloudSite0 = new CloudSite(); + String string0 = cloudSite0.toString(); + assertEquals("CloudSite: id=null, regionId=null, identityServiceId=null, aic_version=null, clli=null", string0); + } + + @Test(timeout = 4000) + public void test26() throws Throwable { + CloudSite cloudSite0 = new CloudSite(); + String string0 = cloudSite0.getAic_version(); + assertNull(string0); + } + + @Test(timeout = 4000) + public void test27() throws Throwable { + CloudSite cloudSite0 = new CloudSite(); + CloudIdentity cloudIdentity0 = new CloudIdentity(); + cloudSite0.setIdentityService(cloudIdentity0); + cloudSite0.hashCode(); + } + + @Test(timeout = 4000) + public void test28() throws Throwable { + CloudSite cloudSite0 = new CloudSite(); + String string0 = cloudSite0.getClli(); + assertNull(string0); + } + + @Test(timeout = 4000) + public void test29() throws Throwable { + CloudSite cloudSite0 = new CloudSite(); + String string0 = cloudSite0.getId(); + assertNull(string0); + } + + @Test(timeout = 4000) + public void test30() throws Throwable { + CloudSite cloudSite0 = new CloudSite(); + String string0 = cloudSite0.getRegionId(); + assertNull(string0); + } + + @Test(timeout = 4000) + public void test31() throws Throwable { + CloudSite cloudSite0 = new CloudSite(); + cloudSite0.setId("Tx;$hjj"); + String string0 = cloudSite0.getId(); + assertEquals("Tx;$hjj", string0); + } + + @Test(timeout = 4000) + public void test32() throws Throwable { + CloudSite cloudSite0 = new CloudSite(); + CloudIdentity cloudIdentity0 = cloudSite0.getIdentityService(); + assertNull(cloudIdentity0); + } + + @Test(timeout = 4000) + public void test33() throws Throwable { + CloudSite cloudSite0 = new CloudSite(); + // Undeclared exception! + try { + cloudSite0.clone(); + fail("Expecting exception: NullPointerException"); + + } catch(NullPointerException e) { + // + // no message in exception (getMessage() returned null) + // + verifyException("org.openecomp.mso.cloud.CloudSite", e); + } + } +} diff --git a/adapters/mso-adapter-utils/src/test/java/org/openecomp/mso/cloud/CloudSiteESTestscaffolding.java b/adapters/mso-adapter-utils/src/test/java/org/openecomp/mso/cloud/CloudSiteESTestscaffolding.java new file mode 100644 index 0000000000..48e800ff5b --- /dev/null +++ b/adapters/mso-adapter-utils/src/test/java/org/openecomp/mso/cloud/CloudSiteESTestscaffolding.java @@ -0,0 +1,150 @@ +/** + * Scaffolding file used to store all the setups needed to run + * tests automatically generated by EvoSuite + * Mon Nov 14 08:42:36 GMT 2016 + */ + +package org.openecomp.mso.cloud; + +import org.evosuite.runtime.annotation.EvoSuiteClassExclude; +import org.junit.BeforeClass; +import org.junit.Before; +import org.junit.After; +import org.junit.AfterClass; +import org.evosuite.runtime.sandbox.Sandbox; + +@EvoSuiteClassExclude +public class CloudSiteESTestscaffolding { + + @org.junit.Rule + public org.evosuite.runtime.vnet.NonFunctionalRequirementRule nfr = new org.evosuite.runtime.vnet.NonFunctionalRequirementRule(); + + private static final java.util.Properties defaultProperties = (java.util.Properties) java.lang.System.getProperties().clone(); + + private org.evosuite.runtime.thread.ThreadStopper threadStopper = new org.evosuite.runtime.thread.ThreadStopper (org.evosuite.runtime.thread.KillSwitchHandler.getInstance(), 3000); + + @BeforeClass + public static void initEvoSuiteFramework() { + org.evosuite.runtime.RuntimeSettings.className = "org.openecomp.mso.cloud.CloudSite"; + org.evosuite.runtime.GuiSupport.initialize(); + org.evosuite.runtime.RuntimeSettings.maxNumberOfThreads = 100; + org.evosuite.runtime.RuntimeSettings.maxNumberOfIterationsPerLoop = 10000; + org.evosuite.runtime.RuntimeSettings.mockSystemIn = true; + org.evosuite.runtime.RuntimeSettings.sandboxMode = org.evosuite.runtime.sandbox.Sandbox.SandboxMode.RECOMMENDED; + org.evosuite.runtime.sandbox.Sandbox.initializeSecurityManagerForSUT(); + org.evosuite.runtime.classhandling.JDKClassResetter.init(); + initializeClasses(); + org.evosuite.runtime.Runtime.getInstance().resetRuntime(); + } + + @AfterClass + public static void clearEvoSuiteFramework(){ + Sandbox.resetDefaultSecurityManager(); + java.lang.System.setProperties((java.util.Properties) defaultProperties.clone()); + } + + @Before + public void initTestCase(){ + threadStopper.storeCurrentThreads(); + threadStopper.startRecordingTime(); + org.evosuite.runtime.jvm.ShutdownHookHandler.getInstance().initHandler(); + org.evosuite.runtime.sandbox.Sandbox.goingToExecuteSUTCode(); + + org.evosuite.runtime.GuiSupport.setHeadless(); + org.evosuite.runtime.Runtime.getInstance().resetRuntime(); + org.evosuite.runtime.agent.InstrumentingAgent.activate(); + } + + @After + public void doneWithTestCase(){ + threadStopper.killAndJoinClientThreads(); + org.evosuite.runtime.jvm.ShutdownHookHandler.getInstance().safeExecuteAddedHooks(); + org.evosuite.runtime.classhandling.JDKClassResetter.reset(); + resetClasses(); + org.evosuite.runtime.sandbox.Sandbox.doneWithExecutingSUTCode(); + org.evosuite.runtime.agent.InstrumentingAgent.deactivate(); + org.evosuite.runtime.GuiSupport.restoreHeadlessMode(); + } + + + private static void initializeClasses() { + org.evosuite.runtime.classhandling.ClassStateSupport.initializeClasses(CloudSiteESTestscaffolding.class.getClassLoader() , + "org.openecomp.mso.logger.MsoLogger", + "org.openecomp.mso.logger.MessageEnum", + "com.att.eelf.i18n.EELFResolvableErrorEnum", + "org.openecomp.mso.logger.MsoLogger$ResponseCode", + "org.openecomp.mso.entity.MsoRequest", + "org.openecomp.mso.cloud.CloudSite", + "org.openecomp.mso.logger.MsoLogger$StatusCode", + "com.att.eelf.i18n.EELFResourceManager$RESOURCE_TYPES", + "com.att.eelf.configuration.EELFManager", + "org.openecomp.mso.cloud.CloudIdentity$IdentityServerType", + "org.openecomp.mso.logger.MsoLogger$ErrorCode", + "com.att.eelf.configuration.EELFLogger", + "com.att.eelf.i18n.EELFMsgs", + "org.openecomp.mso.openstack.exceptions.MsoException", + "com.att.eelf.configuration.EELFLogger$Level", + "org.openecomp.mso.logger.MsoLogger$Catalog", + "com.att.eelf.configuration.SLF4jWrapper", + "com.att.eelf.i18n.EELFResourceManager", + "org.openecomp.mso.cloud.CloudIdentity" + ); + } + + private static void resetClasses() { + org.evosuite.runtime.classhandling.ClassResetter.getInstance().setClassLoader(CloudSiteESTestscaffolding.class.getClassLoader()); + + org.evosuite.runtime.classhandling.ClassStateSupport.resetClasses( + "org.openecomp.mso.logger.MsoLogger$Catalog", + "org.openecomp.mso.logger.MsoLogger", + "com.att.eelf.i18n.EELFResourceManager", + "com.att.eelf.i18n.EELFMsgs", + "com.att.eelf.i18n.EELFResourceManager$RESOURCE_TYPES", + "org.apache.xerces.jaxp.SAXParserFactoryImpl", + "org.apache.xerces.jaxp.SAXParserImpl", + "org.apache.xerces.parsers.XMLParser", + "org.apache.xerces.parsers.AbstractSAXParser", + "org.apache.xerces.parsers.SAXParser", + "org.apache.xerces.parsers.ObjectFactory", + "org.apache.xerces.util.ParserConfigurationSettings", + "org.apache.xerces.parsers.XML11Configuration", + "org.apache.xerces.parsers.XIncludeAwareParserConfiguration", + "org.apache.xerces.util.SymbolTable", + "org.apache.xerces.impl.XMLEntityManager", + "org.apache.xerces.util.AugmentationsImpl$SmallContainer", + "org.apache.xerces.impl.XMLEntityManager$ByteBufferPool", + "org.apache.xerces.impl.XMLEntityManager$CharacterBufferPool", + "org.apache.xerces.impl.XMLEntityScanner$1", + "org.apache.xerces.impl.XMLEntityScanner", + "org.apache.xerces.impl.XMLErrorReporter", + "org.apache.xerces.impl.XMLScanner", + "org.apache.xerces.impl.XMLDocumentFragmentScannerImpl", + "org.apache.xerces.impl.XMLDocumentScannerImpl", + "org.apache.xerces.util.XMLStringBuffer", + "org.apache.xerces.util.XMLAttributesImpl", + "org.apache.xerces.impl.XMLDTDScannerImpl", + "org.apache.xerces.impl.dtd.XMLDTDProcessor", + "org.apache.xerces.impl.dtd.XMLDTDValidator", + "org.apache.xerces.impl.validation.ValidationState", + "org.apache.xerces.impl.dtd.XMLElementDecl", + "org.apache.xerces.impl.dtd.XMLSimpleType", + "org.apache.xerces.impl.dv.DTDDVFactory", + "org.apache.xerces.impl.dv.ObjectFactory", + "org.apache.xerces.impl.dv.dtd.DTDDVFactoryImpl", + "org.apache.xerces.impl.XMLVersionDetector", + "org.apache.xerces.impl.msg.XMLMessageFormatter", + "org.apache.xerces.impl.io.UTF8Reader", + "org.apache.xerces.util.XMLSymbols", + "org.apache.xerces.xni.NamespaceContext", + "org.apache.xerces.util.XMLChar", + "org.apache.xerces.impl.Constants", + "com.att.eelf.configuration.EELFLogger$Level", + "com.att.eelf.configuration.EELFManager", + "org.openecomp.mso.logger.MessageEnum", + "org.openecomp.mso.cloud.CloudIdentity", + "org.openecomp.mso.utils.CryptoUtils", + "org.openecomp.mso.logger.MsoAlarmLogger", + "org.openecomp.mso.openstack.utils.MsoCommonUtils" + ); + } +} diff --git a/adapters/mso-adapter-utils/src/test/java/org/openecomp/mso/openstack/beans/MsoTenantESTest.java b/adapters/mso-adapter-utils/src/test/java/org/openecomp/mso/openstack/beans/MsoTenantESTest.java new file mode 100644 index 0000000000..241ca88a1d --- /dev/null +++ b/adapters/mso-adapter-utils/src/test/java/org/openecomp/mso/openstack/beans/MsoTenantESTest.java @@ -0,0 +1,83 @@ +/* + * This file was automatically generated by EvoSuite + * Mon Nov 14 08:56:50 GMT 2016 + */ + +package org.openecomp.mso.openstack.beans; + +import org.junit.Test; +import static org.junit.Assert.*; + +import java.util.Map; +import org.evosuite.runtime.EvoRunner; +import org.evosuite.runtime.EvoRunnerParameters; +import org.junit.runner.RunWith; + +@RunWith(EvoRunner.class) @EvoRunnerParameters(mockJVMNonDeterminism = true, useVFS = true, useVNET = true, resetStaticState = true, useJEE = true) +public class MsoTenantESTest extends MsoTenantESTestscaffolding { + + @Test(timeout = 4000) + public void test0() throws Throwable { + MsoTenant msoTenant0 = new MsoTenant("P<5j-:=G4zf", "P<5j-:=G4zf", (Map<String, String>) null); + String string0 = msoTenant0.getTenantName(); + assertEquals("P<5j-:=G4zf", string0); + } + + @Test(timeout = 4000) + public void test1() throws Throwable { + MsoTenant msoTenant0 = new MsoTenant("", "", (Map<String, String>) null); + String string0 = msoTenant0.getTenantName(); + assertEquals("", string0); + } + + @Test(timeout = 4000) + public void test2() throws Throwable { + MsoTenant msoTenant0 = new MsoTenant(); + String string0 = msoTenant0.getTenantName(); + assertNull(string0); + } + + @Test(timeout = 4000) + public void test3() throws Throwable { + MsoTenant msoTenant0 = new MsoTenant(); + Map<String, String> map0 = msoTenant0.getMetadata(); + assertNull(map0); + } + + @Test(timeout = 4000) + public void test4() throws Throwable { + MsoTenant msoTenant0 = new MsoTenant("", "SsK{%:", (Map<String, String>) null); + String string0 = msoTenant0.getTenantId(); + assertEquals("", string0); + assertEquals("SsK{%:", msoTenant0.getTenantName()); + } + + @Test(timeout = 4000) + public void test5() throws Throwable { + MsoTenant msoTenant0 = new MsoTenant(); + msoTenant0.setTenantId("9A"); + String string0 = msoTenant0.getTenantId(); + assertEquals("9A", string0); + } + + @Test(timeout = 4000) + public void test6() throws Throwable { + MsoTenant msoTenant0 = new MsoTenant(); + msoTenant0.setMetadata((Map<String, String>) null); + assertNull(msoTenant0.getTenantName()); + } + + @Test(timeout = 4000) + public void test7() throws Throwable { + MsoTenant msoTenant0 = new MsoTenant(); + msoTenant0.setTenantName("9A"); + assertNull(msoTenant0.getTenantId()); + } + + @Test(timeout = 4000) + public void test8() throws Throwable { + MsoTenant msoTenant0 = new MsoTenant(); + String string0 = msoTenant0.getTenantId(); + assertNull(string0); + } +} diff --git a/adapters/mso-adapter-utils/src/test/java/org/openecomp/mso/openstack/beans/MsoTenantESTestscaffolding.java b/adapters/mso-adapter-utils/src/test/java/org/openecomp/mso/openstack/beans/MsoTenantESTestscaffolding.java new file mode 100644 index 0000000000..0ac4893ee8 --- /dev/null +++ b/adapters/mso-adapter-utils/src/test/java/org/openecomp/mso/openstack/beans/MsoTenantESTestscaffolding.java @@ -0,0 +1,78 @@ +/** + * Scaffolding file used to store all the setups needed to run + * tests automatically generated by EvoSuite + * Mon Nov 14 08:56:50 GMT 2016 + */ + +package org.openecomp.mso.openstack.beans; + +import org.evosuite.runtime.annotation.EvoSuiteClassExclude; +import org.junit.BeforeClass; +import org.junit.Before; +import org.junit.After; +import org.junit.AfterClass; +import org.evosuite.runtime.sandbox.Sandbox; + +@EvoSuiteClassExclude +public class MsoTenantESTestscaffolding { + + @org.junit.Rule + public org.evosuite.runtime.vnet.NonFunctionalRequirementRule nfr = new org.evosuite.runtime.vnet.NonFunctionalRequirementRule(); + + private static final java.util.Properties defaultProperties = (java.util.Properties) java.lang.System.getProperties().clone(); + + private org.evosuite.runtime.thread.ThreadStopper threadStopper = new org.evosuite.runtime.thread.ThreadStopper (org.evosuite.runtime.thread.KillSwitchHandler.getInstance(), 3000); + + @BeforeClass + public static void initEvoSuiteFramework() { + org.evosuite.runtime.RuntimeSettings.className = "org.openecomp.mso.openstack.beans.MsoTenant"; + org.evosuite.runtime.GuiSupport.initialize(); + org.evosuite.runtime.RuntimeSettings.maxNumberOfThreads = 100; + org.evosuite.runtime.RuntimeSettings.maxNumberOfIterationsPerLoop = 10000; + org.evosuite.runtime.RuntimeSettings.mockSystemIn = true; + org.evosuite.runtime.RuntimeSettings.sandboxMode = org.evosuite.runtime.sandbox.Sandbox.SandboxMode.RECOMMENDED; + org.evosuite.runtime.sandbox.Sandbox.initializeSecurityManagerForSUT(); + org.evosuite.runtime.classhandling.JDKClassResetter.init(); + initializeClasses(); + org.evosuite.runtime.Runtime.getInstance().resetRuntime(); + } + + @AfterClass + public static void clearEvoSuiteFramework(){ + Sandbox.resetDefaultSecurityManager(); + java.lang.System.setProperties((java.util.Properties) defaultProperties.clone()); + } + + @Before + public void initTestCase(){ + threadStopper.storeCurrentThreads(); + threadStopper.startRecordingTime(); + org.evosuite.runtime.jvm.ShutdownHookHandler.getInstance().initHandler(); + org.evosuite.runtime.sandbox.Sandbox.goingToExecuteSUTCode(); + + org.evosuite.runtime.GuiSupport.setHeadless(); + org.evosuite.runtime.Runtime.getInstance().resetRuntime(); + org.evosuite.runtime.agent.InstrumentingAgent.activate(); + } + + @After + public void doneWithTestCase(){ + threadStopper.killAndJoinClientThreads(); + org.evosuite.runtime.jvm.ShutdownHookHandler.getInstance().safeExecuteAddedHooks(); + org.evosuite.runtime.classhandling.JDKClassResetter.reset(); + resetClasses(); + org.evosuite.runtime.sandbox.Sandbox.doneWithExecutingSUTCode(); + org.evosuite.runtime.agent.InstrumentingAgent.deactivate(); + org.evosuite.runtime.GuiSupport.restoreHeadlessMode(); + } + + + private static void initializeClasses() { + org.evosuite.runtime.classhandling.ClassStateSupport.initializeClasses(MsoTenantESTestscaffolding.class.getClassLoader() , + "org.openecomp.mso.openstack.beans.MsoTenant" + ); + } + + private static void resetClasses() { + } +} diff --git a/adapters/mso-adapter-utils/src/test/java/org/openecomp/mso/openstack/beans/NetworkInfoESTest.java b/adapters/mso-adapter-utils/src/test/java/org/openecomp/mso/openstack/beans/NetworkInfoESTest.java new file mode 100644 index 0000000000..9c157252ed --- /dev/null +++ b/adapters/mso-adapter-utils/src/test/java/org/openecomp/mso/openstack/beans/NetworkInfoESTest.java @@ -0,0 +1,247 @@ +/* + * This file was automatically generated by EvoSuite + * Mon Nov 14 08:44:14 GMT 2016 + */ + +package org.openecomp.mso.openstack.beans; + +import org.junit.Test; +import static org.junit.Assert.*; +import static org.evosuite.shaded.org.mockito.Mockito.*; +import static org.evosuite.runtime.MockitoExtension.*; + +import com.woorea.openstack.quantum.model.Network; +import com.woorea.openstack.quantum.model.Segment; +import java.util.List; +import org.evosuite.runtime.EvoRunner; +import org.evosuite.runtime.EvoRunnerParameters; +import org.evosuite.runtime.ViolatedAssumptionAnswer; +import org.junit.runner.RunWith; + +@RunWith(EvoRunner.class) @EvoRunnerParameters(mockJVMNonDeterminism = true, useVFS = true, useVNET = true, resetStaticState = true, useJEE = true) +public class NetworkInfoESTest extends NetworkInfoESTestscaffolding { + + @Test(timeout = 4000) + public void test00() throws Throwable { + NetworkInfo networkInfo0 = new NetworkInfo(); + networkInfo0.setVlans((List<Integer>) null); + List<Integer> list0 = networkInfo0.getVlans(); + assertNull(list0); + } + + @Test(timeout = 4000) + public void test01() throws Throwable { + Network network0 = mock(Network.class, new ViolatedAssumptionAnswer()); + doReturn((String) null).when(network0).getId(); + doReturn((String) null).when(network0).getName(); + doReturn((String) null).when(network0).getProviderPhysicalNetwork(); + doReturn((List) null).when(network0).getSegments(); + doReturn((String) null).when(network0).getStatus(); + doReturn((List) null).when(network0).getSubnets(); + NetworkInfo networkInfo0 = new NetworkInfo(network0); + List<String> list0 = networkInfo0.getSubnets(); + assertNull(list0); + } + + @Test(timeout = 4000) + public void test02() throws Throwable { + NetworkInfo networkInfo0 = new NetworkInfo(); + networkInfo0.setShared("Network [id="); + String string0 = networkInfo0.getShared(); + assertEquals("Network [id=", string0); + } + + @Test(timeout = 4000) + public void test03() throws Throwable { + NetworkInfo networkInfo0 = new NetworkInfo(); + networkInfo0.setProvider((String) null); + String string0 = networkInfo0.getProvider(); + assertNull(string0); + } + + @Test(timeout = 4000) + public void test04() throws Throwable { + NetworkInfo networkInfo0 = new NetworkInfo(); + networkInfo0.setProvider("ERROR"); + String string0 = networkInfo0.getProvider(); + assertEquals("ERROR", string0); + } + + @Test(timeout = 4000) + public void test05() throws Throwable { + NetworkInfo networkInfo0 = new NetworkInfo(); + networkInfo0.setId((String) null); + String string0 = networkInfo0.getId(); + assertNull(string0); + } + + @Test(timeout = 4000) + public void test06() throws Throwable { + NetworkStatus networkStatus0 = NetworkStatus.DOWN; + NetworkInfo networkInfo0 = new NetworkInfo("IghhGdNW B*}", networkStatus0); + String string0 = networkInfo0.getId(); + assertEquals("IghhGdNW B*}", string0); + } + + @Test(timeout = 4000) + public void test07() throws Throwable { + Network network0 = mock(Network.class, new ViolatedAssumptionAnswer()); + doReturn((String) null).when(network0).getId(); + doReturn((String) null).when(network0).getName(); + doReturn((String) null).when(network0).getProviderPhysicalNetwork(); + doReturn((List) null).when(network0).getSegments(); + doReturn((String) null).when(network0).getStatus(); + doReturn((List) null).when(network0).getSubnets(); + NetworkInfo networkInfo0 = new NetworkInfo(network0); + List<String> list0 = networkInfo0.getSubnets(); + Network network1 = mock(Network.class, new ViolatedAssumptionAnswer()); + doReturn((String) null).when(network1).getId(); + doReturn((String) null).when(network1).getName(); + doReturn((String) null).when(network1).getProviderPhysicalNetwork(); + doReturn((List<Segment>) null).when(network1).getSegments(); + doReturn("uxR^({\"", (String) null).when(network1).getStatus(); + doReturn(list0).when(network1).getSubnets(); + NetworkInfo networkInfo1 = new NetworkInfo(network1); + assertNull(networkInfo1.getName()); + } + + @Test(timeout = 4000) + public void test08() throws Throwable { + Network network0 = mock(Network.class, new ViolatedAssumptionAnswer()); + doReturn(", segments: ").when(network0).getId(); + doReturn("ACTIVE").when(network0).getName(); + doReturn("l1~gC_#a'H,#*").when(network0).getProviderNetworkType(); + doReturn("ACTIVE", "").when(network0).getProviderPhysicalNetwork(); + doReturn("ERROR", "ERROR", "%<3T-").when(network0).getStatus(); + doReturn((List) null).when(network0).getSubnets(); + NetworkInfo networkInfo0 = new NetworkInfo(network0); + networkInfo0.getStatus(); + } + + @Test(timeout = 4000) + public void test09() throws Throwable { + Network network0 = mock(Network.class, new ViolatedAssumptionAnswer()); + doReturn(", segments: ").when(network0).getId(); + doReturn("ACTIVE").when(network0).getName(); + doReturn((String) null).when(network0).getProviderNetworkType(); + doReturn("ACTIVE", (String) null).when(network0).getProviderPhysicalNetwork(); + doReturn("ERROR", (String) null).when(network0).getStatus(); + NetworkInfo networkInfo0 = null; + try { + networkInfo0 = new NetworkInfo(network0); + fail("Expecting exception: NullPointerException"); + + } catch(NullPointerException e) { + } + } + + @Test(timeout = 4000) + public void test10() throws Throwable { + NetworkInfo networkInfo0 = new NetworkInfo((Network) null); + assertEquals("", networkInfo0.getId()); + } + + @Test(timeout = 4000) + public void test11() throws Throwable { + NetworkInfo networkInfo0 = new NetworkInfo(); + String string0 = networkInfo0.toString(); + assertEquals("Network: name=,id=,status=UNKNOWN,provider=,vlans=[],subnets=[],shared=", string0); + } + + @Test(timeout = 4000) + public void test12() throws Throwable { + NetworkInfo networkInfo0 = new NetworkInfo(); + NetworkStatus networkStatus0 = NetworkStatus.NOTFOUND; + networkInfo0.setStatus(networkStatus0); + assertEquals("", networkInfo0.getShared()); + } + + @Test(timeout = 4000) + public void test13() throws Throwable { + NetworkStatus networkStatus0 = NetworkStatus.UNKNOWN; + NetworkInfo networkInfo0 = new NetworkInfo((String) null, networkStatus0); + String string0 = networkInfo0.getName(); + assertNull(string0); + } + + @Test(timeout = 4000) + public void test14() throws Throwable { + NetworkInfo networkInfo0 = new NetworkInfo(); + networkInfo0.setShared((String) null); + String string0 = networkInfo0.getShared(); + assertNull(string0); + } + + @Test(timeout = 4000) + public void test15() throws Throwable { + NetworkInfo networkInfo0 = new NetworkInfo(); + String string0 = networkInfo0.getShared(); + assertEquals("", string0); + } + + @Test(timeout = 4000) + public void test16() throws Throwable { + NetworkInfo networkInfo0 = new NetworkInfo(); + List<String> list0 = networkInfo0.getSubnets(); + Network network0 = mock(Network.class, new ViolatedAssumptionAnswer()); + doReturn("R65k@>rbu`lzb#").when(network0).getId(); + doReturn("ERROR").when(network0).getName(); + doReturn("DOWN").when(network0).getProviderNetworkType(); + doReturn("u1Z(%z~k-ao5#y", "R65k@>rbu`lzb#").when(network0).getProviderPhysicalNetwork(); + doReturn("R65k@>rbu`lzb#", "R65k@>rbu`lzb#").when(network0).getStatus(); + doReturn(list0).when(network0).getSubnets(); + NetworkInfo networkInfo1 = new NetworkInfo(network0); + networkInfo1.getName(); + assertEquals("R65k@>rbu`lzb#", networkInfo1.getProvider()); + } + + @Test(timeout = 4000) + public void test17() throws Throwable { + NetworkInfo networkInfo0 = new NetworkInfo(); + List<Integer> list0 = networkInfo0.getVlans(); + networkInfo0.setVlans(list0); + assertEquals("", networkInfo0.getProvider()); + } + + @Test(timeout = 4000) + public void test18() throws Throwable { + NetworkInfo networkInfo0 = new NetworkInfo(); + networkInfo0.setName(""); + assertEquals(NetworkStatus.UNKNOWN, networkInfo0.getStatus()); + } + + @Test(timeout = 4000) + public void test19() throws Throwable { + NetworkInfo networkInfo0 = new NetworkInfo(); + networkInfo0.setSubnets((List<String>) null); + assertEquals("", networkInfo0.getShared()); + } + + @Test(timeout = 4000) + public void test20() throws Throwable { + NetworkInfo networkInfo0 = new NetworkInfo(); + NetworkStatus networkStatus0 = networkInfo0.getStatus(); + assertEquals(NetworkStatus.UNKNOWN, networkStatus0); + } + + @Test(timeout = 4000) + public void test21() throws Throwable { + NetworkInfo networkInfo0 = new NetworkInfo(); + String string0 = networkInfo0.getProvider(); + assertEquals("", string0); + } + + @Test(timeout = 4000) + public void test22() throws Throwable { + NetworkInfo networkInfo0 = new NetworkInfo(); + String string0 = networkInfo0.getId(); + assertEquals("", string0); + } + + @Test(timeout = 4000) + public void test23() throws Throwable { + NetworkInfo networkInfo0 = new NetworkInfo(); + String string0 = networkInfo0.getName(); + assertEquals("", string0); + } +} diff --git a/adapters/mso-adapter-utils/src/test/java/org/openecomp/mso/openstack/beans/NetworkInfoESTestscaffolding.java b/adapters/mso-adapter-utils/src/test/java/org/openecomp/mso/openstack/beans/NetworkInfoESTestscaffolding.java new file mode 100644 index 0000000000..0c87ca9016 --- /dev/null +++ b/adapters/mso-adapter-utils/src/test/java/org/openecomp/mso/openstack/beans/NetworkInfoESTestscaffolding.java @@ -0,0 +1,92 @@ +/** + * Scaffolding file used to store all the setups needed to run + * tests automatically generated by EvoSuite + * Mon Nov 14 08:44:14 GMT 2016 + */ + +package org.openecomp.mso.openstack.beans; + +import org.evosuite.runtime.annotation.EvoSuiteClassExclude; +import org.junit.BeforeClass; +import org.junit.Before; +import org.junit.After; +import org.junit.AfterClass; +import org.evosuite.runtime.sandbox.Sandbox; + +@EvoSuiteClassExclude +public class NetworkInfoESTestscaffolding { + + @org.junit.Rule + public org.evosuite.runtime.vnet.NonFunctionalRequirementRule nfr = new org.evosuite.runtime.vnet.NonFunctionalRequirementRule(); + + private static final java.util.Properties defaultProperties = (java.util.Properties) java.lang.System.getProperties().clone(); + + private org.evosuite.runtime.thread.ThreadStopper threadStopper = new org.evosuite.runtime.thread.ThreadStopper (org.evosuite.runtime.thread.KillSwitchHandler.getInstance(), 3000); + + @BeforeClass + public static void initEvoSuiteFramework() { + org.evosuite.runtime.RuntimeSettings.className = "org.openecomp.mso.openstack.beans.NetworkInfo"; + org.evosuite.runtime.GuiSupport.initialize(); + org.evosuite.runtime.RuntimeSettings.maxNumberOfThreads = 100; + org.evosuite.runtime.RuntimeSettings.maxNumberOfIterationsPerLoop = 10000; + org.evosuite.runtime.RuntimeSettings.mockSystemIn = true; + org.evosuite.runtime.RuntimeSettings.sandboxMode = org.evosuite.runtime.sandbox.Sandbox.SandboxMode.RECOMMENDED; + org.evosuite.runtime.sandbox.Sandbox.initializeSecurityManagerForSUT(); + org.evosuite.runtime.classhandling.JDKClassResetter.init(); + initializeClasses(); + org.evosuite.runtime.Runtime.getInstance().resetRuntime(); + } + + @AfterClass + public static void clearEvoSuiteFramework(){ + Sandbox.resetDefaultSecurityManager(); + java.lang.System.setProperties((java.util.Properties) defaultProperties.clone()); + } + + @Before + public void initTestCase(){ + threadStopper.storeCurrentThreads(); + threadStopper.startRecordingTime(); + org.evosuite.runtime.jvm.ShutdownHookHandler.getInstance().initHandler(); + org.evosuite.runtime.sandbox.Sandbox.goingToExecuteSUTCode(); + + org.evosuite.runtime.GuiSupport.setHeadless(); + org.evosuite.runtime.Runtime.getInstance().resetRuntime(); + org.evosuite.runtime.agent.InstrumentingAgent.activate(); + } + + @After + public void doneWithTestCase(){ + threadStopper.killAndJoinClientThreads(); + org.evosuite.runtime.jvm.ShutdownHookHandler.getInstance().safeExecuteAddedHooks(); + org.evosuite.runtime.classhandling.JDKClassResetter.reset(); + resetClasses(); + org.evosuite.runtime.sandbox.Sandbox.doneWithExecutingSUTCode(); + org.evosuite.runtime.agent.InstrumentingAgent.deactivate(); + org.evosuite.runtime.GuiSupport.restoreHeadlessMode(); + } + + + private static void initializeClasses() { + org.evosuite.runtime.classhandling.ClassStateSupport.initializeClasses(NetworkInfoESTestscaffolding.class.getClassLoader() , + "org.codehaus.jackson.annotate.JacksonAnnotation", + "com.woorea.openstack.quantum.model.Network", + "org.codehaus.jackson.annotate.JsonIgnoreProperties", + "com.woorea.openstack.quantum.model.Segment", + "org.openecomp.mso.openstack.beans.NetworkInfo", + "org.openecomp.mso.openstack.beans.NetworkStatus", + "com.woorea.openstack.quantum.model.Network$NetworkType", + "org.codehaus.jackson.map.annotate.JsonRootName" + ); + } + + private static void resetClasses() { + org.evosuite.runtime.classhandling.ClassResetter.getInstance().setClassLoader(NetworkInfoESTestscaffolding.class.getClassLoader()); + + org.evosuite.runtime.classhandling.ClassStateSupport.resetClasses( + "org.openecomp.mso.openstack.beans.NetworkStatus", + "org.openecomp.mso.openstack.beans.NetworkInfo", + "com.woorea.openstack.quantum.model.Network" + ); + } +} diff --git a/adapters/mso-adapter-utils/src/test/java/org/openecomp/mso/openstack/beans/NetworkRollbackESTest.java b/adapters/mso-adapter-utils/src/test/java/org/openecomp/mso/openstack/beans/NetworkRollbackESTest.java new file mode 100644 index 0000000000..bad2bde0af --- /dev/null +++ b/adapters/mso-adapter-utils/src/test/java/org/openecomp/mso/openstack/beans/NetworkRollbackESTest.java @@ -0,0 +1,303 @@ +/* + * This file was automatically generated by EvoSuite + * Mon Nov 14 08:55:12 GMT 2016 + */ + +package org.openecomp.mso.openstack.beans; + +import org.junit.Test; +import static org.junit.Assert.*; +import static org.evosuite.shaded.org.mockito.Mockito.*; +import static org.evosuite.runtime.MockitoExtension.*; +import org.openecomp.mso.entity.MsoRequest; + +import java.util.List; +import org.evosuite.runtime.EvoRunner; +import org.evosuite.runtime.EvoRunnerParameters; +import org.evosuite.runtime.ViolatedAssumptionAnswer; +import org.junit.runner.RunWith; + +@RunWith(EvoRunner.class) @EvoRunnerParameters(mockJVMNonDeterminism = true, useVFS = true, useVNET = true, resetStaticState = true, useJEE = true) +public class NetworkRollbackESTest extends NetworkRollbackESTestscaffolding { + + @Test(timeout = 4000) + public void test00() throws Throwable { + NetworkRollback networkRollback0 = new NetworkRollback(); + networkRollback0.setNetworkStackId("H/r!m+_NT$?ed$IPcLD"); + networkRollback0.setNeutronNetworkId("H/r!m+_NT$?ed$IPcLD"); + MsoRequest msoRequest0 = mock(MsoRequest.class, new ViolatedAssumptionAnswer()); + doReturn((String) null, (String) null, (String) null).when(msoRequest0).toString(); + networkRollback0.setNetworkStackId(""); + networkRollback0.setMsoRequest((MsoRequest) null); + networkRollback0.setMsoRequest(msoRequest0); + networkRollback0.toString(); + networkRollback0.setNeutronNetworkId("NetworkRollback [networkId=null, neutronNetworkId=H/r!m+_NT$?ed$IPcLD, networkStackId=, tenantId=null, cloudId=null, networkType=null, networkCreated=false, networkName=null, physicalNetwork=null]"); + networkRollback0.getVlans(); + networkRollback0.setCloudId("NetworkRollback [networkId=null, neutronNetworkId=H/r!m+_NT$?ed$IPcLD, networkStackId=, tenantId=null, cloudId=null, networkType=null, networkCreated=false, networkName=null, physicalNetwork=null]"); + networkRollback0.setNetworkType("NetworkRollback [networkId=null, neutronNetworkId=H/r!m+_NT$?ed$IPcLD, networkStackId=, tenantId=null, cloudId=null, networkType=null, networkCreated=false, networkName=null, physicalNetwork=null]"); + networkRollback0.toString(); + networkRollback0.setCloudId("NetworkRollback [networkId=null, neutronNetworkId=H/r!m+_NT$?ed$IPcLD, networkStackId=, tenantId=null, cloudId=null, networkType=null, networkCreated=false, networkName=null, physicalNetwork=null]"); + networkRollback0.setTenantId("80\u0002<]~y|x(#fl"); + networkRollback0.setCloudId("=:U\"]"); + networkRollback0.toString(); + networkRollback0.getVlans(); + networkRollback0.toString(); + networkRollback0.getVlans(); + networkRollback0.getVlans(); + networkRollback0.getVlans(); + networkRollback0.setVlans((List<Integer>) null); + networkRollback0.toString(); + networkRollback0.getMsoRequest(); + networkRollback0.getVlans(); + networkRollback0.toString(); + networkRollback0.getMsoRequest(); + networkRollback0.getVlans(); + networkRollback0.getMsoRequest(); + networkRollback0.getVlans(); + List<Integer> list0 = networkRollback0.getVlans(); + assertNull(list0); + } + + @Test(timeout = 4000) + public void test01() throws Throwable { + NetworkRollback networkRollback0 = new NetworkRollback(); + networkRollback0.setNetworkType((String) null); + networkRollback0.getMsoRequest(); + networkRollback0.setMsoRequest((MsoRequest) null); + networkRollback0.setNetworkId(""); + networkRollback0.setTenantId(""); + networkRollback0.getNetworkId(); + networkRollback0.setNeutronNetworkId(""); + networkRollback0.setCloudId("O;On"); + assertFalse(networkRollback0.getNetworkCreated()); + } + + @Test(timeout = 4000) + public void test02() throws Throwable { + NetworkRollback networkRollback0 = new NetworkRollback(); + networkRollback0.setCloudId("C5FS|V@CMBag"); + networkRollback0.getVlans(); + networkRollback0.setVlans((List<Integer>) null); + networkRollback0.getPhysicalNetwork(); + networkRollback0.setVlans((List<Integer>) null); + networkRollback0.getNeutronNetworkId(); + networkRollback0.setNetworkType("C5FS|V@CMBag"); + networkRollback0.getNetworkType(); + assertFalse(networkRollback0.getNetworkCreated()); + } + + @Test(timeout = 4000) + public void test03() throws Throwable { + NetworkRollback networkRollback0 = new NetworkRollback(); + networkRollback0.setNetworkId(", networkName="); + networkRollback0.setNetworkStackId("u)"); + networkRollback0.setNetworkId("u)"); + networkRollback0.setNetworkId(", networkName="); + networkRollback0.getNetworkStackId(); + assertFalse(networkRollback0.getNetworkCreated()); + } + + @Test(timeout = 4000) + public void test04() throws Throwable { + NetworkRollback networkRollback0 = new NetworkRollback(); + networkRollback0.setNetworkType("V3$f~dKduUu0"); + networkRollback0.setNetworkType(""); + networkRollback0.setTenantId(""); + networkRollback0.getPhysicalNetwork(); + networkRollback0.getVlans(); + networkRollback0.getNetworkType(); + assertFalse(networkRollback0.getNetworkCreated()); + } + + @Test(timeout = 4000) + public void test05() throws Throwable { + NetworkRollback networkRollback0 = new NetworkRollback(); + networkRollback0.setTenantId("Lu#)!pt2p=<#T."); + networkRollback0.getTenantId(); + networkRollback0.setNetworkStackId("Lu#)!pt2p=<#T."); + networkRollback0.getNeutronNetworkId(); + networkRollback0.setTenantId("Lu#)!pt2p=<#T."); + networkRollback0.setNetworkStackId((String) null); + String string0 = networkRollback0.toString(); + assertEquals("NetworkRollback [networkId=null, neutronNetworkId=null, networkStackId=null, tenantId=Lu#)!pt2p=<#T., cloudId=null, networkType=null, networkCreated=false, networkName=null, physicalNetwork=null]", string0); + } + + @Test(timeout = 4000) + public void test06() throws Throwable { + NetworkRollback networkRollback0 = new NetworkRollback(); + networkRollback0.getMsoRequest(); + networkRollback0.setMsoRequest((MsoRequest) null); + String string0 = networkRollback0.toString(); + assertEquals("NetworkRollback [networkId=null, neutronNetworkId=null, networkStackId=null, tenantId=null, cloudId=null, networkType=null, networkCreated=false, networkName=null, physicalNetwork=null]", string0); + + networkRollback0.setNetworkName(""); + networkRollback0.getNetworkName(); + networkRollback0.setNetworkCreated(true); + networkRollback0.setNetworkName(""); + networkRollback0.getPhysicalNetwork(); + networkRollback0.setTenantId(""); + networkRollback0.setNetworkId(""); + assertTrue(networkRollback0.getNetworkCreated()); + } + + @Test(timeout = 4000) + public void test07() throws Throwable { + NetworkRollback networkRollback0 = new NetworkRollback(); + networkRollback0.getTenantId(); + networkRollback0.setNetworkStackId((String) null); + networkRollback0.getVlans(); + networkRollback0.setTenantId(""); + networkRollback0.getTenantId(); + networkRollback0.setVlans((List<Integer>) null); + String string0 = networkRollback0.toString(); + assertEquals("NetworkRollback [networkId=null, neutronNetworkId=null, networkStackId=null, tenantId=, cloudId=null, networkType=null, networkCreated=false, networkName=null, physicalNetwork=null]", string0); + + NetworkRollback networkRollback1 = new NetworkRollback(); + assertFalse(networkRollback1.getNetworkCreated()); + } + + @Test(timeout = 4000) + public void test08() throws Throwable { + NetworkRollback networkRollback0 = new NetworkRollback(); + networkRollback0.setNeutronNetworkId(""); + networkRollback0.setCloudId(""); + networkRollback0.getTenantId(); + networkRollback0.setTenantId(""); + networkRollback0.setNetworkType("Y=x>wx'"); + networkRollback0.getNeutronNetworkId(); + networkRollback0.getVlans(); + networkRollback0.setVlans((List<Integer>) null); + networkRollback0.setNetworkStackId("6P7@4aGo &Kd>V"); + networkRollback0.getCloudId(); + NetworkRollback networkRollback1 = new NetworkRollback(); + assertFalse(networkRollback1.getNetworkCreated()); + } + + @Test(timeout = 4000) + public void test09() throws Throwable { + NetworkRollback networkRollback0 = new NetworkRollback(); + assertFalse(networkRollback0.getNetworkCreated()); + + networkRollback0.setNetworkCreated(true); + networkRollback0.toString(); + networkRollback0.setNeutronNetworkId("NetworkRollback [networkId=null, neutronNetworkId=null, networkStackId=null, tenantId=null, cloudId=null, networkType=null, networkCreated=true, networkName=null, physicalNetwork=null]"); + networkRollback0.getPhysicalNetwork(); + boolean boolean0 = networkRollback0.getNetworkCreated(); + assertTrue(boolean0); + } + + @Test(timeout = 4000) + public void test10() throws Throwable { + NetworkRollback networkRollback0 = new NetworkRollback(); + networkRollback0.setNetworkId(", tenantId="); + networkRollback0.setNetworkId(""); + networkRollback0.setTenantId(", tenantId="); + networkRollback0.setNetworkName("+*"); + networkRollback0.getNetworkName(); + networkRollback0.setNetworkStackId(", tenantId="); + networkRollback0.setCloudId("+*"); + networkRollback0.getCloudId(); + NetworkRollback networkRollback1 = new NetworkRollback(); + assertFalse(networkRollback1.getNetworkCreated()); + } + + @Test(timeout = 4000) + public void test11() throws Throwable { + NetworkRollback networkRollback0 = new NetworkRollback(); + networkRollback0.setPhysicalNetwork("!(>41heY7e"); + networkRollback0.setTenantId("j"); + networkRollback0.setNeutronNetworkId("j"); + networkRollback0.getPhysicalNetwork(); + networkRollback0.getVlans(); + NetworkRollback networkRollback1 = new NetworkRollback(); + networkRollback1.getMsoRequest(); + networkRollback0.setMsoRequest((MsoRequest) null); + networkRollback0.setNetworkCreated(false); + networkRollback0.setNeutronNetworkId("j"); + assertFalse(networkRollback0.getNetworkCreated()); + } + + @Test(timeout = 4000) + public void test12() throws Throwable { + NetworkRollback networkRollback0 = new NetworkRollback(); + networkRollback0.setPhysicalNetwork(""); + networkRollback0.setNetworkStackId(""); + networkRollback0.setNeutronNetworkId(""); + networkRollback0.getNetworkStackId(); + networkRollback0.getMsoRequest(); + assertFalse(networkRollback0.getNetworkCreated()); + } + + @Test(timeout = 4000) + public void test13() throws Throwable { + NetworkRollback networkRollback0 = new NetworkRollback(); + networkRollback0.setCloudId("7u@lc[l##+g`2V"); + networkRollback0.getVlans(); + networkRollback0.setVlans((List<Integer>) null); + networkRollback0.setNetworkType(""); + networkRollback0.setCloudId(", physicalNetwork="); + networkRollback0.setPhysicalNetwork(""); + networkRollback0.setNeutronNetworkId(", physicalNetwork="); + networkRollback0.getPhysicalNetwork(); + networkRollback0.getNeutronNetworkId(); + assertFalse(networkRollback0.getNetworkCreated()); + } + + @Test(timeout = 4000) + public void test14() throws Throwable { + NetworkRollback networkRollback0 = new NetworkRollback(); + networkRollback0.getNetworkId(); + assertFalse(networkRollback0.getNetworkCreated()); + } + + @Test(timeout = 4000) + public void test15() throws Throwable { + NetworkRollback networkRollback0 = new NetworkRollback(); + networkRollback0.getMsoRequest(); + networkRollback0.setMsoRequest((MsoRequest) null); + networkRollback0.getNetworkCreated(); + networkRollback0.setNetworkId(", networkName="); + networkRollback0.getNeutronNetworkId(); + networkRollback0.setPhysicalNetwork((String) null); + networkRollback0.getNetworkId(); + NetworkRollback networkRollback1 = new NetworkRollback(); + String string0 = networkRollback1.toString(); + assertEquals("NetworkRollback [networkId=null, neutronNetworkId=null, networkStackId=null, tenantId=null, cloudId=null, networkType=null, networkCreated=false, networkName=null, physicalNetwork=null]", string0); + + networkRollback1.getVlans(); + networkRollback0.setVlans((List<Integer>) null); + networkRollback0.getNetworkId(); + networkRollback1.getPhysicalNetwork(); + networkRollback1.setNetworkCreated(false); + assertFalse(networkRollback1.getNetworkCreated()); + } + + @Test(timeout = 4000) + public void test16() throws Throwable { + NetworkRollback networkRollback0 = new NetworkRollback(); + networkRollback0.getNetworkType(); + networkRollback0.setTenantId((String) null); + networkRollback0.setNetworkName(" networkStacId="); + networkRollback0.getCloudId(); + networkRollback0.getTenantId(); + networkRollback0.setNetworkStackId(" networkStacId="); + networkRollback0.setNeutronNetworkId((String) null); + assertFalse(networkRollback0.getNetworkCreated()); + } + + @Test(timeout = 4000) + public void test17() throws Throwable { + NetworkRollback networkRollback0 = new NetworkRollback(); + networkRollback0.getNetworkName(); + assertFalse(networkRollback0.getNetworkCreated()); + } + + @Test(timeout = 4000) + public void test18() throws Throwable { + NetworkRollback networkRollback0 = new NetworkRollback(); + networkRollback0.setNetworkType("uK+JCvyg\"J(C d.w["); + networkRollback0.setCloudId("uK+JCvyg\"J(C d.w["); + networkRollback0.getNetworkStackId(); + assertFalse(networkRollback0.getNetworkCreated()); + } +} diff --git a/adapters/mso-adapter-utils/src/test/java/org/openecomp/mso/openstack/beans/NetworkRollbackESTestscaffolding.java b/adapters/mso-adapter-utils/src/test/java/org/openecomp/mso/openstack/beans/NetworkRollbackESTestscaffolding.java new file mode 100644 index 0000000000..1665732f62 --- /dev/null +++ b/adapters/mso-adapter-utils/src/test/java/org/openecomp/mso/openstack/beans/NetworkRollbackESTestscaffolding.java @@ -0,0 +1,79 @@ +/** + * Scaffolding file used to store all the setups needed to run + * tests automatically generated by EvoSuite + * Mon Nov 14 08:55:12 GMT 2016 + */ + +package org.openecomp.mso.openstack.beans; + +import org.evosuite.runtime.annotation.EvoSuiteClassExclude; +import org.junit.BeforeClass; +import org.junit.Before; +import org.junit.After; +import org.junit.AfterClass; +import org.evosuite.runtime.sandbox.Sandbox; + +@EvoSuiteClassExclude +public class NetworkRollbackESTestscaffolding { + + @org.junit.Rule + public org.evosuite.runtime.vnet.NonFunctionalRequirementRule nfr = new org.evosuite.runtime.vnet.NonFunctionalRequirementRule(); + + private static final java.util.Properties defaultProperties = (java.util.Properties) java.lang.System.getProperties().clone(); + + private org.evosuite.runtime.thread.ThreadStopper threadStopper = new org.evosuite.runtime.thread.ThreadStopper (org.evosuite.runtime.thread.KillSwitchHandler.getInstance(), 3000); + + @BeforeClass + public static void initEvoSuiteFramework() { + org.evosuite.runtime.RuntimeSettings.className = "org.openecomp.mso.openstack.beans.NetworkRollback"; + org.evosuite.runtime.GuiSupport.initialize(); + org.evosuite.runtime.RuntimeSettings.maxNumberOfThreads = 100; + org.evosuite.runtime.RuntimeSettings.maxNumberOfIterationsPerLoop = 10000; + org.evosuite.runtime.RuntimeSettings.mockSystemIn = true; + org.evosuite.runtime.RuntimeSettings.sandboxMode = org.evosuite.runtime.sandbox.Sandbox.SandboxMode.RECOMMENDED; + org.evosuite.runtime.sandbox.Sandbox.initializeSecurityManagerForSUT(); + org.evosuite.runtime.classhandling.JDKClassResetter.init(); + initializeClasses(); + org.evosuite.runtime.Runtime.getInstance().resetRuntime(); + } + + @AfterClass + public static void clearEvoSuiteFramework(){ + Sandbox.resetDefaultSecurityManager(); + java.lang.System.setProperties((java.util.Properties) defaultProperties.clone()); + } + + @Before + public void initTestCase(){ + threadStopper.storeCurrentThreads(); + threadStopper.startRecordingTime(); + org.evosuite.runtime.jvm.ShutdownHookHandler.getInstance().initHandler(); + org.evosuite.runtime.sandbox.Sandbox.goingToExecuteSUTCode(); + + org.evosuite.runtime.GuiSupport.setHeadless(); + org.evosuite.runtime.Runtime.getInstance().resetRuntime(); + org.evosuite.runtime.agent.InstrumentingAgent.activate(); + } + + @After + public void doneWithTestCase(){ + threadStopper.killAndJoinClientThreads(); + org.evosuite.runtime.jvm.ShutdownHookHandler.getInstance().safeExecuteAddedHooks(); + org.evosuite.runtime.classhandling.JDKClassResetter.reset(); + resetClasses(); + org.evosuite.runtime.sandbox.Sandbox.doneWithExecutingSUTCode(); + org.evosuite.runtime.agent.InstrumentingAgent.deactivate(); + org.evosuite.runtime.GuiSupport.restoreHeadlessMode(); + } + + + private static void initializeClasses() { + org.evosuite.runtime.classhandling.ClassStateSupport.initializeClasses(NetworkRollbackESTestscaffolding.class.getClassLoader() , + "org.openecomp.mso.entity.MsoRequest", + "org.openecomp.mso.openstack.beans.NetworkRollback" + ); + } + + private static void resetClasses() { + } +} diff --git a/adapters/mso-adapter-utils/src/test/java/org/openecomp/mso/openstack/beans/PoolESTest.java b/adapters/mso-adapter-utils/src/test/java/org/openecomp/mso/openstack/beans/PoolESTest.java new file mode 100644 index 0000000000..0ec588ded9 --- /dev/null +++ b/adapters/mso-adapter-utils/src/test/java/org/openecomp/mso/openstack/beans/PoolESTest.java @@ -0,0 +1,70 @@ +/* + * This file was automatically generated by EvoSuite + * Mon Nov 14 08:49:52 GMT 2016 + */ + +package org.openecomp.mso.openstack.beans; + +import org.junit.Test; +import static org.junit.Assert.*; + +import org.evosuite.runtime.EvoRunner; +import org.evosuite.runtime.EvoRunnerParameters; +import org.junit.runner.RunWith; + +@RunWith(EvoRunner.class) @EvoRunnerParameters(mockJVMNonDeterminism = true, useVFS = true, useVNET = true, resetStaticState = true, useJEE = true) +public class PoolESTest extends PoolESTestscaffolding { + + @Test(timeout = 4000) + public void test0() throws Throwable { + Pool pool0 = new Pool(); + pool0.setStart("Allocation_pool [start=null, end=null]"); + String string0 = pool0.getStart(); + assertEquals("Allocation_pool [start=null, end=null]", string0); + } + + @Test(timeout = 4000) + public void test1() throws Throwable { + Pool pool0 = new Pool(); + pool0.setEnd("Allocation_pool [start=null, end=null]"); + String string0 = pool0.getEnd(); + assertEquals("Allocation_pool [start=null, end=null]", string0); + } + + @Test(timeout = 4000) + public void test2() throws Throwable { + Pool pool0 = new Pool(); + String string0 = pool0.getEnd(); + assertNull(string0); + } + + @Test(timeout = 4000) + public void test3() throws Throwable { + Pool pool0 = new Pool(); + pool0.setStart(""); + String string0 = pool0.getStart(); + assertEquals("", string0); + } + + @Test(timeout = 4000) + public void test4() throws Throwable { + Pool pool0 = new Pool(); + String string0 = pool0.toString(); + assertEquals("Allocation_pool [start=null, end=null]", string0); + } + + @Test(timeout = 4000) + public void test5() throws Throwable { + Pool pool0 = new Pool(); + pool0.setEnd(""); + String string0 = pool0.getEnd(); + assertEquals("", string0); + } + + @Test(timeout = 4000) + public void test6() throws Throwable { + Pool pool0 = new Pool(); + String string0 = pool0.getStart(); + assertNull(string0); + } +} diff --git a/adapters/mso-adapter-utils/src/test/java/org/openecomp/mso/openstack/beans/PoolESTestscaffolding.java b/adapters/mso-adapter-utils/src/test/java/org/openecomp/mso/openstack/beans/PoolESTestscaffolding.java new file mode 100644 index 0000000000..8ce9cb88b7 --- /dev/null +++ b/adapters/mso-adapter-utils/src/test/java/org/openecomp/mso/openstack/beans/PoolESTestscaffolding.java @@ -0,0 +1,78 @@ +/** + * Scaffolding file used to store all the setups needed to run + * tests automatically generated by EvoSuite + * Mon Nov 14 08:49:52 GMT 2016 + */ + +package org.openecomp.mso.openstack.beans; + +import org.evosuite.runtime.annotation.EvoSuiteClassExclude; +import org.junit.BeforeClass; +import org.junit.Before; +import org.junit.After; +import org.junit.AfterClass; +import org.evosuite.runtime.sandbox.Sandbox; + +@EvoSuiteClassExclude +public class PoolESTestscaffolding { + + @org.junit.Rule + public org.evosuite.runtime.vnet.NonFunctionalRequirementRule nfr = new org.evosuite.runtime.vnet.NonFunctionalRequirementRule(); + + private static final java.util.Properties defaultProperties = (java.util.Properties) java.lang.System.getProperties().clone(); + + private org.evosuite.runtime.thread.ThreadStopper threadStopper = new org.evosuite.runtime.thread.ThreadStopper (org.evosuite.runtime.thread.KillSwitchHandler.getInstance(), 3000); + + @BeforeClass + public static void initEvoSuiteFramework() { + org.evosuite.runtime.RuntimeSettings.className = "org.openecomp.mso.openstack.beans.Pool"; + org.evosuite.runtime.GuiSupport.initialize(); + org.evosuite.runtime.RuntimeSettings.maxNumberOfThreads = 100; + org.evosuite.runtime.RuntimeSettings.maxNumberOfIterationsPerLoop = 10000; + org.evosuite.runtime.RuntimeSettings.mockSystemIn = true; + org.evosuite.runtime.RuntimeSettings.sandboxMode = org.evosuite.runtime.sandbox.Sandbox.SandboxMode.RECOMMENDED; + org.evosuite.runtime.sandbox.Sandbox.initializeSecurityManagerForSUT(); + org.evosuite.runtime.classhandling.JDKClassResetter.init(); + initializeClasses(); + org.evosuite.runtime.Runtime.getInstance().resetRuntime(); + } + + @AfterClass + public static void clearEvoSuiteFramework(){ + Sandbox.resetDefaultSecurityManager(); + java.lang.System.setProperties((java.util.Properties) defaultProperties.clone()); + } + + @Before + public void initTestCase(){ + threadStopper.storeCurrentThreads(); + threadStopper.startRecordingTime(); + org.evosuite.runtime.jvm.ShutdownHookHandler.getInstance().initHandler(); + org.evosuite.runtime.sandbox.Sandbox.goingToExecuteSUTCode(); + + org.evosuite.runtime.GuiSupport.setHeadless(); + org.evosuite.runtime.Runtime.getInstance().resetRuntime(); + org.evosuite.runtime.agent.InstrumentingAgent.activate(); + } + + @After + public void doneWithTestCase(){ + threadStopper.killAndJoinClientThreads(); + org.evosuite.runtime.jvm.ShutdownHookHandler.getInstance().safeExecuteAddedHooks(); + org.evosuite.runtime.classhandling.JDKClassResetter.reset(); + resetClasses(); + org.evosuite.runtime.sandbox.Sandbox.doneWithExecutingSUTCode(); + org.evosuite.runtime.agent.InstrumentingAgent.deactivate(); + org.evosuite.runtime.GuiSupport.restoreHeadlessMode(); + } + + + private static void initializeClasses() { + org.evosuite.runtime.classhandling.ClassStateSupport.initializeClasses(PoolESTestscaffolding.class.getClassLoader() , + "org.openecomp.mso.openstack.beans.Pool" + ); + } + + private static void resetClasses() { + } +} diff --git a/adapters/mso-adapter-utils/src/test/java/org/openecomp/mso/openstack/beans/SubnetESTest.java b/adapters/mso-adapter-utils/src/test/java/org/openecomp/mso/openstack/beans/SubnetESTest.java new file mode 100644 index 0000000000..7be8339439 --- /dev/null +++ b/adapters/mso-adapter-utils/src/test/java/org/openecomp/mso/openstack/beans/SubnetESTest.java @@ -0,0 +1,221 @@ +/* + * This file was automatically generated by EvoSuite + * Mon Nov 14 08:52:14 GMT 2016 + */ + +package org.openecomp.mso.openstack.beans; + +import org.junit.Test; +import static org.junit.Assert.*; + +import java.util.List; +import org.evosuite.runtime.EvoRunner; +import org.evosuite.runtime.EvoRunnerParameters; +import org.junit.runner.RunWith; + +@RunWith(EvoRunner.class) @EvoRunnerParameters(mockJVMNonDeterminism = true, useVFS = true, useVNET = true, resetStaticState = true, useJEE = true) +public class SubnetESTest extends SubnetESTestscaffolding { + + @Test(timeout = 4000) + public void test00() throws Throwable { + Subnet subnet0 = new Subnet(); + subnet0.setSubnetName("lu[c8x"); + subnet0.getSubnetName(); + assertEquals("4", subnet0.getIpVersion()); + } + + @Test(timeout = 4000) + public void test01() throws Throwable { + Subnet subnet0 = new Subnet(); + subnet0.setSubnetName(""); + subnet0.getSubnetName(); + assertEquals("4", subnet0.getIpVersion()); + } + + @Test(timeout = 4000) + public void test02() throws Throwable { + Subnet subnet0 = new Subnet(); + subnet0.setSubnetId("nL"); + subnet0.getSubnetId(); + assertEquals("4", subnet0.getIpVersion()); + } + + @Test(timeout = 4000) + public void test03() throws Throwable { + Subnet subnet0 = new Subnet(); + subnet0.setSubnetId(""); + subnet0.getSubnetId(); + assertEquals("4", subnet0.getIpVersion()); + } + + @Test(timeout = 4000) + public void test04() throws Throwable { + Subnet subnet0 = new Subnet(); + subnet0.setNeutronId("`jC)vXXeOG"); + subnet0.getNeutronId(); + assertEquals("4", subnet0.getIpVersion()); + } + + @Test(timeout = 4000) + public void test05() throws Throwable { + Subnet subnet0 = new Subnet(); + subnet0.setIpVersion(""); + String string0 = subnet0.getIpVersion(); + assertEquals("", string0); + } + + @Test(timeout = 4000) + public void test06() throws Throwable { + Subnet subnet0 = new Subnet(); + subnet0.setGatewayIp((String) null); + subnet0.getGatewayIp(); + assertEquals("4", subnet0.getIpVersion()); + } + + @Test(timeout = 4000) + public void test07() throws Throwable { + Subnet subnet0 = new Subnet(); + subnet0.setGatewayIp("Subnet [subnetName=null, neutronId=null, subnetId=null, cidr=null, gatewayIp=, ipVersion=4, enableDHCP=false, hostRoutes=null, allocationPools=null, dnsNameServers=null]"); + subnet0.getGatewayIp(); + assertEquals("4", subnet0.getIpVersion()); + } + + @Test(timeout = 4000) + public void test08() throws Throwable { + Subnet subnet0 = new Subnet(); + subnet0.setCidr("H3%q_*bOC2"); + subnet0.getCidr(); + assertEquals("4", subnet0.getIpVersion()); + } + + @Test(timeout = 4000) + public void test09() throws Throwable { + Subnet subnet0 = new Subnet(); + subnet0.setIpVersion((String) null); + String string0 = subnet0.getIpVersion(); + assertNull(string0); + } + + @Test(timeout = 4000) + public void test10() throws Throwable { + Subnet subnet0 = new Subnet(); + subnet0.setAllocationPools((List<Pool>) null); + assertEquals("4", subnet0.getIpVersion()); + } + + @Test(timeout = 4000) + public void test11() throws Throwable { + Subnet subnet0 = new Subnet(); + subnet0.getNeutronId(); + assertEquals("4", subnet0.getIpVersion()); + } + + @Test(timeout = 4000) + public void test12() throws Throwable { + Subnet subnet0 = new Subnet(); + subnet0.getHostRoutes(); + assertEquals("4", subnet0.getIpVersion()); + } + + @Test(timeout = 4000) + public void test13() throws Throwable { + Subnet subnet0 = new Subnet(); + String string0 = subnet0.toString(); + assertEquals("Subnet [subnetName=null, neutronId=null, subnetId=null, cidr=null, gatewayIp=, ipVersion=4, enableDHCP=false, hostRoutes=null, allocationPools=null, dnsNameServers=null]", string0); + } + + @Test(timeout = 4000) + public void test14() throws Throwable { + Subnet subnet0 = new Subnet(); + subnet0.getSubnetName(); + assertEquals("4", subnet0.getIpVersion()); + } + + @Test(timeout = 4000) + public void test15() throws Throwable { + Subnet subnet0 = new Subnet(); + subnet0.setNeutronId(""); + subnet0.getNeutronId(); + assertEquals("4", subnet0.getIpVersion()); + } + + @Test(timeout = 4000) + public void test16() throws Throwable { + Subnet subnet0 = new Subnet(); + subnet0.setCidr(""); + subnet0.getCidr(); + assertEquals("4", subnet0.getIpVersion()); + } + + @Test(timeout = 4000) + public void test17() throws Throwable { + Subnet subnet0 = new Subnet(); + subnet0.getDnsNameServers(); + assertEquals("4", subnet0.getIpVersion()); + } + + @Test(timeout = 4000) + public void test18() throws Throwable { + Subnet subnet0 = new Subnet(); + subnet0.setHostRoutes((List<String>) null); + assertEquals("4", subnet0.getIpVersion()); + } + + @Test(timeout = 4000) + public void test19() throws Throwable { + Subnet subnet0 = new Subnet(); + String string0 = subnet0.getIpVersion(); + assertEquals("4", string0); + } + + @Test(timeout = 4000) + public void test20() throws Throwable { + Subnet subnet0 = new Subnet(); + subnet0.getSubnetId(); + assertEquals("4", subnet0.getIpVersion()); + } + + @Test(timeout = 4000) + public void test21() throws Throwable { + Subnet subnet0 = new Subnet(); + subnet0.setEnableDHCP((Boolean) null); + subnet0.getEnableDHCP(); + assertEquals("4", subnet0.getIpVersion()); + } + + @Test(timeout = 4000) + public void test22() throws Throwable { + Subnet subnet0 = new Subnet(); + subnet0.getAllocationPools(); + assertEquals("4", subnet0.getIpVersion()); + } + + @Test(timeout = 4000) + public void test23() throws Throwable { + Subnet subnet0 = new Subnet(); + subnet0.getCidr(); + assertEquals("4", subnet0.getIpVersion()); + } + + @Test(timeout = 4000) + public void test24() throws Throwable { + Subnet subnet0 = new Subnet(); + subnet0.getGatewayIp(); + assertEquals("4", subnet0.getIpVersion()); + } + + @Test(timeout = 4000) + public void test25() throws Throwable { + Subnet subnet0 = new Subnet(); + subnet0.setDnsNameServers((List<String>) null); + assertEquals("4", subnet0.getIpVersion()); + } + + @Test(timeout = 4000) + public void test26() throws Throwable { + Subnet subnet0 = new Subnet(); + Boolean boolean0 = subnet0.getEnableDHCP(); + assertFalse(boolean0); + assertEquals("4", subnet0.getIpVersion()); + } +} diff --git a/adapters/mso-adapter-utils/src/test/java/org/openecomp/mso/openstack/beans/SubnetESTestscaffolding.java b/adapters/mso-adapter-utils/src/test/java/org/openecomp/mso/openstack/beans/SubnetESTestscaffolding.java new file mode 100644 index 0000000000..a9bf598355 --- /dev/null +++ b/adapters/mso-adapter-utils/src/test/java/org/openecomp/mso/openstack/beans/SubnetESTestscaffolding.java @@ -0,0 +1,79 @@ +/** + * Scaffolding file used to store all the setups needed to run + * tests automatically generated by EvoSuite + * Mon Nov 14 08:52:14 GMT 2016 + */ + +package org.openecomp.mso.openstack.beans; + +import org.evosuite.runtime.annotation.EvoSuiteClassExclude; +import org.junit.BeforeClass; +import org.junit.Before; +import org.junit.After; +import org.junit.AfterClass; +import org.evosuite.runtime.sandbox.Sandbox; + +@EvoSuiteClassExclude +public class SubnetESTestscaffolding { + + @org.junit.Rule + public org.evosuite.runtime.vnet.NonFunctionalRequirementRule nfr = new org.evosuite.runtime.vnet.NonFunctionalRequirementRule(); + + private static final java.util.Properties defaultProperties = (java.util.Properties) java.lang.System.getProperties().clone(); + + private org.evosuite.runtime.thread.ThreadStopper threadStopper = new org.evosuite.runtime.thread.ThreadStopper (org.evosuite.runtime.thread.KillSwitchHandler.getInstance(), 3000); + + @BeforeClass + public static void initEvoSuiteFramework() { + org.evosuite.runtime.RuntimeSettings.className = "org.openecomp.mso.openstack.beans.Subnet"; + org.evosuite.runtime.GuiSupport.initialize(); + org.evosuite.runtime.RuntimeSettings.maxNumberOfThreads = 100; + org.evosuite.runtime.RuntimeSettings.maxNumberOfIterationsPerLoop = 10000; + org.evosuite.runtime.RuntimeSettings.mockSystemIn = true; + org.evosuite.runtime.RuntimeSettings.sandboxMode = org.evosuite.runtime.sandbox.Sandbox.SandboxMode.RECOMMENDED; + org.evosuite.runtime.sandbox.Sandbox.initializeSecurityManagerForSUT(); + org.evosuite.runtime.classhandling.JDKClassResetter.init(); + initializeClasses(); + org.evosuite.runtime.Runtime.getInstance().resetRuntime(); + } + + @AfterClass + public static void clearEvoSuiteFramework(){ + Sandbox.resetDefaultSecurityManager(); + java.lang.System.setProperties((java.util.Properties) defaultProperties.clone()); + } + + @Before + public void initTestCase(){ + threadStopper.storeCurrentThreads(); + threadStopper.startRecordingTime(); + org.evosuite.runtime.jvm.ShutdownHookHandler.getInstance().initHandler(); + org.evosuite.runtime.sandbox.Sandbox.goingToExecuteSUTCode(); + + org.evosuite.runtime.GuiSupport.setHeadless(); + org.evosuite.runtime.Runtime.getInstance().resetRuntime(); + org.evosuite.runtime.agent.InstrumentingAgent.activate(); + } + + @After + public void doneWithTestCase(){ + threadStopper.killAndJoinClientThreads(); + org.evosuite.runtime.jvm.ShutdownHookHandler.getInstance().safeExecuteAddedHooks(); + org.evosuite.runtime.classhandling.JDKClassResetter.reset(); + resetClasses(); + org.evosuite.runtime.sandbox.Sandbox.doneWithExecutingSUTCode(); + org.evosuite.runtime.agent.InstrumentingAgent.deactivate(); + org.evosuite.runtime.GuiSupport.restoreHeadlessMode(); + } + + + private static void initializeClasses() { + org.evosuite.runtime.classhandling.ClassStateSupport.initializeClasses(SubnetESTestscaffolding.class.getClassLoader() , + "org.openecomp.mso.openstack.beans.Pool", + "org.openecomp.mso.openstack.beans.Subnet" + ); + } + + private static void resetClasses() { + } +} diff --git a/adapters/mso-adapter-utils/src/test/java/org/openecomp/mso/openstack/beans/VnfRollbackESTest.java b/adapters/mso-adapter-utils/src/test/java/org/openecomp/mso/openstack/beans/VnfRollbackESTest.java new file mode 100644 index 0000000000..e76ce410d4 --- /dev/null +++ b/adapters/mso-adapter-utils/src/test/java/org/openecomp/mso/openstack/beans/VnfRollbackESTest.java @@ -0,0 +1,403 @@ +/* + * This file was automatically generated by EvoSuite + * Mon Nov 14 08:51:17 GMT 2016 + */ + +package org.openecomp.mso.openstack.beans; + +import org.junit.Test; +import static org.junit.Assert.*; +import static org.evosuite.shaded.org.mockito.Mockito.*; + +import org.openecomp.mso.entity.MsoRequest; +import org.evosuite.runtime.EvoRunner; +import org.evosuite.runtime.EvoRunnerParameters; +import org.evosuite.runtime.ViolatedAssumptionAnswer; +import org.junit.runner.RunWith; + +@RunWith(EvoRunner.class) @EvoRunnerParameters(mockJVMNonDeterminism = true, useVFS = true, useVNET = true, resetStaticState = true, useJEE = true) +public class VnfRollbackESTest extends VnfRollbackESTestscaffolding { + + @Test(timeout = 4000) + public void test00() throws Throwable { + VnfRollback vnfRollback0 = new VnfRollback(); + vnfRollback0.setVolumeGroupName(", vnfCreated="); + vnfRollback0.getVolumeGroupName(); + assertFalse(vnfRollback0.getVnfCreated()); + assertFalse(vnfRollback0.getTenantCreated()); + assertFalse(vnfRollback0.isBase()); + } + + @Test(timeout = 4000) + public void test01() throws Throwable { + VnfRollback vnfRollback0 = new VnfRollback(); + vnfRollback0.setVolumeGroupId("}mvn2f6!r5FG1/_M~M"); + vnfRollback0.getVolumeGroupId(); + assertFalse(vnfRollback0.getVnfCreated()); + assertFalse(vnfRollback0.getTenantCreated()); + assertFalse(vnfRollback0.isBase()); + } + + @Test(timeout = 4000) + public void test02() throws Throwable { + VnfRollback vnfRollback0 = new VnfRollback(); + vnfRollback0.setVolumeGroupId(""); + vnfRollback0.getVolumeGroupId(); + assertFalse(vnfRollback0.getVnfCreated()); + assertFalse(vnfRollback0.getTenantCreated()); + assertFalse(vnfRollback0.isBase()); + } + + @Test(timeout = 4000) + public void test03() throws Throwable { + VnfRollback vnfRollback0 = new VnfRollback(); + vnfRollback0.setVolumeGroupHeatStackId("Z^t$4-eOKP9"); + vnfRollback0.getVolumeGroupHeatStackId(); + assertFalse(vnfRollback0.getVnfCreated()); + assertFalse(vnfRollback0.getTenantCreated()); + assertFalse(vnfRollback0.isBase()); + } + + @Test(timeout = 4000) + public void test04() throws Throwable { + VnfRollback vnfRollback0 = new VnfRollback(); + vnfRollback0.getVnfId(); + assertFalse(vnfRollback0.getTenantCreated()); + assertFalse(vnfRollback0.getVnfCreated()); + assertFalse(vnfRollback0.isBase()); + } + + @Test(timeout = 4000) + public void test05() throws Throwable { + VnfRollback vnfRollback0 = new VnfRollback(); + vnfRollback0.setVnfId(""); + vnfRollback0.getVnfId(); + assertFalse(vnfRollback0.isBase()); + assertFalse(vnfRollback0.getTenantCreated()); + assertFalse(vnfRollback0.getVnfCreated()); + } + + @Test(timeout = 4000) + public void test06() throws Throwable { + VnfRollback vnfRollback0 = new VnfRollback(); + vnfRollback0.setVfModuleStackId("8y*`!>A$@*l8#a>"); + vnfRollback0.getVfModuleStackId(); + assertFalse(vnfRollback0.getTenantCreated()); + assertFalse(vnfRollback0.isBase()); + assertFalse(vnfRollback0.getVnfCreated()); + } + + @Test(timeout = 4000) + public void test07() throws Throwable { + VnfRollback vnfRollback0 = new VnfRollback(); + vnfRollback0.setVfModuleStackId(""); + vnfRollback0.getVfModuleStackId(); + assertFalse(vnfRollback0.getTenantCreated()); + assertFalse(vnfRollback0.getVnfCreated()); + assertFalse(vnfRollback0.isBase()); + } + + @Test(timeout = 4000) + public void test08() throws Throwable { + VnfRollback vnfRollback0 = new VnfRollback(", tenant=", ", tenant=", ", tenant=", false, false, (MsoRequest) null, ", tenant=", "f5`2h^e^.-x", ", tenant="); + String string0 = vnfRollback0.getTenantId(); + assertFalse(vnfRollback0.getVnfCreated()); + assertEquals(", tenant=", vnfRollback0.getCloudSiteId()); + assertFalse(vnfRollback0.getTenantCreated()); + assertFalse(vnfRollback0.isBase()); + assertEquals(", tenant=", vnfRollback0.getRequestType()); + assertEquals("f5`2h^e^.-x", vnfRollback0.getVolumeGroupId()); + assertEquals(", tenant=", vnfRollback0.getVolumeGroupName()); + assertEquals(", tenant=", vnfRollback0.getVnfId()); + assertEquals(", tenant=", string0); + } + + @Test(timeout = 4000) + public void test09() throws Throwable { + VnfRollback vnfRollback0 = new VnfRollback(); + vnfRollback0.setTenantId(""); + vnfRollback0.getTenantId(); + assertFalse(vnfRollback0.isBase()); + assertFalse(vnfRollback0.getVnfCreated()); + assertFalse(vnfRollback0.getTenantCreated()); + } + + @Test(timeout = 4000) + public void test10() throws Throwable { + VnfRollback vnfRollback0 = new VnfRollback(); + assertFalse(vnfRollback0.getTenantCreated()); + + vnfRollback0.setTenantCreated(true); + boolean boolean0 = vnfRollback0.getTenantCreated(); + assertTrue(boolean0); + } + + @Test(timeout = 4000) + public void test11() throws Throwable { + MsoRequest msoRequest0 = mock(MsoRequest.class, new ViolatedAssumptionAnswer()); + VnfRollback vnfRollback0 = new VnfRollback("", ", vnf=", "Jvr", false, false, msoRequest0, "", "f'D", "VnfRollback: cloud="); + String string0 = vnfRollback0.getRequestType(); + assertFalse(vnfRollback0.isBase()); + assertEquals("Jvr", vnfRollback0.getCloudSiteId()); + assertEquals("", vnfRollback0.getVnfId()); + assertFalse(vnfRollback0.getTenantCreated()); + assertEquals("f'D", vnfRollback0.getVolumeGroupId()); + assertEquals(", vnf=", vnfRollback0.getTenantId()); + assertEquals("VnfRollback: cloud=", string0); + assertFalse(vnfRollback0.getVnfCreated()); + assertEquals("", vnfRollback0.getVolumeGroupName()); + } + + @Test(timeout = 4000) + public void test12() throws Throwable { + VnfRollback vnfRollback0 = new VnfRollback(); + vnfRollback0.setRequestType(""); + vnfRollback0.getRequestType(); + assertFalse(vnfRollback0.getVnfCreated()); + assertFalse(vnfRollback0.getTenantCreated()); + assertFalse(vnfRollback0.isBase()); + } + + @Test(timeout = 4000) + public void test13() throws Throwable { + MsoRequest msoRequest0 = mock(MsoRequest.class, new ViolatedAssumptionAnswer()); + doReturn("Jvr").when(msoRequest0).toString(); + VnfRollback vnfRollback0 = new VnfRollback("", ", vnf=", "Jvr", false, false, msoRequest0, "", "f'D", "VnfRollback: cloud="); + vnfRollback0.getMsoRequest(); + assertEquals("Jvr", vnfRollback0.getCloudSiteId()); + assertEquals("", vnfRollback0.getVnfId()); + assertFalse(vnfRollback0.isBase()); + assertEquals(", vnf=", vnfRollback0.getTenantId()); + assertEquals("", vnfRollback0.getVolumeGroupName()); + assertEquals("f'D", vnfRollback0.getVolumeGroupId()); + assertEquals("VnfRollback: cloud=", vnfRollback0.getRequestType()); + assertFalse(vnfRollback0.getVnfCreated()); + assertFalse(vnfRollback0.getTenantCreated()); + } + + @Test(timeout = 4000) + public void test14() throws Throwable { + VnfRollback vnfRollback0 = new VnfRollback(", tenant=", ", tenant=", ", tenant=", false, false, (MsoRequest) null, ", tenant=", "f5`2h^e^.-x", ", tenant="); + String string0 = vnfRollback0.getCloudSiteId(); + assertFalse(vnfRollback0.isBase()); + assertEquals(", tenant=", string0); + assertEquals("f5`2h^e^.-x", vnfRollback0.getVolumeGroupId()); + assertFalse(vnfRollback0.getVnfCreated()); + assertEquals(", tenant=", vnfRollback0.getVnfId()); + assertFalse(vnfRollback0.getTenantCreated()); + assertEquals(", tenant=", vnfRollback0.getVolumeGroupName()); + assertEquals(", tenant=", vnfRollback0.getRequestType()); + assertEquals(", tenant=", vnfRollback0.getTenantId()); + } + + @Test(timeout = 4000) + public void test15() throws Throwable { + VnfRollback vnfRollback0 = new VnfRollback(); + vnfRollback0.setCloudSiteId(""); + vnfRollback0.getCloudSiteId(); + assertFalse(vnfRollback0.getVnfCreated()); + assertFalse(vnfRollback0.isBase()); + assertFalse(vnfRollback0.getTenantCreated()); + } + + @Test(timeout = 4000) + public void test16() throws Throwable { + VnfRollback vnfRollback0 = new VnfRollback(); + vnfRollback0.setBaseGroupHeatStackId("3(6Q^)Ic kf:zj"); + vnfRollback0.getBaseGroupHeatStackId(); + assertFalse(vnfRollback0.isBase()); + assertFalse(vnfRollback0.getTenantCreated()); + assertFalse(vnfRollback0.getVnfCreated()); + } + + @Test(timeout = 4000) + public void test17() throws Throwable { + VnfRollback vnfRollback0 = new VnfRollback(); + vnfRollback0.setBaseGroupHeatStackId(""); + vnfRollback0.getBaseGroupHeatStackId(); + assertFalse(vnfRollback0.isBase()); + assertFalse(vnfRollback0.getVnfCreated()); + assertFalse(vnfRollback0.getTenantCreated()); + } + + @Test(timeout = 4000) + public void test18() throws Throwable { + VnfRollback vnfRollback0 = new VnfRollback(); + assertFalse(vnfRollback0.isBase()); + + vnfRollback0.setIsBase(true); + boolean boolean0 = vnfRollback0.isBase(); + assertTrue(boolean0); + } + + @Test(timeout = 4000) + public void test19() throws Throwable { + VnfRollback vnfRollback0 = new VnfRollback(); + vnfRollback0.getVfModuleStackId(); + assertFalse(vnfRollback0.isBase()); + assertFalse(vnfRollback0.getTenantCreated()); + assertFalse(vnfRollback0.getVnfCreated()); + } + + @Test(timeout = 4000) + public void test20() throws Throwable { + VnfRollback vnfRollback0 = new VnfRollback(); + vnfRollback0.getVolumeGroupName(); + assertFalse(vnfRollback0.getVnfCreated()); + assertFalse(vnfRollback0.isBase()); + assertFalse(vnfRollback0.getTenantCreated()); + } + + @Test(timeout = 4000) + public void test21() throws Throwable { + VnfRollback vnfRollback0 = new VnfRollback(); + vnfRollback0.setVolumeGroupName(""); + vnfRollback0.getVolumeGroupName(); + assertFalse(vnfRollback0.isBase()); + assertFalse(vnfRollback0.getTenantCreated()); + assertFalse(vnfRollback0.getVnfCreated()); + } + + @Test(timeout = 4000) + public void test22() throws Throwable { + VnfRollback vnfRollback0 = new VnfRollback(); + boolean boolean0 = vnfRollback0.getTenantCreated(); + assertFalse(vnfRollback0.getVnfCreated()); + assertFalse(boolean0); + assertFalse(vnfRollback0.isBase()); + } + + @Test(timeout = 4000) + public void test23() throws Throwable { + VnfRollback vnfRollback0 = new VnfRollback(); + boolean boolean0 = vnfRollback0.isBase(); + assertFalse(vnfRollback0.getVnfCreated()); + assertFalse(vnfRollback0.getTenantCreated()); + assertFalse(boolean0); + } + + @Test(timeout = 4000) + public void test24() throws Throwable { + VnfRollback vnfRollback0 = new VnfRollback(); + String string0 = vnfRollback0.toString(); + assertFalse(vnfRollback0.isBase()); + assertEquals("VnfRollback: cloud=null, tenant=null, vnf=null, tenantCreated=false, vnfCreated=false, requestType = null", string0); + } + + @Test(timeout = 4000) + public void test25() throws Throwable { + VnfRollback vnfRollback0 = new VnfRollback(); + boolean boolean0 = vnfRollback0.getVnfCreated(); + assertFalse(vnfRollback0.getTenantCreated()); + assertFalse(boolean0); + assertFalse(vnfRollback0.isBase()); + } + + @Test(timeout = 4000) + public void test26() throws Throwable { + VnfRollback vnfRollback0 = new VnfRollback(); + vnfRollback0.getVolumeGroupHeatStackId(); + assertFalse(vnfRollback0.getTenantCreated()); + assertFalse(vnfRollback0.getVnfCreated()); + assertFalse(vnfRollback0.isBase()); + } + + @Test(timeout = 4000) + public void test27() throws Throwable { + VnfRollback vnfRollback0 = new VnfRollback(); + vnfRollback0.getBaseGroupHeatStackId(); + assertFalse(vnfRollback0.getTenantCreated()); + assertFalse(vnfRollback0.getVnfCreated()); + assertFalse(vnfRollback0.isBase()); + } + + @Test(timeout = 4000) + public void test28() throws Throwable { + VnfRollback vnfRollback0 = new VnfRollback(); + vnfRollback0.getCloudSiteId(); + assertFalse(vnfRollback0.isBase()); + assertFalse(vnfRollback0.getTenantCreated()); + assertFalse(vnfRollback0.getVnfCreated()); + } + + @Test(timeout = 4000) + public void test29() throws Throwable { + VnfRollback vnfRollback0 = new VnfRollback(); + vnfRollback0.getTenantId(); + assertFalse(vnfRollback0.getTenantCreated()); + assertFalse(vnfRollback0.isBase()); + assertFalse(vnfRollback0.getVnfCreated()); + } + + @Test(timeout = 4000) + public void test30() throws Throwable { + VnfRollback vnfRollback0 = new VnfRollback(); + MsoRequest msoRequest0 = mock(MsoRequest.class, new ViolatedAssumptionAnswer()); + vnfRollback0.setMsoRequest(msoRequest0); + assertFalse(vnfRollback0.getTenantCreated()); + assertFalse(vnfRollback0.getVnfCreated()); + assertFalse(vnfRollback0.isBase()); + } + + @Test(timeout = 4000) + public void test31() throws Throwable { + VnfRollback vnfRollback0 = new VnfRollback(); + vnfRollback0.getMsoRequest(); + assertFalse(vnfRollback0.getTenantCreated()); + assertFalse(vnfRollback0.getVnfCreated()); + assertFalse(vnfRollback0.isBase()); + } + + @Test(timeout = 4000) + public void test32() throws Throwable { + VnfRollback vnfRollback0 = new VnfRollback(); + assertFalse(vnfRollback0.getVnfCreated()); + + vnfRollback0.setVnfCreated(true); + boolean boolean0 = vnfRollback0.getVnfCreated(); + assertTrue(boolean0); + } + + @Test(timeout = 4000) + public void test33() throws Throwable { + VnfRollback vnfRollback0 = new VnfRollback(); + vnfRollback0.getVolumeGroupId(); + assertFalse(vnfRollback0.getVnfCreated()); + assertFalse(vnfRollback0.getTenantCreated()); + assertFalse(vnfRollback0.isBase()); + } + + @Test(timeout = 4000) + public void test34() throws Throwable { + VnfRollback vnfRollback0 = new VnfRollback(); + vnfRollback0.getRequestType(); + assertFalse(vnfRollback0.isBase()); + assertFalse(vnfRollback0.getTenantCreated()); + assertFalse(vnfRollback0.getVnfCreated()); + } + + @Test(timeout = 4000) + public void test35() throws Throwable { + VnfRollback vnfRollback0 = new VnfRollback(); + vnfRollback0.setVolumeGroupHeatStackId(""); + vnfRollback0.getVolumeGroupHeatStackId(); + assertFalse(vnfRollback0.isBase()); + assertFalse(vnfRollback0.getTenantCreated()); + assertFalse(vnfRollback0.getVnfCreated()); + } + + @Test(timeout = 4000) + public void test36() throws Throwable { + VnfRollback vnfRollback0 = new VnfRollback(", tenant=", ", tenant=", ", tenant=", false, false, (MsoRequest) null, ", tenant=", "f5`2h^e^.-x", ", tenant="); + String string0 = vnfRollback0.getVnfId(); + assertEquals(", tenant=", string0); + assertEquals(", tenant=", vnfRollback0.getTenantId()); + assertFalse(vnfRollback0.getVnfCreated()); + assertFalse(vnfRollback0.isBase()); + assertFalse(vnfRollback0.getTenantCreated()); + assertEquals(", tenant=", vnfRollback0.getCloudSiteId()); + assertEquals(", tenant=", vnfRollback0.getVolumeGroupName()); + assertEquals(", tenant=", vnfRollback0.getRequestType()); + assertEquals("f5`2h^e^.-x", vnfRollback0.getVolumeGroupId()); + } +} diff --git a/adapters/mso-adapter-utils/src/test/java/org/openecomp/mso/openstack/beans/VnfRollbackESTestscaffolding.java b/adapters/mso-adapter-utils/src/test/java/org/openecomp/mso/openstack/beans/VnfRollbackESTestscaffolding.java new file mode 100644 index 0000000000..e07b2cfee3 --- /dev/null +++ b/adapters/mso-adapter-utils/src/test/java/org/openecomp/mso/openstack/beans/VnfRollbackESTestscaffolding.java @@ -0,0 +1,79 @@ +/** + * Scaffolding file used to store all the setups needed to run + * tests automatically generated by EvoSuite + * Mon Nov 14 08:51:17 GMT 2016 + */ + +package org.openecomp.mso.openstack.beans; + +import org.evosuite.runtime.annotation.EvoSuiteClassExclude; +import org.junit.BeforeClass; +import org.junit.Before; +import org.junit.After; +import org.junit.AfterClass; +import org.evosuite.runtime.sandbox.Sandbox; + +@EvoSuiteClassExclude +public class VnfRollbackESTestscaffolding { + + @org.junit.Rule + public org.evosuite.runtime.vnet.NonFunctionalRequirementRule nfr = new org.evosuite.runtime.vnet.NonFunctionalRequirementRule(); + + private static final java.util.Properties defaultProperties = (java.util.Properties) java.lang.System.getProperties().clone(); + + private org.evosuite.runtime.thread.ThreadStopper threadStopper = new org.evosuite.runtime.thread.ThreadStopper (org.evosuite.runtime.thread.KillSwitchHandler.getInstance(), 3000); + + @BeforeClass + public static void initEvoSuiteFramework() { + org.evosuite.runtime.RuntimeSettings.className = "org.openecomp.mso.openstack.beans.VnfRollback"; + org.evosuite.runtime.GuiSupport.initialize(); + org.evosuite.runtime.RuntimeSettings.maxNumberOfThreads = 100; + org.evosuite.runtime.RuntimeSettings.maxNumberOfIterationsPerLoop = 10000; + org.evosuite.runtime.RuntimeSettings.mockSystemIn = true; + org.evosuite.runtime.RuntimeSettings.sandboxMode = org.evosuite.runtime.sandbox.Sandbox.SandboxMode.RECOMMENDED; + org.evosuite.runtime.sandbox.Sandbox.initializeSecurityManagerForSUT(); + org.evosuite.runtime.classhandling.JDKClassResetter.init(); + initializeClasses(); + org.evosuite.runtime.Runtime.getInstance().resetRuntime(); + } + + @AfterClass + public static void clearEvoSuiteFramework(){ + Sandbox.resetDefaultSecurityManager(); + java.lang.System.setProperties((java.util.Properties) defaultProperties.clone()); + } + + @Before + public void initTestCase(){ + threadStopper.storeCurrentThreads(); + threadStopper.startRecordingTime(); + org.evosuite.runtime.jvm.ShutdownHookHandler.getInstance().initHandler(); + org.evosuite.runtime.sandbox.Sandbox.goingToExecuteSUTCode(); + + org.evosuite.runtime.GuiSupport.setHeadless(); + org.evosuite.runtime.Runtime.getInstance().resetRuntime(); + org.evosuite.runtime.agent.InstrumentingAgent.activate(); + } + + @After + public void doneWithTestCase(){ + threadStopper.killAndJoinClientThreads(); + org.evosuite.runtime.jvm.ShutdownHookHandler.getInstance().safeExecuteAddedHooks(); + org.evosuite.runtime.classhandling.JDKClassResetter.reset(); + resetClasses(); + org.evosuite.runtime.sandbox.Sandbox.doneWithExecutingSUTCode(); + org.evosuite.runtime.agent.InstrumentingAgent.deactivate(); + org.evosuite.runtime.GuiSupport.restoreHeadlessMode(); + } + + + private static void initializeClasses() { + org.evosuite.runtime.classhandling.ClassStateSupport.initializeClasses(VnfRollbackESTestscaffolding.class.getClassLoader() , + "org.openecomp.mso.openstack.beans.VnfRollback", + "org.openecomp.mso.entity.MsoRequest" + ); + } + + private static void resetClasses() { + } +} diff --git a/adapters/mso-adapter-utils/src/test/java/org/openecomp/mso/openstack/exceptions/MsoAdapterExceptionESTest.java b/adapters/mso-adapter-utils/src/test/java/org/openecomp/mso/openstack/exceptions/MsoAdapterExceptionESTest.java new file mode 100644 index 0000000000..ccc5a949b7 --- /dev/null +++ b/adapters/mso-adapter-utils/src/test/java/org/openecomp/mso/openstack/exceptions/MsoAdapterExceptionESTest.java @@ -0,0 +1,24 @@ +/* + * This file was automatically generated by EvoSuite + * Mon Nov 14 08:51:02 GMT 2016 + */ + +package org.openecomp.mso.openstack.exceptions; + +import org.junit.Test; +import static org.junit.Assert.*; + +import org.evosuite.runtime.EvoRunner; +import org.evosuite.runtime.EvoRunnerParameters; +import org.junit.runner.RunWith; + +@RunWith(EvoRunner.class) @EvoRunnerParameters(mockJVMNonDeterminism = true, useVFS = true, useVNET = true, resetStaticState = true, useJEE = true) +public class MsoAdapterExceptionESTest extends MsoAdapterExceptionESTestscaffolding { + + @Test(timeout = 4000) + public void test0() throws Throwable { + MsoAdapterException msoAdapterException0 = new MsoAdapterException(""); + MsoAdapterException msoAdapterException1 = new MsoAdapterException("", (Throwable) msoAdapterException0); + assertFalse(msoAdapterException1.equals((Object)msoAdapterException0)); + } +} diff --git a/adapters/mso-adapter-utils/src/test/java/org/openecomp/mso/openstack/exceptions/MsoAdapterExceptionESTestscaffolding.java b/adapters/mso-adapter-utils/src/test/java/org/openecomp/mso/openstack/exceptions/MsoAdapterExceptionESTestscaffolding.java new file mode 100644 index 0000000000..657b8b28c4 --- /dev/null +++ b/adapters/mso-adapter-utils/src/test/java/org/openecomp/mso/openstack/exceptions/MsoAdapterExceptionESTestscaffolding.java @@ -0,0 +1,87 @@ +/** + * Scaffolding file used to store all the setups needed to run + * tests automatically generated by EvoSuite + * Mon Nov 14 08:51:02 GMT 2016 + */ + +package org.openecomp.mso.openstack.exceptions; + +import org.evosuite.runtime.annotation.EvoSuiteClassExclude; +import org.junit.BeforeClass; +import org.junit.Before; +import org.junit.After; +import org.junit.AfterClass; +import org.evosuite.runtime.sandbox.Sandbox; + +@EvoSuiteClassExclude +public class MsoAdapterExceptionESTestscaffolding { + + @org.junit.Rule + public org.evosuite.runtime.vnet.NonFunctionalRequirementRule nfr = new org.evosuite.runtime.vnet.NonFunctionalRequirementRule(); + + private static final java.util.Properties defaultProperties = (java.util.Properties) java.lang.System.getProperties().clone(); + + private org.evosuite.runtime.thread.ThreadStopper threadStopper = new org.evosuite.runtime.thread.ThreadStopper (org.evosuite.runtime.thread.KillSwitchHandler.getInstance(), 3000); + + @BeforeClass + public static void initEvoSuiteFramework() { + org.evosuite.runtime.RuntimeSettings.className = "org.openecomp.mso.openstack.exceptions.MsoAdapterException"; + org.evosuite.runtime.GuiSupport.initialize(); + org.evosuite.runtime.RuntimeSettings.maxNumberOfThreads = 100; + org.evosuite.runtime.RuntimeSettings.maxNumberOfIterationsPerLoop = 10000; + org.evosuite.runtime.RuntimeSettings.mockSystemIn = true; + org.evosuite.runtime.RuntimeSettings.sandboxMode = org.evosuite.runtime.sandbox.Sandbox.SandboxMode.RECOMMENDED; + org.evosuite.runtime.sandbox.Sandbox.initializeSecurityManagerForSUT(); + org.evosuite.runtime.classhandling.JDKClassResetter.init(); + initializeClasses(); + org.evosuite.runtime.Runtime.getInstance().resetRuntime(); + } + + @AfterClass + public static void clearEvoSuiteFramework(){ + Sandbox.resetDefaultSecurityManager(); + java.lang.System.setProperties((java.util.Properties) defaultProperties.clone()); + } + + @Before + public void initTestCase(){ + threadStopper.storeCurrentThreads(); + threadStopper.startRecordingTime(); + org.evosuite.runtime.jvm.ShutdownHookHandler.getInstance().initHandler(); + org.evosuite.runtime.sandbox.Sandbox.goingToExecuteSUTCode(); + + org.evosuite.runtime.GuiSupport.setHeadless(); + org.evosuite.runtime.Runtime.getInstance().resetRuntime(); + org.evosuite.runtime.agent.InstrumentingAgent.activate(); + } + + @After + public void doneWithTestCase(){ + threadStopper.killAndJoinClientThreads(); + org.evosuite.runtime.jvm.ShutdownHookHandler.getInstance().safeExecuteAddedHooks(); + org.evosuite.runtime.classhandling.JDKClassResetter.reset(); + resetClasses(); + org.evosuite.runtime.sandbox.Sandbox.doneWithExecutingSUTCode(); + org.evosuite.runtime.agent.InstrumentingAgent.deactivate(); + org.evosuite.runtime.GuiSupport.restoreHeadlessMode(); + } + + + private static void initializeClasses() { + org.evosuite.runtime.classhandling.ClassStateSupport.initializeClasses(MsoAdapterExceptionESTestscaffolding.class.getClassLoader() , + "org.openecomp.mso.openstack.exceptions.MsoExceptionCategory", + "org.openecomp.mso.openstack.exceptions.MsoException", + "org.openecomp.mso.openstack.exceptions.MsoAdapterException" + ); + } + + private static void resetClasses() { + org.evosuite.runtime.classhandling.ClassResetter.getInstance().setClassLoader(MsoAdapterExceptionESTestscaffolding.class.getClassLoader()); + + org.evosuite.runtime.classhandling.ClassStateSupport.resetClasses( + "org.openecomp.mso.openstack.exceptions.MsoExceptionCategory", + "org.openecomp.mso.openstack.exceptions.MsoException", + "org.openecomp.mso.openstack.exceptions.MsoAdapterException" + ); + } +} diff --git a/adapters/mso-adapter-utils/src/test/java/org/openecomp/mso/openstack/exceptions/MsoCloudSiteNotFoundESTest.java b/adapters/mso-adapter-utils/src/test/java/org/openecomp/mso/openstack/exceptions/MsoCloudSiteNotFoundESTest.java new file mode 100644 index 0000000000..f840c12025 --- /dev/null +++ b/adapters/mso-adapter-utils/src/test/java/org/openecomp/mso/openstack/exceptions/MsoCloudSiteNotFoundESTest.java @@ -0,0 +1,30 @@ +/* + * This file was automatically generated by EvoSuite + * Mon Nov 14 08:56:48 GMT 2016 + */ + +package org.openecomp.mso.openstack.exceptions; + +import org.junit.Test; +import static org.junit.Assert.*; + +import org.evosuite.runtime.EvoRunner; +import org.evosuite.runtime.EvoRunnerParameters; +import org.junit.runner.RunWith; + +@RunWith(EvoRunner.class) @EvoRunnerParameters(mockJVMNonDeterminism = true, useVFS = true, useVNET = true, resetStaticState = true, useJEE = true) +public class MsoCloudSiteNotFoundESTest extends MsoCloudSiteNotFoundESTestscaffolding { + + @Test(timeout = 4000) + public void test0() throws Throwable { + MsoCloudSiteNotFound msoCloudSiteNotFound0 = new MsoCloudSiteNotFound(); + assertEquals(MsoExceptionCategory.USERDATA, msoCloudSiteNotFound0.getCategory()); + } + + @Test(timeout = 4000) + public void test1() throws Throwable { + MsoCloudSiteNotFound msoCloudSiteNotFound0 = new MsoCloudSiteNotFound("NQz5T^"); + String string0 = msoCloudSiteNotFound0.toString(); + assertEquals("Cloud Site [NQz5T^] not found", string0); + } +} diff --git a/adapters/mso-adapter-utils/src/test/java/org/openecomp/mso/openstack/exceptions/MsoCloudSiteNotFoundESTestscaffolding.java b/adapters/mso-adapter-utils/src/test/java/org/openecomp/mso/openstack/exceptions/MsoCloudSiteNotFoundESTestscaffolding.java new file mode 100644 index 0000000000..ba287051dd --- /dev/null +++ b/adapters/mso-adapter-utils/src/test/java/org/openecomp/mso/openstack/exceptions/MsoCloudSiteNotFoundESTestscaffolding.java @@ -0,0 +1,87 @@ +/** + * Scaffolding file used to store all the setups needed to run + * tests automatically generated by EvoSuite + * Mon Nov 14 08:56:48 GMT 2016 + */ + +package org.openecomp.mso.openstack.exceptions; + +import org.evosuite.runtime.annotation.EvoSuiteClassExclude; +import org.junit.BeforeClass; +import org.junit.Before; +import org.junit.After; +import org.junit.AfterClass; +import org.evosuite.runtime.sandbox.Sandbox; + +@EvoSuiteClassExclude +public class MsoCloudSiteNotFoundESTestscaffolding { + + @org.junit.Rule + public org.evosuite.runtime.vnet.NonFunctionalRequirementRule nfr = new org.evosuite.runtime.vnet.NonFunctionalRequirementRule(); + + private static final java.util.Properties defaultProperties = (java.util.Properties) java.lang.System.getProperties().clone(); + + private org.evosuite.runtime.thread.ThreadStopper threadStopper = new org.evosuite.runtime.thread.ThreadStopper (org.evosuite.runtime.thread.KillSwitchHandler.getInstance(), 3000); + + @BeforeClass + public static void initEvoSuiteFramework() { + org.evosuite.runtime.RuntimeSettings.className = "org.openecomp.mso.openstack.exceptions.MsoCloudSiteNotFound"; + org.evosuite.runtime.GuiSupport.initialize(); + org.evosuite.runtime.RuntimeSettings.maxNumberOfThreads = 100; + org.evosuite.runtime.RuntimeSettings.maxNumberOfIterationsPerLoop = 10000; + org.evosuite.runtime.RuntimeSettings.mockSystemIn = true; + org.evosuite.runtime.RuntimeSettings.sandboxMode = org.evosuite.runtime.sandbox.Sandbox.SandboxMode.RECOMMENDED; + org.evosuite.runtime.sandbox.Sandbox.initializeSecurityManagerForSUT(); + org.evosuite.runtime.classhandling.JDKClassResetter.init(); + initializeClasses(); + org.evosuite.runtime.Runtime.getInstance().resetRuntime(); + } + + @AfterClass + public static void clearEvoSuiteFramework(){ + Sandbox.resetDefaultSecurityManager(); + java.lang.System.setProperties((java.util.Properties) defaultProperties.clone()); + } + + @Before + public void initTestCase(){ + threadStopper.storeCurrentThreads(); + threadStopper.startRecordingTime(); + org.evosuite.runtime.jvm.ShutdownHookHandler.getInstance().initHandler(); + org.evosuite.runtime.sandbox.Sandbox.goingToExecuteSUTCode(); + + org.evosuite.runtime.GuiSupport.setHeadless(); + org.evosuite.runtime.Runtime.getInstance().resetRuntime(); + org.evosuite.runtime.agent.InstrumentingAgent.activate(); + } + + @After + public void doneWithTestCase(){ + threadStopper.killAndJoinClientThreads(); + org.evosuite.runtime.jvm.ShutdownHookHandler.getInstance().safeExecuteAddedHooks(); + org.evosuite.runtime.classhandling.JDKClassResetter.reset(); + resetClasses(); + org.evosuite.runtime.sandbox.Sandbox.doneWithExecutingSUTCode(); + org.evosuite.runtime.agent.InstrumentingAgent.deactivate(); + org.evosuite.runtime.GuiSupport.restoreHeadlessMode(); + } + + + private static void initializeClasses() { + org.evosuite.runtime.classhandling.ClassStateSupport.initializeClasses(MsoCloudSiteNotFoundESTestscaffolding.class.getClassLoader() , + "org.openecomp.mso.openstack.exceptions.MsoExceptionCategory", + "org.openecomp.mso.openstack.exceptions.MsoCloudSiteNotFound", + "org.openecomp.mso.openstack.exceptions.MsoException" + ); + } + + private static void resetClasses() { + org.evosuite.runtime.classhandling.ClassResetter.getInstance().setClassLoader(MsoCloudSiteNotFoundESTestscaffolding.class.getClassLoader()); + + org.evosuite.runtime.classhandling.ClassStateSupport.resetClasses( + "org.openecomp.mso.openstack.exceptions.MsoExceptionCategory", + "org.openecomp.mso.openstack.exceptions.MsoException", + "org.openecomp.mso.openstack.exceptions.MsoCloudSiteNotFound" + ); + } +} diff --git a/adapters/mso-adapter-utils/src/test/java/org/openecomp/mso/openstack/exceptions/MsoExceptionESTest.java b/adapters/mso-adapter-utils/src/test/java/org/openecomp/mso/openstack/exceptions/MsoExceptionESTest.java new file mode 100644 index 0000000000..2bd71fb525 --- /dev/null +++ b/adapters/mso-adapter-utils/src/test/java/org/openecomp/mso/openstack/exceptions/MsoExceptionESTest.java @@ -0,0 +1,77 @@ +/* + * This file was automatically generated by EvoSuite + * Mon Nov 14 08:48:01 GMT 2016 + */ + +package org.openecomp.mso.openstack.exceptions; + +import org.junit.Test; +import static org.junit.Assert.*; + +import org.evosuite.runtime.EvoRunner; +import org.evosuite.runtime.EvoRunnerParameters; +import org.junit.runner.RunWith; + +@RunWith(EvoRunner.class) @EvoRunnerParameters(mockJVMNonDeterminism = true, useVFS = true, useVNET = true, resetStaticState = true, useJEE = true) +public class MsoExceptionESTest extends MsoExceptionESTestscaffolding { + + @Test(timeout = 4000) + public void test0() throws Throwable { + MsoTenantNotFound msoTenantNotFound0 = new MsoTenantNotFound("T&~q", "Cloud Site ["); + MsoIOException msoIOException0 = new MsoIOException("", (Throwable) msoTenantNotFound0); + String string0 = msoIOException0.getContextMessage(); + assertEquals("", string0); + } + + @Test(timeout = 4000) + public void test1() throws Throwable { + MsoNetworkNotFound msoNetworkNotFound0 = new MsoNetworkNotFound("", "", ""); + msoNetworkNotFound0.addContext(""); + String string0 = msoNetworkNotFound0.getContext(); + assertEquals("", string0); + assertNotNull(string0); + } + + @Test(timeout = 4000) + public void test2() throws Throwable { + MsoAdapterException msoAdapterException0 = new MsoAdapterException(" "); + msoAdapterException0.setContext(" "); + String string0 = msoAdapterException0.getContextMessage(); + assertEquals("[ ] ", string0); + } + + @Test(timeout = 4000) + public void test3() throws Throwable { + MsoCloudSiteNotFound msoCloudSiteNotFound0 = new MsoCloudSiteNotFound(); + MsoAdapterException msoAdapterException0 = new MsoAdapterException("", (Throwable) msoCloudSiteNotFound0); + msoAdapterException0.addContext(""); + msoAdapterException0.addContext(""); + String string0 = msoAdapterException0.getContext(); + assertEquals(":", msoAdapterException0.getContext()); + assertNotNull(string0); + } + + @Test(timeout = 4000) + public void test4() throws Throwable { + MsoCloudSiteNotFound msoCloudSiteNotFound0 = new MsoCloudSiteNotFound((String) null); + MsoExceptionCategory msoExceptionCategory0 = msoCloudSiteNotFound0.getCategory(); + MsoAdapterException msoAdapterException0 = new MsoAdapterException((String) null, (Throwable) msoCloudSiteNotFound0); + msoAdapterException0.setCategory(msoExceptionCategory0); + assertNull(msoAdapterException0.getContext()); + } + + @Test(timeout = 4000) + public void test5() throws Throwable { + MsoNetworkNotFound msoNetworkNotFound0 = new MsoNetworkNotFound("", "", ""); + String string0 = msoNetworkNotFound0.getContext(); + assertNull(string0); + } + + @Test(timeout = 4000) + public void test6() throws Throwable { + MsoCloudSiteNotFound msoCloudSiteNotFound0 = new MsoCloudSiteNotFound((String) null); + MsoAdapterException msoAdapterException0 = new MsoAdapterException((String) null, (Throwable) msoCloudSiteNotFound0); + String string0 = msoAdapterException0.getContextMessage(); + assertNull(string0); + } +} diff --git a/adapters/mso-adapter-utils/src/test/java/org/openecomp/mso/openstack/exceptions/MsoExceptionESTestscaffolding.java b/adapters/mso-adapter-utils/src/test/java/org/openecomp/mso/openstack/exceptions/MsoExceptionESTestscaffolding.java new file mode 100644 index 0000000000..8ce85b76bf --- /dev/null +++ b/adapters/mso-adapter-utils/src/test/java/org/openecomp/mso/openstack/exceptions/MsoExceptionESTestscaffolding.java @@ -0,0 +1,101 @@ +/** + * Scaffolding file used to store all the setups needed to run + * tests automatically generated by EvoSuite + * Mon Nov 14 08:48:01 GMT 2016 + */ + +package org.openecomp.mso.openstack.exceptions; + +import org.evosuite.runtime.annotation.EvoSuiteClassExclude; +import org.junit.BeforeClass; +import org.junit.Before; +import org.junit.After; +import org.junit.AfterClass; +import org.evosuite.runtime.sandbox.Sandbox; + +@EvoSuiteClassExclude +public class MsoExceptionESTestscaffolding { + + @org.junit.Rule + public org.evosuite.runtime.vnet.NonFunctionalRequirementRule nfr = new org.evosuite.runtime.vnet.NonFunctionalRequirementRule(); + + private static final java.util.Properties defaultProperties = (java.util.Properties) java.lang.System.getProperties().clone(); + + private org.evosuite.runtime.thread.ThreadStopper threadStopper = new org.evosuite.runtime.thread.ThreadStopper (org.evosuite.runtime.thread.KillSwitchHandler.getInstance(), 3000); + + @BeforeClass + public static void initEvoSuiteFramework() { + org.evosuite.runtime.RuntimeSettings.className = "org.openecomp.mso.openstack.exceptions.MsoException"; + org.evosuite.runtime.GuiSupport.initialize(); + org.evosuite.runtime.RuntimeSettings.maxNumberOfThreads = 100; + org.evosuite.runtime.RuntimeSettings.maxNumberOfIterationsPerLoop = 10000; + org.evosuite.runtime.RuntimeSettings.mockSystemIn = true; + org.evosuite.runtime.RuntimeSettings.sandboxMode = org.evosuite.runtime.sandbox.Sandbox.SandboxMode.RECOMMENDED; + org.evosuite.runtime.sandbox.Sandbox.initializeSecurityManagerForSUT(); + org.evosuite.runtime.classhandling.JDKClassResetter.init(); + initializeClasses(); + org.evosuite.runtime.Runtime.getInstance().resetRuntime(); + } + + @AfterClass + public static void clearEvoSuiteFramework(){ + Sandbox.resetDefaultSecurityManager(); + java.lang.System.setProperties((java.util.Properties) defaultProperties.clone()); + } + + @Before + public void initTestCase(){ + threadStopper.storeCurrentThreads(); + threadStopper.startRecordingTime(); + org.evosuite.runtime.jvm.ShutdownHookHandler.getInstance().initHandler(); + org.evosuite.runtime.sandbox.Sandbox.goingToExecuteSUTCode(); + + org.evosuite.runtime.GuiSupport.setHeadless(); + org.evosuite.runtime.Runtime.getInstance().resetRuntime(); + org.evosuite.runtime.agent.InstrumentingAgent.activate(); + } + + @After + public void doneWithTestCase(){ + threadStopper.killAndJoinClientThreads(); + org.evosuite.runtime.jvm.ShutdownHookHandler.getInstance().safeExecuteAddedHooks(); + org.evosuite.runtime.classhandling.JDKClassResetter.reset(); + resetClasses(); + org.evosuite.runtime.sandbox.Sandbox.doneWithExecutingSUTCode(); + org.evosuite.runtime.agent.InstrumentingAgent.deactivate(); + org.evosuite.runtime.GuiSupport.restoreHeadlessMode(); + } + + + private static void initializeClasses() { + org.evosuite.runtime.classhandling.ClassStateSupport.initializeClasses(MsoExceptionESTestscaffolding.class.getClassLoader() , + "org.openecomp.mso.openstack.exceptions.MsoExceptionCategory", + "org.openecomp.mso.openstack.exceptions.MsoTenantNotFound", + "org.openecomp.mso.openstack.exceptions.MsoIOException", + "org.openecomp.mso.openstack.exceptions.MsoCloudSiteNotFound", + "org.openecomp.mso.openstack.exceptions.MsoNetworkNotFound", + "org.openecomp.mso.openstack.exceptions.MsoException", + "org.openecomp.mso.openstack.exceptions.MsoAdapterException", + "org.openecomp.mso.openstack.exceptions.MsoOpenstackException" + ); + } + + private static void resetClasses() { + org.evosuite.runtime.classhandling.ClassResetter.getInstance().setClassLoader(MsoExceptionESTestscaffolding.class.getClassLoader()); + + org.evosuite.runtime.classhandling.ClassStateSupport.resetClasses( + "org.openecomp.mso.openstack.exceptions.MsoExceptionCategory", + "org.openecomp.mso.openstack.exceptions.MsoCloudSiteNotFound", + "org.openecomp.mso.openstack.exceptions.MsoIOException", + "org.openecomp.mso.openstack.exceptions.MsoOpenstackException", + "org.openecomp.mso.openstack.exceptions.MsoNetworkAlreadyExists", + "org.openecomp.mso.openstack.exceptions.MsoNetworkNotFound", + "org.openecomp.mso.openstack.exceptions.MsoStackAlreadyExists", + "org.openecomp.mso.openstack.exceptions.MsoStackNotFound", + "org.openecomp.mso.openstack.exceptions.MsoTenantNotFound", + "org.openecomp.mso.openstack.exceptions.MsoAdapterException", + "org.openecomp.mso.openstack.exceptions.MsoTenantAlreadyExists", + "org.openecomp.mso.openstack.exceptions.MsoException" + ); + } +} diff --git a/adapters/mso-adapter-utils/src/test/java/org/openecomp/mso/openstack/exceptions/MsoIOExceptionESTest.java b/adapters/mso-adapter-utils/src/test/java/org/openecomp/mso/openstack/exceptions/MsoIOExceptionESTest.java new file mode 100644 index 0000000000..ec2699c3f3 --- /dev/null +++ b/adapters/mso-adapter-utils/src/test/java/org/openecomp/mso/openstack/exceptions/MsoIOExceptionESTest.java @@ -0,0 +1,24 @@ +/* + * This file was automatically generated by EvoSuite + * Mon Nov 14 08:50:20 GMT 2016 + */ + +package org.openecomp.mso.openstack.exceptions; + +import org.junit.Test; +import static org.junit.Assert.*; + +import org.evosuite.runtime.EvoRunner; +import org.evosuite.runtime.EvoRunnerParameters; +import org.junit.runner.RunWith; + +@RunWith(EvoRunner.class) @EvoRunnerParameters(mockJVMNonDeterminism = true, useVFS = true, useVNET = true, resetStaticState = true, useJEE = true) +public class MsoIOExceptionESTest extends MsoIOExceptionESTestscaffolding { + + @Test(timeout = 4000) + public void test0() throws Throwable { + MsoIOException msoIOException0 = new MsoIOException(""); + MsoIOException msoIOException1 = new MsoIOException("", (Throwable) msoIOException0); + assertNull(msoIOException1.getContext()); + } +} diff --git a/adapters/mso-adapter-utils/src/test/java/org/openecomp/mso/openstack/exceptions/MsoIOExceptionESTestscaffolding.java b/adapters/mso-adapter-utils/src/test/java/org/openecomp/mso/openstack/exceptions/MsoIOExceptionESTestscaffolding.java new file mode 100644 index 0000000000..e657718fc4 --- /dev/null +++ b/adapters/mso-adapter-utils/src/test/java/org/openecomp/mso/openstack/exceptions/MsoIOExceptionESTestscaffolding.java @@ -0,0 +1,87 @@ +/** + * Scaffolding file used to store all the setups needed to run + * tests automatically generated by EvoSuite + * Mon Nov 14 08:50:20 GMT 2016 + */ + +package org.openecomp.mso.openstack.exceptions; + +import org.evosuite.runtime.annotation.EvoSuiteClassExclude; +import org.junit.BeforeClass; +import org.junit.Before; +import org.junit.After; +import org.junit.AfterClass; +import org.evosuite.runtime.sandbox.Sandbox; + +@EvoSuiteClassExclude +public class MsoIOExceptionESTestscaffolding { + + @org.junit.Rule + public org.evosuite.runtime.vnet.NonFunctionalRequirementRule nfr = new org.evosuite.runtime.vnet.NonFunctionalRequirementRule(); + + private static final java.util.Properties defaultProperties = (java.util.Properties) java.lang.System.getProperties().clone(); + + private org.evosuite.runtime.thread.ThreadStopper threadStopper = new org.evosuite.runtime.thread.ThreadStopper (org.evosuite.runtime.thread.KillSwitchHandler.getInstance(), 3000); + + @BeforeClass + public static void initEvoSuiteFramework() { + org.evosuite.runtime.RuntimeSettings.className = "org.openecomp.mso.openstack.exceptions.MsoIOException"; + org.evosuite.runtime.GuiSupport.initialize(); + org.evosuite.runtime.RuntimeSettings.maxNumberOfThreads = 100; + org.evosuite.runtime.RuntimeSettings.maxNumberOfIterationsPerLoop = 10000; + org.evosuite.runtime.RuntimeSettings.mockSystemIn = true; + org.evosuite.runtime.RuntimeSettings.sandboxMode = org.evosuite.runtime.sandbox.Sandbox.SandboxMode.RECOMMENDED; + org.evosuite.runtime.sandbox.Sandbox.initializeSecurityManagerForSUT(); + org.evosuite.runtime.classhandling.JDKClassResetter.init(); + initializeClasses(); + org.evosuite.runtime.Runtime.getInstance().resetRuntime(); + } + + @AfterClass + public static void clearEvoSuiteFramework(){ + Sandbox.resetDefaultSecurityManager(); + java.lang.System.setProperties((java.util.Properties) defaultProperties.clone()); + } + + @Before + public void initTestCase(){ + threadStopper.storeCurrentThreads(); + threadStopper.startRecordingTime(); + org.evosuite.runtime.jvm.ShutdownHookHandler.getInstance().initHandler(); + org.evosuite.runtime.sandbox.Sandbox.goingToExecuteSUTCode(); + + org.evosuite.runtime.GuiSupport.setHeadless(); + org.evosuite.runtime.Runtime.getInstance().resetRuntime(); + org.evosuite.runtime.agent.InstrumentingAgent.activate(); + } + + @After + public void doneWithTestCase(){ + threadStopper.killAndJoinClientThreads(); + org.evosuite.runtime.jvm.ShutdownHookHandler.getInstance().safeExecuteAddedHooks(); + org.evosuite.runtime.classhandling.JDKClassResetter.reset(); + resetClasses(); + org.evosuite.runtime.sandbox.Sandbox.doneWithExecutingSUTCode(); + org.evosuite.runtime.agent.InstrumentingAgent.deactivate(); + org.evosuite.runtime.GuiSupport.restoreHeadlessMode(); + } + + + private static void initializeClasses() { + org.evosuite.runtime.classhandling.ClassStateSupport.initializeClasses(MsoIOExceptionESTestscaffolding.class.getClassLoader() , + "org.openecomp.mso.openstack.exceptions.MsoIOException", + "org.openecomp.mso.openstack.exceptions.MsoExceptionCategory", + "org.openecomp.mso.openstack.exceptions.MsoException" + ); + } + + private static void resetClasses() { + org.evosuite.runtime.classhandling.ClassResetter.getInstance().setClassLoader(MsoIOExceptionESTestscaffolding.class.getClassLoader()); + + org.evosuite.runtime.classhandling.ClassStateSupport.resetClasses( + "org.openecomp.mso.openstack.exceptions.MsoExceptionCategory", + "org.openecomp.mso.openstack.exceptions.MsoException", + "org.openecomp.mso.openstack.exceptions.MsoIOException" + ); + } +} diff --git a/adapters/mso-adapter-utils/src/test/java/org/openecomp/mso/openstack/exceptions/MsoNetworkAlreadyExistsESTest.java b/adapters/mso-adapter-utils/src/test/java/org/openecomp/mso/openstack/exceptions/MsoNetworkAlreadyExistsESTest.java new file mode 100644 index 0000000000..2c423b7405 --- /dev/null +++ b/adapters/mso-adapter-utils/src/test/java/org/openecomp/mso/openstack/exceptions/MsoNetworkAlreadyExistsESTest.java @@ -0,0 +1,23 @@ +/* + * This file was automatically generated by EvoSuite + * Mon Nov 14 08:52:37 GMT 2016 + */ + +package org.openecomp.mso.openstack.exceptions; + +import org.junit.Test; +import static org.junit.Assert.*; + +import org.evosuite.runtime.EvoRunner; +import org.evosuite.runtime.EvoRunnerParameters; +import org.junit.runner.RunWith; + +@RunWith(EvoRunner.class) @EvoRunnerParameters(mockJVMNonDeterminism = true, useVFS = true, useVNET = true, resetStaticState = true, useJEE = true) +public class MsoNetworkAlreadyExistsESTest extends MsoNetworkAlreadyExistsESTestscaffolding { + + @Test(timeout = 4000) + public void test0() throws Throwable { + MsoNetworkAlreadyExists msoNetworkAlreadyExists0 = new MsoNetworkAlreadyExists((String) null, (String) null, (String) null); + assertNull(msoNetworkAlreadyExists0.getContext()); + } +} diff --git a/adapters/mso-adapter-utils/src/test/java/org/openecomp/mso/openstack/exceptions/MsoNetworkAlreadyExistsESTestscaffolding.java b/adapters/mso-adapter-utils/src/test/java/org/openecomp/mso/openstack/exceptions/MsoNetworkAlreadyExistsESTestscaffolding.java new file mode 100644 index 0000000000..1c00ba9d8d --- /dev/null +++ b/adapters/mso-adapter-utils/src/test/java/org/openecomp/mso/openstack/exceptions/MsoNetworkAlreadyExistsESTestscaffolding.java @@ -0,0 +1,89 @@ +/** + * Scaffolding file used to store all the setups needed to run + * tests automatically generated by EvoSuite + * Mon Nov 14 08:52:37 GMT 2016 + */ + +package org.openecomp.mso.openstack.exceptions; + +import org.evosuite.runtime.annotation.EvoSuiteClassExclude; +import org.junit.BeforeClass; +import org.junit.Before; +import org.junit.After; +import org.junit.AfterClass; +import org.evosuite.runtime.sandbox.Sandbox; + +@EvoSuiteClassExclude +public class MsoNetworkAlreadyExistsESTestscaffolding { + + @org.junit.Rule + public org.evosuite.runtime.vnet.NonFunctionalRequirementRule nfr = new org.evosuite.runtime.vnet.NonFunctionalRequirementRule(); + + private static final java.util.Properties defaultProperties = (java.util.Properties) java.lang.System.getProperties().clone(); + + private org.evosuite.runtime.thread.ThreadStopper threadStopper = new org.evosuite.runtime.thread.ThreadStopper (org.evosuite.runtime.thread.KillSwitchHandler.getInstance(), 3000); + + @BeforeClass + public static void initEvoSuiteFramework() { + org.evosuite.runtime.RuntimeSettings.className = "org.openecomp.mso.openstack.exceptions.MsoNetworkAlreadyExists"; + org.evosuite.runtime.GuiSupport.initialize(); + org.evosuite.runtime.RuntimeSettings.maxNumberOfThreads = 100; + org.evosuite.runtime.RuntimeSettings.maxNumberOfIterationsPerLoop = 10000; + org.evosuite.runtime.RuntimeSettings.mockSystemIn = true; + org.evosuite.runtime.RuntimeSettings.sandboxMode = org.evosuite.runtime.sandbox.Sandbox.SandboxMode.RECOMMENDED; + org.evosuite.runtime.sandbox.Sandbox.initializeSecurityManagerForSUT(); + org.evosuite.runtime.classhandling.JDKClassResetter.init(); + initializeClasses(); + org.evosuite.runtime.Runtime.getInstance().resetRuntime(); + } + + @AfterClass + public static void clearEvoSuiteFramework(){ + Sandbox.resetDefaultSecurityManager(); + java.lang.System.setProperties((java.util.Properties) defaultProperties.clone()); + } + + @Before + public void initTestCase(){ + threadStopper.storeCurrentThreads(); + threadStopper.startRecordingTime(); + org.evosuite.runtime.jvm.ShutdownHookHandler.getInstance().initHandler(); + org.evosuite.runtime.sandbox.Sandbox.goingToExecuteSUTCode(); + + org.evosuite.runtime.GuiSupport.setHeadless(); + org.evosuite.runtime.Runtime.getInstance().resetRuntime(); + org.evosuite.runtime.agent.InstrumentingAgent.activate(); + } + + @After + public void doneWithTestCase(){ + threadStopper.killAndJoinClientThreads(); + org.evosuite.runtime.jvm.ShutdownHookHandler.getInstance().safeExecuteAddedHooks(); + org.evosuite.runtime.classhandling.JDKClassResetter.reset(); + resetClasses(); + org.evosuite.runtime.sandbox.Sandbox.doneWithExecutingSUTCode(); + org.evosuite.runtime.agent.InstrumentingAgent.deactivate(); + org.evosuite.runtime.GuiSupport.restoreHeadlessMode(); + } + + + private static void initializeClasses() { + org.evosuite.runtime.classhandling.ClassStateSupport.initializeClasses(MsoNetworkAlreadyExistsESTestscaffolding.class.getClassLoader() , + "org.openecomp.mso.openstack.exceptions.MsoExceptionCategory", + "org.openecomp.mso.openstack.exceptions.MsoNetworkAlreadyExists", + "org.openecomp.mso.openstack.exceptions.MsoException", + "org.openecomp.mso.openstack.exceptions.MsoOpenstackException" + ); + } + + private static void resetClasses() { + org.evosuite.runtime.classhandling.ClassResetter.getInstance().setClassLoader(MsoNetworkAlreadyExistsESTestscaffolding.class.getClassLoader()); + + org.evosuite.runtime.classhandling.ClassStateSupport.resetClasses( + "org.openecomp.mso.openstack.exceptions.MsoExceptionCategory", + "org.openecomp.mso.openstack.exceptions.MsoException", + "org.openecomp.mso.openstack.exceptions.MsoOpenstackException", + "org.openecomp.mso.openstack.exceptions.MsoNetworkAlreadyExists" + ); + } +} diff --git a/adapters/mso-adapter-utils/src/test/java/org/openecomp/mso/openstack/exceptions/MsoNetworkNotFoundESTest.java b/adapters/mso-adapter-utils/src/test/java/org/openecomp/mso/openstack/exceptions/MsoNetworkNotFoundESTest.java new file mode 100644 index 0000000000..418545056c --- /dev/null +++ b/adapters/mso-adapter-utils/src/test/java/org/openecomp/mso/openstack/exceptions/MsoNetworkNotFoundESTest.java @@ -0,0 +1,23 @@ +/* + * This file was automatically generated by EvoSuite + * Mon Nov 14 08:54:45 GMT 2016 + */ + +package org.openecomp.mso.openstack.exceptions; + +import org.junit.Test; +import static org.junit.Assert.*; + +import org.evosuite.runtime.EvoRunner; +import org.evosuite.runtime.EvoRunnerParameters; +import org.junit.runner.RunWith; + +@RunWith(EvoRunner.class) @EvoRunnerParameters(mockJVMNonDeterminism = true, useVFS = true, useVNET = true, resetStaticState = true, useJEE = true) +public class MsoNetworkNotFoundESTest extends MsoNetworkNotFoundESTestscaffolding { + + @Test(timeout = 4000) + public void test0() throws Throwable { + MsoNetworkNotFound msoNetworkNotFound0 = new MsoNetworkNotFound("6", "6", "yX9(}I;;7<c%.4HYX"); + assertNull(msoNetworkNotFound0.getContext()); + } +} diff --git a/adapters/mso-adapter-utils/src/test/java/org/openecomp/mso/openstack/exceptions/MsoNetworkNotFoundESTestscaffolding.java b/adapters/mso-adapter-utils/src/test/java/org/openecomp/mso/openstack/exceptions/MsoNetworkNotFoundESTestscaffolding.java new file mode 100644 index 0000000000..1506836f1e --- /dev/null +++ b/adapters/mso-adapter-utils/src/test/java/org/openecomp/mso/openstack/exceptions/MsoNetworkNotFoundESTestscaffolding.java @@ -0,0 +1,89 @@ +/** + * Scaffolding file used to store all the setups needed to run + * tests automatically generated by EvoSuite + * Mon Nov 14 08:54:45 GMT 2016 + */ + +package org.openecomp.mso.openstack.exceptions; + +import org.evosuite.runtime.annotation.EvoSuiteClassExclude; +import org.junit.BeforeClass; +import org.junit.Before; +import org.junit.After; +import org.junit.AfterClass; +import org.evosuite.runtime.sandbox.Sandbox; + +@EvoSuiteClassExclude +public class MsoNetworkNotFoundESTestscaffolding { + + @org.junit.Rule + public org.evosuite.runtime.vnet.NonFunctionalRequirementRule nfr = new org.evosuite.runtime.vnet.NonFunctionalRequirementRule(); + + private static final java.util.Properties defaultProperties = (java.util.Properties) java.lang.System.getProperties().clone(); + + private org.evosuite.runtime.thread.ThreadStopper threadStopper = new org.evosuite.runtime.thread.ThreadStopper (org.evosuite.runtime.thread.KillSwitchHandler.getInstance(), 3000); + + @BeforeClass + public static void initEvoSuiteFramework() { + org.evosuite.runtime.RuntimeSettings.className = "org.openecomp.mso.openstack.exceptions.MsoNetworkNotFound"; + org.evosuite.runtime.GuiSupport.initialize(); + org.evosuite.runtime.RuntimeSettings.maxNumberOfThreads = 100; + org.evosuite.runtime.RuntimeSettings.maxNumberOfIterationsPerLoop = 10000; + org.evosuite.runtime.RuntimeSettings.mockSystemIn = true; + org.evosuite.runtime.RuntimeSettings.sandboxMode = org.evosuite.runtime.sandbox.Sandbox.SandboxMode.RECOMMENDED; + org.evosuite.runtime.sandbox.Sandbox.initializeSecurityManagerForSUT(); + org.evosuite.runtime.classhandling.JDKClassResetter.init(); + initializeClasses(); + org.evosuite.runtime.Runtime.getInstance().resetRuntime(); + } + + @AfterClass + public static void clearEvoSuiteFramework(){ + Sandbox.resetDefaultSecurityManager(); + java.lang.System.setProperties((java.util.Properties) defaultProperties.clone()); + } + + @Before + public void initTestCase(){ + threadStopper.storeCurrentThreads(); + threadStopper.startRecordingTime(); + org.evosuite.runtime.jvm.ShutdownHookHandler.getInstance().initHandler(); + org.evosuite.runtime.sandbox.Sandbox.goingToExecuteSUTCode(); + + org.evosuite.runtime.GuiSupport.setHeadless(); + org.evosuite.runtime.Runtime.getInstance().resetRuntime(); + org.evosuite.runtime.agent.InstrumentingAgent.activate(); + } + + @After + public void doneWithTestCase(){ + threadStopper.killAndJoinClientThreads(); + org.evosuite.runtime.jvm.ShutdownHookHandler.getInstance().safeExecuteAddedHooks(); + org.evosuite.runtime.classhandling.JDKClassResetter.reset(); + resetClasses(); + org.evosuite.runtime.sandbox.Sandbox.doneWithExecutingSUTCode(); + org.evosuite.runtime.agent.InstrumentingAgent.deactivate(); + org.evosuite.runtime.GuiSupport.restoreHeadlessMode(); + } + + + private static void initializeClasses() { + org.evosuite.runtime.classhandling.ClassStateSupport.initializeClasses(MsoNetworkNotFoundESTestscaffolding.class.getClassLoader() , + "org.openecomp.mso.openstack.exceptions.MsoExceptionCategory", + "org.openecomp.mso.openstack.exceptions.MsoNetworkNotFound", + "org.openecomp.mso.openstack.exceptions.MsoException", + "org.openecomp.mso.openstack.exceptions.MsoOpenstackException" + ); + } + + private static void resetClasses() { + org.evosuite.runtime.classhandling.ClassResetter.getInstance().setClassLoader(MsoNetworkNotFoundESTestscaffolding.class.getClassLoader()); + + org.evosuite.runtime.classhandling.ClassStateSupport.resetClasses( + "org.openecomp.mso.openstack.exceptions.MsoExceptionCategory", + "org.openecomp.mso.openstack.exceptions.MsoException", + "org.openecomp.mso.openstack.exceptions.MsoOpenstackException", + "org.openecomp.mso.openstack.exceptions.MsoNetworkNotFound" + ); + } +} diff --git a/adapters/mso-adapter-utils/src/test/java/org/openecomp/mso/openstack/exceptions/MsoOpenstackExceptionESTest.java b/adapters/mso-adapter-utils/src/test/java/org/openecomp/mso/openstack/exceptions/MsoOpenstackExceptionESTest.java new file mode 100644 index 0000000000..00d7035c93 --- /dev/null +++ b/adapters/mso-adapter-utils/src/test/java/org/openecomp/mso/openstack/exceptions/MsoOpenstackExceptionESTest.java @@ -0,0 +1,32 @@ +/* + * This file was automatically generated by EvoSuite + * Mon Nov 14 08:51:53 GMT 2016 + */ + +package org.openecomp.mso.openstack.exceptions; + +import org.junit.Test; +import static org.junit.Assert.*; + +import org.evosuite.runtime.EvoRunner; +import org.evosuite.runtime.EvoRunnerParameters; +import org.junit.runner.RunWith; + +@RunWith(EvoRunner.class) @EvoRunnerParameters(mockJVMNonDeterminism = true, useVFS = true, useVNET = true, resetStaticState = true, useJEE = true) +public class MsoOpenstackExceptionESTest extends MsoOpenstackExceptionESTestscaffolding { + + @Test(timeout = 4000) + public void test0() throws Throwable { + MsoOpenstackException msoOpenstackException0 = new MsoOpenstackException((-20), "zOT*@]B@O~zuv2", "zOT*@]B@O~zuv2"); + MsoOpenstackException msoOpenstackException1 = new MsoOpenstackException((-20), "zOT*@]B@O~zuv2", "zOT*@]B@O~zuv2", (Exception) msoOpenstackException0); + assertEquals(MsoExceptionCategory.OPENSTACK, msoOpenstackException1.getCategory()); + } + + @Test(timeout = 4000) + public void test1() throws Throwable { + MsoOpenstackException msoOpenstackException0 = new MsoOpenstackException((-20), "zOT*@]B@O~zuv2", "zOT*@]B@O~zuv2"); + String string0 = msoOpenstackException0.toString(); + assertNotNull(string0); + assertEquals("-20 zOT*@]B@O~zuv2: zOT*@]B@O~zuv2", string0); + } +} diff --git a/adapters/mso-adapter-utils/src/test/java/org/openecomp/mso/openstack/exceptions/MsoOpenstackExceptionESTestscaffolding.java b/adapters/mso-adapter-utils/src/test/java/org/openecomp/mso/openstack/exceptions/MsoOpenstackExceptionESTestscaffolding.java new file mode 100644 index 0000000000..78a71cce45 --- /dev/null +++ b/adapters/mso-adapter-utils/src/test/java/org/openecomp/mso/openstack/exceptions/MsoOpenstackExceptionESTestscaffolding.java @@ -0,0 +1,87 @@ +/** + * Scaffolding file used to store all the setups needed to run + * tests automatically generated by EvoSuite + * Mon Nov 14 08:51:53 GMT 2016 + */ + +package org.openecomp.mso.openstack.exceptions; + +import org.evosuite.runtime.annotation.EvoSuiteClassExclude; +import org.junit.BeforeClass; +import org.junit.Before; +import org.junit.After; +import org.junit.AfterClass; +import org.evosuite.runtime.sandbox.Sandbox; + +@EvoSuiteClassExclude +public class MsoOpenstackExceptionESTestscaffolding { + + @org.junit.Rule + public org.evosuite.runtime.vnet.NonFunctionalRequirementRule nfr = new org.evosuite.runtime.vnet.NonFunctionalRequirementRule(); + + private static final java.util.Properties defaultProperties = (java.util.Properties) java.lang.System.getProperties().clone(); + + private org.evosuite.runtime.thread.ThreadStopper threadStopper = new org.evosuite.runtime.thread.ThreadStopper (org.evosuite.runtime.thread.KillSwitchHandler.getInstance(), 3000); + + @BeforeClass + public static void initEvoSuiteFramework() { + org.evosuite.runtime.RuntimeSettings.className = "org.openecomp.mso.openstack.exceptions.MsoOpenstackException"; + org.evosuite.runtime.GuiSupport.initialize(); + org.evosuite.runtime.RuntimeSettings.maxNumberOfThreads = 100; + org.evosuite.runtime.RuntimeSettings.maxNumberOfIterationsPerLoop = 10000; + org.evosuite.runtime.RuntimeSettings.mockSystemIn = true; + org.evosuite.runtime.RuntimeSettings.sandboxMode = org.evosuite.runtime.sandbox.Sandbox.SandboxMode.RECOMMENDED; + org.evosuite.runtime.sandbox.Sandbox.initializeSecurityManagerForSUT(); + org.evosuite.runtime.classhandling.JDKClassResetter.init(); + initializeClasses(); + org.evosuite.runtime.Runtime.getInstance().resetRuntime(); + } + + @AfterClass + public static void clearEvoSuiteFramework(){ + Sandbox.resetDefaultSecurityManager(); + java.lang.System.setProperties((java.util.Properties) defaultProperties.clone()); + } + + @Before + public void initTestCase(){ + threadStopper.storeCurrentThreads(); + threadStopper.startRecordingTime(); + org.evosuite.runtime.jvm.ShutdownHookHandler.getInstance().initHandler(); + org.evosuite.runtime.sandbox.Sandbox.goingToExecuteSUTCode(); + + org.evosuite.runtime.GuiSupport.setHeadless(); + org.evosuite.runtime.Runtime.getInstance().resetRuntime(); + org.evosuite.runtime.agent.InstrumentingAgent.activate(); + } + + @After + public void doneWithTestCase(){ + threadStopper.killAndJoinClientThreads(); + org.evosuite.runtime.jvm.ShutdownHookHandler.getInstance().safeExecuteAddedHooks(); + org.evosuite.runtime.classhandling.JDKClassResetter.reset(); + resetClasses(); + org.evosuite.runtime.sandbox.Sandbox.doneWithExecutingSUTCode(); + org.evosuite.runtime.agent.InstrumentingAgent.deactivate(); + org.evosuite.runtime.GuiSupport.restoreHeadlessMode(); + } + + + private static void initializeClasses() { + org.evosuite.runtime.classhandling.ClassStateSupport.initializeClasses(MsoOpenstackExceptionESTestscaffolding.class.getClassLoader() , + "org.openecomp.mso.openstack.exceptions.MsoExceptionCategory", + "org.openecomp.mso.openstack.exceptions.MsoException", + "org.openecomp.mso.openstack.exceptions.MsoOpenstackException" + ); + } + + private static void resetClasses() { + org.evosuite.runtime.classhandling.ClassResetter.getInstance().setClassLoader(MsoOpenstackExceptionESTestscaffolding.class.getClassLoader()); + + org.evosuite.runtime.classhandling.ClassStateSupport.resetClasses( + "org.openecomp.mso.openstack.exceptions.MsoExceptionCategory", + "org.openecomp.mso.openstack.exceptions.MsoException", + "org.openecomp.mso.openstack.exceptions.MsoOpenstackException" + ); + } +} diff --git a/adapters/mso-adapter-utils/src/test/java/org/openecomp/mso/openstack/exceptions/MsoStackAlreadyExistsESTest.java b/adapters/mso-adapter-utils/src/test/java/org/openecomp/mso/openstack/exceptions/MsoStackAlreadyExistsESTest.java new file mode 100644 index 0000000000..289b2a6aa2 --- /dev/null +++ b/adapters/mso-adapter-utils/src/test/java/org/openecomp/mso/openstack/exceptions/MsoStackAlreadyExistsESTest.java @@ -0,0 +1,23 @@ +/* + * This file was automatically generated by EvoSuite + * Mon Nov 14 08:55:08 GMT 2016 + */ + +package org.openecomp.mso.openstack.exceptions; + +import org.junit.Test; +import static org.junit.Assert.*; + +import org.evosuite.runtime.EvoRunner; +import org.evosuite.runtime.EvoRunnerParameters; +import org.junit.runner.RunWith; + +@RunWith(EvoRunner.class) @EvoRunnerParameters(mockJVMNonDeterminism = true, useVFS = true, useVNET = true, resetStaticState = true, useJEE = true) +public class MsoStackAlreadyExistsESTest extends MsoStackAlreadyExistsESTestscaffolding { + + @Test(timeout = 4000) + public void test0() throws Throwable { + MsoStackAlreadyExists msoStackAlreadyExists0 = new MsoStackAlreadyExists("", "", ""); + assertEquals(MsoExceptionCategory.OPENSTACK, msoStackAlreadyExists0.getCategory()); + } +} diff --git a/adapters/mso-adapter-utils/src/test/java/org/openecomp/mso/openstack/exceptions/MsoStackAlreadyExistsESTestscaffolding.java b/adapters/mso-adapter-utils/src/test/java/org/openecomp/mso/openstack/exceptions/MsoStackAlreadyExistsESTestscaffolding.java new file mode 100644 index 0000000000..c7b8c85f67 --- /dev/null +++ b/adapters/mso-adapter-utils/src/test/java/org/openecomp/mso/openstack/exceptions/MsoStackAlreadyExistsESTestscaffolding.java @@ -0,0 +1,89 @@ +/** + * Scaffolding file used to store all the setups needed to run + * tests automatically generated by EvoSuite + * Mon Nov 14 08:55:08 GMT 2016 + */ + +package org.openecomp.mso.openstack.exceptions; + +import org.evosuite.runtime.annotation.EvoSuiteClassExclude; +import org.junit.BeforeClass; +import org.junit.Before; +import org.junit.After; +import org.junit.AfterClass; +import org.evosuite.runtime.sandbox.Sandbox; + +@EvoSuiteClassExclude +public class MsoStackAlreadyExistsESTestscaffolding { + + @org.junit.Rule + public org.evosuite.runtime.vnet.NonFunctionalRequirementRule nfr = new org.evosuite.runtime.vnet.NonFunctionalRequirementRule(); + + private static final java.util.Properties defaultProperties = (java.util.Properties) java.lang.System.getProperties().clone(); + + private org.evosuite.runtime.thread.ThreadStopper threadStopper = new org.evosuite.runtime.thread.ThreadStopper (org.evosuite.runtime.thread.KillSwitchHandler.getInstance(), 3000); + + @BeforeClass + public static void initEvoSuiteFramework() { + org.evosuite.runtime.RuntimeSettings.className = "org.openecomp.mso.openstack.exceptions.MsoStackAlreadyExists"; + org.evosuite.runtime.GuiSupport.initialize(); + org.evosuite.runtime.RuntimeSettings.maxNumberOfThreads = 100; + org.evosuite.runtime.RuntimeSettings.maxNumberOfIterationsPerLoop = 10000; + org.evosuite.runtime.RuntimeSettings.mockSystemIn = true; + org.evosuite.runtime.RuntimeSettings.sandboxMode = org.evosuite.runtime.sandbox.Sandbox.SandboxMode.RECOMMENDED; + org.evosuite.runtime.sandbox.Sandbox.initializeSecurityManagerForSUT(); + org.evosuite.runtime.classhandling.JDKClassResetter.init(); + initializeClasses(); + org.evosuite.runtime.Runtime.getInstance().resetRuntime(); + } + + @AfterClass + public static void clearEvoSuiteFramework(){ + Sandbox.resetDefaultSecurityManager(); + java.lang.System.setProperties((java.util.Properties) defaultProperties.clone()); + } + + @Before + public void initTestCase(){ + threadStopper.storeCurrentThreads(); + threadStopper.startRecordingTime(); + org.evosuite.runtime.jvm.ShutdownHookHandler.getInstance().initHandler(); + org.evosuite.runtime.sandbox.Sandbox.goingToExecuteSUTCode(); + + org.evosuite.runtime.GuiSupport.setHeadless(); + org.evosuite.runtime.Runtime.getInstance().resetRuntime(); + org.evosuite.runtime.agent.InstrumentingAgent.activate(); + } + + @After + public void doneWithTestCase(){ + threadStopper.killAndJoinClientThreads(); + org.evosuite.runtime.jvm.ShutdownHookHandler.getInstance().safeExecuteAddedHooks(); + org.evosuite.runtime.classhandling.JDKClassResetter.reset(); + resetClasses(); + org.evosuite.runtime.sandbox.Sandbox.doneWithExecutingSUTCode(); + org.evosuite.runtime.agent.InstrumentingAgent.deactivate(); + org.evosuite.runtime.GuiSupport.restoreHeadlessMode(); + } + + + private static void initializeClasses() { + org.evosuite.runtime.classhandling.ClassStateSupport.initializeClasses(MsoStackAlreadyExistsESTestscaffolding.class.getClassLoader() , + "org.openecomp.mso.openstack.exceptions.MsoStackAlreadyExists", + "org.openecomp.mso.openstack.exceptions.MsoExceptionCategory", + "org.openecomp.mso.openstack.exceptions.MsoException", + "org.openecomp.mso.openstack.exceptions.MsoOpenstackException" + ); + } + + private static void resetClasses() { + org.evosuite.runtime.classhandling.ClassResetter.getInstance().setClassLoader(MsoStackAlreadyExistsESTestscaffolding.class.getClassLoader()); + + org.evosuite.runtime.classhandling.ClassStateSupport.resetClasses( + "org.openecomp.mso.openstack.exceptions.MsoExceptionCategory", + "org.openecomp.mso.openstack.exceptions.MsoException", + "org.openecomp.mso.openstack.exceptions.MsoOpenstackException", + "org.openecomp.mso.openstack.exceptions.MsoStackAlreadyExists" + ); + } +} diff --git a/adapters/mso-adapter-utils/src/test/java/org/openecomp/mso/openstack/exceptions/MsoStackNotFoundESTest.java b/adapters/mso-adapter-utils/src/test/java/org/openecomp/mso/openstack/exceptions/MsoStackNotFoundESTest.java new file mode 100644 index 0000000000..e8b6e85e74 --- /dev/null +++ b/adapters/mso-adapter-utils/src/test/java/org/openecomp/mso/openstack/exceptions/MsoStackNotFoundESTest.java @@ -0,0 +1,23 @@ +/* + * This file was automatically generated by EvoSuite + * Mon Nov 14 08:55:36 GMT 2016 + */ + +package org.openecomp.mso.openstack.exceptions; + +import org.junit.Test; +import static org.junit.Assert.*; + +import org.evosuite.runtime.EvoRunner; +import org.evosuite.runtime.EvoRunnerParameters; +import org.junit.runner.RunWith; + +@RunWith(EvoRunner.class) @EvoRunnerParameters(mockJVMNonDeterminism = true, useVFS = true, useVNET = true, resetStaticState = true, useJEE = true) +public class MsoStackNotFoundESTest extends MsoStackNotFoundESTestscaffolding { + + @Test(timeout = 4000) + public void test0() throws Throwable { + MsoStackNotFound msoStackNotFound0 = new MsoStackNotFound("", (String) null, (String) null); + assertEquals(MsoExceptionCategory.OPENSTACK, msoStackNotFound0.getCategory()); + } +} diff --git a/adapters/mso-adapter-utils/src/test/java/org/openecomp/mso/openstack/exceptions/MsoStackNotFoundESTestscaffolding.java b/adapters/mso-adapter-utils/src/test/java/org/openecomp/mso/openstack/exceptions/MsoStackNotFoundESTestscaffolding.java new file mode 100644 index 0000000000..3ce09164d8 --- /dev/null +++ b/adapters/mso-adapter-utils/src/test/java/org/openecomp/mso/openstack/exceptions/MsoStackNotFoundESTestscaffolding.java @@ -0,0 +1,89 @@ +/** + * Scaffolding file used to store all the setups needed to run + * tests automatically generated by EvoSuite + * Mon Nov 14 08:55:36 GMT 2016 + */ + +package org.openecomp.mso.openstack.exceptions; + +import org.evosuite.runtime.annotation.EvoSuiteClassExclude; +import org.junit.BeforeClass; +import org.junit.Before; +import org.junit.After; +import org.junit.AfterClass; +import org.evosuite.runtime.sandbox.Sandbox; + +@EvoSuiteClassExclude +public class MsoStackNotFoundESTestscaffolding { + + @org.junit.Rule + public org.evosuite.runtime.vnet.NonFunctionalRequirementRule nfr = new org.evosuite.runtime.vnet.NonFunctionalRequirementRule(); + + private static final java.util.Properties defaultProperties = (java.util.Properties) java.lang.System.getProperties().clone(); + + private org.evosuite.runtime.thread.ThreadStopper threadStopper = new org.evosuite.runtime.thread.ThreadStopper (org.evosuite.runtime.thread.KillSwitchHandler.getInstance(), 3000); + + @BeforeClass + public static void initEvoSuiteFramework() { + org.evosuite.runtime.RuntimeSettings.className = "org.openecomp.mso.openstack.exceptions.MsoStackNotFound"; + org.evosuite.runtime.GuiSupport.initialize(); + org.evosuite.runtime.RuntimeSettings.maxNumberOfThreads = 100; + org.evosuite.runtime.RuntimeSettings.maxNumberOfIterationsPerLoop = 10000; + org.evosuite.runtime.RuntimeSettings.mockSystemIn = true; + org.evosuite.runtime.RuntimeSettings.sandboxMode = org.evosuite.runtime.sandbox.Sandbox.SandboxMode.RECOMMENDED; + org.evosuite.runtime.sandbox.Sandbox.initializeSecurityManagerForSUT(); + org.evosuite.runtime.classhandling.JDKClassResetter.init(); + initializeClasses(); + org.evosuite.runtime.Runtime.getInstance().resetRuntime(); + } + + @AfterClass + public static void clearEvoSuiteFramework(){ + Sandbox.resetDefaultSecurityManager(); + java.lang.System.setProperties((java.util.Properties) defaultProperties.clone()); + } + + @Before + public void initTestCase(){ + threadStopper.storeCurrentThreads(); + threadStopper.startRecordingTime(); + org.evosuite.runtime.jvm.ShutdownHookHandler.getInstance().initHandler(); + org.evosuite.runtime.sandbox.Sandbox.goingToExecuteSUTCode(); + + org.evosuite.runtime.GuiSupport.setHeadless(); + org.evosuite.runtime.Runtime.getInstance().resetRuntime(); + org.evosuite.runtime.agent.InstrumentingAgent.activate(); + } + + @After + public void doneWithTestCase(){ + threadStopper.killAndJoinClientThreads(); + org.evosuite.runtime.jvm.ShutdownHookHandler.getInstance().safeExecuteAddedHooks(); + org.evosuite.runtime.classhandling.JDKClassResetter.reset(); + resetClasses(); + org.evosuite.runtime.sandbox.Sandbox.doneWithExecutingSUTCode(); + org.evosuite.runtime.agent.InstrumentingAgent.deactivate(); + org.evosuite.runtime.GuiSupport.restoreHeadlessMode(); + } + + + private static void initializeClasses() { + org.evosuite.runtime.classhandling.ClassStateSupport.initializeClasses(MsoStackNotFoundESTestscaffolding.class.getClassLoader() , + "org.openecomp.mso.openstack.exceptions.MsoExceptionCategory", + "org.openecomp.mso.openstack.exceptions.MsoStackNotFound", + "org.openecomp.mso.openstack.exceptions.MsoException", + "org.openecomp.mso.openstack.exceptions.MsoOpenstackException" + ); + } + + private static void resetClasses() { + org.evosuite.runtime.classhandling.ClassResetter.getInstance().setClassLoader(MsoStackNotFoundESTestscaffolding.class.getClassLoader()); + + org.evosuite.runtime.classhandling.ClassStateSupport.resetClasses( + "org.openecomp.mso.openstack.exceptions.MsoExceptionCategory", + "org.openecomp.mso.openstack.exceptions.MsoException", + "org.openecomp.mso.openstack.exceptions.MsoOpenstackException", + "org.openecomp.mso.openstack.exceptions.MsoStackNotFound" + ); + } +} diff --git a/adapters/mso-adapter-utils/src/test/java/org/openecomp/mso/openstack/exceptions/MsoTenantAlreadyExistsESTest.java b/adapters/mso-adapter-utils/src/test/java/org/openecomp/mso/openstack/exceptions/MsoTenantAlreadyExistsESTest.java new file mode 100644 index 0000000000..a47f778cc0 --- /dev/null +++ b/adapters/mso-adapter-utils/src/test/java/org/openecomp/mso/openstack/exceptions/MsoTenantAlreadyExistsESTest.java @@ -0,0 +1,23 @@ +/* + * This file was automatically generated by EvoSuite + * Mon Nov 14 08:56:00 GMT 2016 + */ + +package org.openecomp.mso.openstack.exceptions; + +import org.junit.Test; +import static org.junit.Assert.*; + +import org.evosuite.runtime.EvoRunner; +import org.evosuite.runtime.EvoRunnerParameters; +import org.junit.runner.RunWith; + +@RunWith(EvoRunner.class) @EvoRunnerParameters(mockJVMNonDeterminism = true, useVFS = true, useVNET = true, resetStaticState = true, useJEE = true) +public class MsoTenantAlreadyExistsESTest extends MsoTenantAlreadyExistsESTestscaffolding { + + @Test(timeout = 4000) + public void test0() throws Throwable { + MsoTenantAlreadyExists msoTenantAlreadyExists0 = new MsoTenantAlreadyExists("Q]>\u00018.eW8", "Q]>\u00018.eW8"); + assertEquals(MsoExceptionCategory.OPENSTACK, msoTenantAlreadyExists0.getCategory()); + } +} diff --git a/adapters/mso-adapter-utils/src/test/java/org/openecomp/mso/openstack/exceptions/MsoTenantAlreadyExistsESTestscaffolding.java b/adapters/mso-adapter-utils/src/test/java/org/openecomp/mso/openstack/exceptions/MsoTenantAlreadyExistsESTestscaffolding.java new file mode 100644 index 0000000000..11700e6e75 --- /dev/null +++ b/adapters/mso-adapter-utils/src/test/java/org/openecomp/mso/openstack/exceptions/MsoTenantAlreadyExistsESTestscaffolding.java @@ -0,0 +1,89 @@ +/** + * Scaffolding file used to store all the setups needed to run + * tests automatically generated by EvoSuite + * Mon Nov 14 08:56:00 GMT 2016 + */ + +package org.openecomp.mso.openstack.exceptions; + +import org.evosuite.runtime.annotation.EvoSuiteClassExclude; +import org.junit.BeforeClass; +import org.junit.Before; +import org.junit.After; +import org.junit.AfterClass; +import org.evosuite.runtime.sandbox.Sandbox; + +@EvoSuiteClassExclude +public class MsoTenantAlreadyExistsESTestscaffolding { + + @org.junit.Rule + public org.evosuite.runtime.vnet.NonFunctionalRequirementRule nfr = new org.evosuite.runtime.vnet.NonFunctionalRequirementRule(); + + private static final java.util.Properties defaultProperties = (java.util.Properties) java.lang.System.getProperties().clone(); + + private org.evosuite.runtime.thread.ThreadStopper threadStopper = new org.evosuite.runtime.thread.ThreadStopper (org.evosuite.runtime.thread.KillSwitchHandler.getInstance(), 3000); + + @BeforeClass + public static void initEvoSuiteFramework() { + org.evosuite.runtime.RuntimeSettings.className = "org.openecomp.mso.openstack.exceptions.MsoTenantAlreadyExists"; + org.evosuite.runtime.GuiSupport.initialize(); + org.evosuite.runtime.RuntimeSettings.maxNumberOfThreads = 100; + org.evosuite.runtime.RuntimeSettings.maxNumberOfIterationsPerLoop = 10000; + org.evosuite.runtime.RuntimeSettings.mockSystemIn = true; + org.evosuite.runtime.RuntimeSettings.sandboxMode = org.evosuite.runtime.sandbox.Sandbox.SandboxMode.RECOMMENDED; + org.evosuite.runtime.sandbox.Sandbox.initializeSecurityManagerForSUT(); + org.evosuite.runtime.classhandling.JDKClassResetter.init(); + initializeClasses(); + org.evosuite.runtime.Runtime.getInstance().resetRuntime(); + } + + @AfterClass + public static void clearEvoSuiteFramework(){ + Sandbox.resetDefaultSecurityManager(); + java.lang.System.setProperties((java.util.Properties) defaultProperties.clone()); + } + + @Before + public void initTestCase(){ + threadStopper.storeCurrentThreads(); + threadStopper.startRecordingTime(); + org.evosuite.runtime.jvm.ShutdownHookHandler.getInstance().initHandler(); + org.evosuite.runtime.sandbox.Sandbox.goingToExecuteSUTCode(); + + org.evosuite.runtime.GuiSupport.setHeadless(); + org.evosuite.runtime.Runtime.getInstance().resetRuntime(); + org.evosuite.runtime.agent.InstrumentingAgent.activate(); + } + + @After + public void doneWithTestCase(){ + threadStopper.killAndJoinClientThreads(); + org.evosuite.runtime.jvm.ShutdownHookHandler.getInstance().safeExecuteAddedHooks(); + org.evosuite.runtime.classhandling.JDKClassResetter.reset(); + resetClasses(); + org.evosuite.runtime.sandbox.Sandbox.doneWithExecutingSUTCode(); + org.evosuite.runtime.agent.InstrumentingAgent.deactivate(); + org.evosuite.runtime.GuiSupport.restoreHeadlessMode(); + } + + + private static void initializeClasses() { + org.evosuite.runtime.classhandling.ClassStateSupport.initializeClasses(MsoTenantAlreadyExistsESTestscaffolding.class.getClassLoader() , + "org.openecomp.mso.openstack.exceptions.MsoExceptionCategory", + "org.openecomp.mso.openstack.exceptions.MsoTenantAlreadyExists", + "org.openecomp.mso.openstack.exceptions.MsoException", + "org.openecomp.mso.openstack.exceptions.MsoOpenstackException" + ); + } + + private static void resetClasses() { + org.evosuite.runtime.classhandling.ClassResetter.getInstance().setClassLoader(MsoTenantAlreadyExistsESTestscaffolding.class.getClassLoader()); + + org.evosuite.runtime.classhandling.ClassStateSupport.resetClasses( + "org.openecomp.mso.openstack.exceptions.MsoExceptionCategory", + "org.openecomp.mso.openstack.exceptions.MsoException", + "org.openecomp.mso.openstack.exceptions.MsoOpenstackException", + "org.openecomp.mso.openstack.exceptions.MsoTenantAlreadyExists" + ); + } +} diff --git a/adapters/mso-adapter-utils/src/test/java/org/openecomp/mso/openstack/exceptions/MsoTenantNotFoundESTest.java b/adapters/mso-adapter-utils/src/test/java/org/openecomp/mso/openstack/exceptions/MsoTenantNotFoundESTest.java new file mode 100644 index 0000000000..b65bd1f5e4 --- /dev/null +++ b/adapters/mso-adapter-utils/src/test/java/org/openecomp/mso/openstack/exceptions/MsoTenantNotFoundESTest.java @@ -0,0 +1,23 @@ +/* + * This file was automatically generated by EvoSuite + * Mon Nov 14 08:52:17 GMT 2016 + */ + +package org.openecomp.mso.openstack.exceptions; + +import org.junit.Test; +import static org.junit.Assert.*; + +import org.evosuite.runtime.EvoRunner; +import org.evosuite.runtime.EvoRunnerParameters; +import org.junit.runner.RunWith; + +@RunWith(EvoRunner.class) @EvoRunnerParameters(mockJVMNonDeterminism = true, useVFS = true, useVNET = true, resetStaticState = true, useJEE = true) +public class MsoTenantNotFoundESTest extends MsoTenantNotFoundESTestscaffolding { + + @Test(timeout = 4000) + public void test0() throws Throwable { + MsoTenantNotFound msoTenantNotFound0 = new MsoTenantNotFound("", ""); + assertEquals(MsoExceptionCategory.OPENSTACK, msoTenantNotFound0.getCategory()); + } +} diff --git a/adapters/mso-adapter-utils/src/test/java/org/openecomp/mso/openstack/exceptions/MsoTenantNotFoundESTestscaffolding.java b/adapters/mso-adapter-utils/src/test/java/org/openecomp/mso/openstack/exceptions/MsoTenantNotFoundESTestscaffolding.java new file mode 100644 index 0000000000..bd45ba62ad --- /dev/null +++ b/adapters/mso-adapter-utils/src/test/java/org/openecomp/mso/openstack/exceptions/MsoTenantNotFoundESTestscaffolding.java @@ -0,0 +1,89 @@ +/** + * Scaffolding file used to store all the setups needed to run + * tests automatically generated by EvoSuite + * Mon Nov 14 08:52:17 GMT 2016 + */ + +package org.openecomp.mso.openstack.exceptions; + +import org.evosuite.runtime.annotation.EvoSuiteClassExclude; +import org.junit.BeforeClass; +import org.junit.Before; +import org.junit.After; +import org.junit.AfterClass; +import org.evosuite.runtime.sandbox.Sandbox; + +@EvoSuiteClassExclude +public class MsoTenantNotFoundESTestscaffolding { + + @org.junit.Rule + public org.evosuite.runtime.vnet.NonFunctionalRequirementRule nfr = new org.evosuite.runtime.vnet.NonFunctionalRequirementRule(); + + private static final java.util.Properties defaultProperties = (java.util.Properties) java.lang.System.getProperties().clone(); + + private org.evosuite.runtime.thread.ThreadStopper threadStopper = new org.evosuite.runtime.thread.ThreadStopper (org.evosuite.runtime.thread.KillSwitchHandler.getInstance(), 3000); + + @BeforeClass + public static void initEvoSuiteFramework() { + org.evosuite.runtime.RuntimeSettings.className = "org.openecomp.mso.openstack.exceptions.MsoTenantNotFound"; + org.evosuite.runtime.GuiSupport.initialize(); + org.evosuite.runtime.RuntimeSettings.maxNumberOfThreads = 100; + org.evosuite.runtime.RuntimeSettings.maxNumberOfIterationsPerLoop = 10000; + org.evosuite.runtime.RuntimeSettings.mockSystemIn = true; + org.evosuite.runtime.RuntimeSettings.sandboxMode = org.evosuite.runtime.sandbox.Sandbox.SandboxMode.RECOMMENDED; + org.evosuite.runtime.sandbox.Sandbox.initializeSecurityManagerForSUT(); + org.evosuite.runtime.classhandling.JDKClassResetter.init(); + initializeClasses(); + org.evosuite.runtime.Runtime.getInstance().resetRuntime(); + } + + @AfterClass + public static void clearEvoSuiteFramework(){ + Sandbox.resetDefaultSecurityManager(); + java.lang.System.setProperties((java.util.Properties) defaultProperties.clone()); + } + + @Before + public void initTestCase(){ + threadStopper.storeCurrentThreads(); + threadStopper.startRecordingTime(); + org.evosuite.runtime.jvm.ShutdownHookHandler.getInstance().initHandler(); + org.evosuite.runtime.sandbox.Sandbox.goingToExecuteSUTCode(); + + org.evosuite.runtime.GuiSupport.setHeadless(); + org.evosuite.runtime.Runtime.getInstance().resetRuntime(); + org.evosuite.runtime.agent.InstrumentingAgent.activate(); + } + + @After + public void doneWithTestCase(){ + threadStopper.killAndJoinClientThreads(); + org.evosuite.runtime.jvm.ShutdownHookHandler.getInstance().safeExecuteAddedHooks(); + org.evosuite.runtime.classhandling.JDKClassResetter.reset(); + resetClasses(); + org.evosuite.runtime.sandbox.Sandbox.doneWithExecutingSUTCode(); + org.evosuite.runtime.agent.InstrumentingAgent.deactivate(); + org.evosuite.runtime.GuiSupport.restoreHeadlessMode(); + } + + + private static void initializeClasses() { + org.evosuite.runtime.classhandling.ClassStateSupport.initializeClasses(MsoTenantNotFoundESTestscaffolding.class.getClassLoader() , + "org.openecomp.mso.openstack.exceptions.MsoTenantNotFound", + "org.openecomp.mso.openstack.exceptions.MsoExceptionCategory", + "org.openecomp.mso.openstack.exceptions.MsoException", + "org.openecomp.mso.openstack.exceptions.MsoOpenstackException" + ); + } + + private static void resetClasses() { + org.evosuite.runtime.classhandling.ClassResetter.getInstance().setClassLoader(MsoTenantNotFoundESTestscaffolding.class.getClassLoader()); + + org.evosuite.runtime.classhandling.ClassStateSupport.resetClasses( + "org.openecomp.mso.openstack.exceptions.MsoExceptionCategory", + "org.openecomp.mso.openstack.exceptions.MsoException", + "org.openecomp.mso.openstack.exceptions.MsoOpenstackException", + "org.openecomp.mso.openstack.exceptions.MsoTenantNotFound" + ); + } +} diff --git a/adapters/mso-adapter-utils/src/test/java/org/openecomp/mso/openstack/utils/MsoHeatEnvironmentEntryESTest.java b/adapters/mso-adapter-utils/src/test/java/org/openecomp/mso/openstack/utils/MsoHeatEnvironmentEntryESTest.java new file mode 100644 index 0000000000..6eaac45a43 --- /dev/null +++ b/adapters/mso-adapter-utils/src/test/java/org/openecomp/mso/openstack/utils/MsoHeatEnvironmentEntryESTest.java @@ -0,0 +1,562 @@ +/* + * This file was automatically generated by EvoSuite + * Mon Nov 14 08:40:12 GMT 2016 + */ + +package org.openecomp.mso.openstack.utils; + +import org.junit.Test; +import static org.junit.Assert.*; +import static org.evosuite.shaded.org.mockito.Mockito.*; +import static org.evosuite.runtime.EvoAssertions.*; +import org.openecomp.mso.db.catalog.beans.HeatTemplateParam; + +import java.util.LinkedHashSet; +import java.util.Set; +import org.evosuite.runtime.EvoRunner; +import org.evosuite.runtime.EvoRunnerParameters; +import org.evosuite.runtime.PrivateAccess; +import org.evosuite.runtime.ViolatedAssumptionAnswer; +import org.junit.runner.RunWith; + +@RunWith(EvoRunner.class) @EvoRunnerParameters(mockJVMNonDeterminism = true, useVFS = true, useVNET = true, resetStaticState = true, useJEE = true) +public class MsoHeatEnvironmentEntryESTest { + + @Test(timeout = 4000) + public void test00() throws Throwable { + MsoHeatEnvironmentEntry msoHeatEnvironmentEntry0 = new MsoHeatEnvironmentEntry(); + Set<MsoHeatEnvironmentResource> set0 = (Set<MsoHeatEnvironmentResource>) mock(Set.class, new ViolatedAssumptionAnswer()); + doReturn((-237540137)).when(set0).size(); + msoHeatEnvironmentEntry0.setResources(set0); + boolean boolean0 = msoHeatEnvironmentEntry0.hasResources(); + assertTrue(msoHeatEnvironmentEntry0.isValid()); + assertFalse(boolean0); + } + + @Test(timeout = 4000) + public void test01() throws Throwable { + MsoHeatEnvironmentEntry msoHeatEnvironmentEntry0 = new MsoHeatEnvironmentEntry(); + PrivateAccess.setVariable((Class<MsoHeatEnvironmentEntry>) MsoHeatEnvironmentEntry.class, msoHeatEnvironmentEntry0, "valid", (Object) false); + boolean boolean0 = msoHeatEnvironmentEntry0.isValid(); + assertFalse(boolean0); + } + + @Test(timeout = 4000) + public void test02() throws Throwable { + MsoHeatEnvironmentEntry msoHeatEnvironmentEntry0 = new MsoHeatEnvironmentEntry(); + LinkedHashSet<MsoHeatEnvironmentResource> linkedHashSet0 = new LinkedHashSet<MsoHeatEnvironmentResource>(); + msoHeatEnvironmentEntry0.setResources(linkedHashSet0); + msoHeatEnvironmentEntry0.getResources(); + assertTrue(msoHeatEnvironmentEntry0.isValid()); + } + + @Test(timeout = 4000) + public void test03() throws Throwable { + MsoHeatEnvironmentEntry msoHeatEnvironmentEntry0 = new MsoHeatEnvironmentEntry(); + MsoHeatEnvironmentResource msoHeatEnvironmentResource0 = new MsoHeatEnvironmentResource("9>KEckx", "8&T!e[SABZ"); + msoHeatEnvironmentEntry0.addResource(msoHeatEnvironmentResource0); + msoHeatEnvironmentEntry0.getResources(); + assertTrue(msoHeatEnvironmentEntry0.isValid()); + } + + @Test(timeout = 4000) + public void test04() throws Throwable { + MsoHeatEnvironmentEntry msoHeatEnvironmentEntry0 = new MsoHeatEnvironmentEntry(); + StringBuilder stringBuilder0 = msoHeatEnvironmentEntry0.toFullString(); + PrivateAccess.setVariable((Class<MsoHeatEnvironmentEntry>) MsoHeatEnvironmentEntry.class, msoHeatEnvironmentEntry0, "rawEntry", (Object) stringBuilder0); + StringBuilder stringBuilder1 = msoHeatEnvironmentEntry0.getRawEntry(); + assertEquals("\nnull", stringBuilder1.toString()); + assertTrue(msoHeatEnvironmentEntry0.isValid()); + } + + @Test(timeout = 4000) + public void test05() throws Throwable { + MsoHeatEnvironmentEntry msoHeatEnvironmentEntry0 = new MsoHeatEnvironmentEntry(); + LinkedHashSet<MsoHeatEnvironmentParameter> linkedHashSet0 = new LinkedHashSet<MsoHeatEnvironmentParameter>(); + msoHeatEnvironmentEntry0.setParameters(linkedHashSet0); + msoHeatEnvironmentEntry0.getParameters(); + assertTrue(msoHeatEnvironmentEntry0.isValid()); + } + + @Test(timeout = 4000) + public void test06() throws Throwable { + MsoHeatEnvironmentEntry msoHeatEnvironmentEntry0 = new MsoHeatEnvironmentEntry(); + MsoHeatEnvironmentParameter msoHeatEnvironmentParameter0 = new MsoHeatEnvironmentParameter(); + msoHeatEnvironmentEntry0.addParameter(msoHeatEnvironmentParameter0); + msoHeatEnvironmentEntry0.getParameters(); + assertTrue(msoHeatEnvironmentEntry0.isValid()); + } + + @Test(timeout = 4000) + public void test07() throws Throwable { + MsoHeatEnvironmentEntry msoHeatEnvironmentEntry0 = new MsoHeatEnvironmentEntry(); + LinkedHashSet<MsoHeatEnvironmentResource> linkedHashSet0 = new LinkedHashSet<MsoHeatEnvironmentResource>(); + msoHeatEnvironmentEntry0.setResources(linkedHashSet0); + msoHeatEnvironmentEntry0.getNumberOfResources(); + assertTrue(msoHeatEnvironmentEntry0.isValid()); + } + + @Test(timeout = 4000) + public void test08() throws Throwable { + MsoHeatEnvironmentEntry msoHeatEnvironmentEntry0 = new MsoHeatEnvironmentEntry(); + MsoHeatEnvironmentResource msoHeatEnvironmentResource0 = new MsoHeatEnvironmentResource(); + msoHeatEnvironmentEntry0.addResource(msoHeatEnvironmentResource0); + msoHeatEnvironmentEntry0.getNumberOfResources(); + assertTrue(msoHeatEnvironmentEntry0.isValid()); + } + + @Test(timeout = 4000) + public void test09() throws Throwable { + MsoHeatEnvironmentEntry msoHeatEnvironmentEntry0 = new MsoHeatEnvironmentEntry(); + Set<MsoHeatEnvironmentResource> set0 = (Set<MsoHeatEnvironmentResource>) mock(Set.class, new ViolatedAssumptionAnswer()); + doReturn(0).when(set0).size(); + msoHeatEnvironmentEntry0.setResources(set0); + msoHeatEnvironmentEntry0.getNumberOfResources(); + assertTrue(msoHeatEnvironmentEntry0.isValid()); + } + + @Test(timeout = 4000) + public void test10() throws Throwable { + MsoHeatEnvironmentEntry msoHeatEnvironmentEntry0 = new MsoHeatEnvironmentEntry(); + LinkedHashSet<MsoHeatEnvironmentParameter> linkedHashSet0 = new LinkedHashSet<MsoHeatEnvironmentParameter>(); + msoHeatEnvironmentEntry0.setParameters(linkedHashSet0); + msoHeatEnvironmentEntry0.getNumberOfParameters(); + assertTrue(msoHeatEnvironmentEntry0.isValid()); + } + + @Test(timeout = 4000) + public void test11() throws Throwable { + MsoHeatEnvironmentEntry msoHeatEnvironmentEntry0 = new MsoHeatEnvironmentEntry(); + MsoHeatEnvironmentParameter msoHeatEnvironmentParameter0 = new MsoHeatEnvironmentParameter(); + msoHeatEnvironmentEntry0.addParameter(msoHeatEnvironmentParameter0); + msoHeatEnvironmentEntry0.getNumberOfParameters(); + assertTrue(msoHeatEnvironmentEntry0.isValid()); + } + + @Test(timeout = 4000) + public void test12() throws Throwable { + MsoHeatEnvironmentEntry msoHeatEnvironmentEntry0 = new MsoHeatEnvironmentEntry(); + PrivateAccess.setVariable((Class<MsoHeatEnvironmentEntry>) MsoHeatEnvironmentEntry.class, msoHeatEnvironmentEntry0, "errorString", (Object) "Param="); + msoHeatEnvironmentEntry0.getErrorString(); + assertTrue(msoHeatEnvironmentEntry0.isValid()); + } + + @Test(timeout = 4000) + public void test13() throws Throwable { + MsoHeatEnvironmentEntry msoHeatEnvironmentEntry0 = new MsoHeatEnvironmentEntry(); + Set<HeatTemplateParam> set0 = (Set<HeatTemplateParam>) mock(Set.class, new ViolatedAssumptionAnswer()); + doReturn((-2945)).when(set0).size(); + // Undeclared exception! + try { + msoHeatEnvironmentEntry0.toFullStringExcludeNonParams(set0); + fail("Expecting exception: IllegalArgumentException"); + + } catch(IllegalArgumentException e) { + // + // Illegal Capacity: -2945 + // + verifyException("java.util.ArrayList", e); + } + } + + @Test(timeout = 4000) + public void test14() throws Throwable { + MsoHeatEnvironmentEntry msoHeatEnvironmentEntry0 = new MsoHeatEnvironmentEntry(); + LinkedHashSet<MsoHeatEnvironmentParameter> linkedHashSet0 = new LinkedHashSet<MsoHeatEnvironmentParameter>(); + linkedHashSet0.add((MsoHeatEnvironmentParameter) null); + msoHeatEnvironmentEntry0.setParameters(linkedHashSet0); + // Undeclared exception! + try { + msoHeatEnvironmentEntry0.toFullString(); + fail("Expecting exception: NullPointerException"); + + } catch(NullPointerException e) { + // + // no message in exception (getMessage() returned null) + // + verifyException("org.openecomp.mso.openstack.utils.MsoHeatEnvironmentEntry", e); + } + } + + @Test(timeout = 4000) + public void test15() throws Throwable { + MsoHeatEnvironmentEntry msoHeatEnvironmentEntry0 = new MsoHeatEnvironmentEntry(); + MsoHeatEnvironmentParameter msoHeatEnvironmentParameter0 = new MsoHeatEnvironmentParameter(); + msoHeatEnvironmentEntry0.addParameter(msoHeatEnvironmentParameter0); + // Undeclared exception! + try { + msoHeatEnvironmentEntry0.containsParameter((String) null, ""); + fail("Expecting exception: NullPointerException"); + + } catch(NullPointerException e) { + // + // no message in exception (getMessage() returned null) + // + verifyException("org.openecomp.mso.openstack.utils.MsoHeatEnvironmentParameter", e); + } + } + + @Test(timeout = 4000) + public void test16() throws Throwable { + MsoHeatEnvironmentEntry msoHeatEnvironmentEntry0 = new MsoHeatEnvironmentEntry(); + LinkedHashSet<MsoHeatEnvironmentParameter> linkedHashSet0 = new LinkedHashSet<MsoHeatEnvironmentParameter>(); + MsoHeatEnvironmentParameter msoHeatEnvironmentParameter0 = new MsoHeatEnvironmentParameter(); + linkedHashSet0.add(msoHeatEnvironmentParameter0); + msoHeatEnvironmentEntry0.setParameters(linkedHashSet0); + // Undeclared exception! + try { + msoHeatEnvironmentEntry0.containsParameter((String) null); + fail("Expecting exception: NullPointerException"); + + } catch(NullPointerException e) { + // + // no message in exception (getMessage() returned null) + // + verifyException("org.openecomp.mso.openstack.utils.MsoHeatEnvironmentParameter", e); + } + } + + @Test(timeout = 4000) + public void test17() throws Throwable { + MsoHeatEnvironmentEntry msoHeatEnvironmentEntry0 = new MsoHeatEnvironmentEntry(); + MsoHeatEnvironmentResource msoHeatEnvironmentResource0 = new MsoHeatEnvironmentResource(); + msoHeatEnvironmentEntry0.addResource(msoHeatEnvironmentResource0); + MsoHeatEnvironmentResource msoHeatEnvironmentResource1 = new MsoHeatEnvironmentResource(); + // Undeclared exception! + try { + msoHeatEnvironmentEntry0.addResource(msoHeatEnvironmentResource1); + fail("Expecting exception: NullPointerException"); + + } catch(NullPointerException e) { + // + // no message in exception (getMessage() returned null) + // + verifyException("org.openecomp.mso.openstack.utils.MsoHeatEnvironmentResource", e); + } + } + + @Test(timeout = 4000) + public void test18() throws Throwable { + MsoHeatEnvironmentEntry msoHeatEnvironmentEntry0 = new MsoHeatEnvironmentEntry(); + MsoHeatEnvironmentParameter msoHeatEnvironmentParameter0 = new MsoHeatEnvironmentParameter(); + msoHeatEnvironmentEntry0.addParameter(msoHeatEnvironmentParameter0); + MsoHeatEnvironmentParameter msoHeatEnvironmentParameter1 = new MsoHeatEnvironmentParameter(); + // Undeclared exception! + try { + msoHeatEnvironmentEntry0.addParameter(msoHeatEnvironmentParameter1); + fail("Expecting exception: NullPointerException"); + + } catch(NullPointerException e) { + // + // no message in exception (getMessage() returned null) + // + verifyException("org.openecomp.mso.openstack.utils.MsoHeatEnvironmentParameter", e); + } + } + + @Test(timeout = 4000) + public void test19() throws Throwable { + MsoHeatEnvironmentEntry msoHeatEnvironmentEntry0 = new MsoHeatEnvironmentEntry(); + MsoHeatEnvironmentParameter msoHeatEnvironmentParameter0 = new MsoHeatEnvironmentParameter("", ""); + msoHeatEnvironmentEntry0.addParameter(msoHeatEnvironmentParameter0); + boolean boolean0 = msoHeatEnvironmentEntry0.containsParameter(""); + assertTrue(msoHeatEnvironmentEntry0.isValid()); + assertTrue(boolean0); + } + + @Test(timeout = 4000) + public void test20() throws Throwable { + MsoHeatEnvironmentEntry msoHeatEnvironmentEntry0 = new MsoHeatEnvironmentEntry(); + MsoHeatEnvironmentParameter msoHeatEnvironmentParameter0 = new MsoHeatEnvironmentParameter(); + msoHeatEnvironmentEntry0.addParameter(msoHeatEnvironmentParameter0); + boolean boolean0 = msoHeatEnvironmentEntry0.hasParameters(); + assertTrue(boolean0); + } + + @Test(timeout = 4000) + public void test21() throws Throwable { + MsoHeatEnvironmentEntry msoHeatEnvironmentEntry0 = new MsoHeatEnvironmentEntry(); + msoHeatEnvironmentEntry0.hasParameters(); + assertTrue(msoHeatEnvironmentEntry0.isValid()); + } + + @Test(timeout = 4000) + public void test22() throws Throwable { + MsoHeatEnvironmentEntry msoHeatEnvironmentEntry0 = new MsoHeatEnvironmentEntry(); + LinkedHashSet<MsoHeatEnvironmentParameter> linkedHashSet0 = new LinkedHashSet<MsoHeatEnvironmentParameter>(); + msoHeatEnvironmentEntry0.setParameters(linkedHashSet0); + boolean boolean0 = msoHeatEnvironmentEntry0.hasParameters(); + assertTrue(msoHeatEnvironmentEntry0.isValid()); + assertFalse(boolean0); + } + + @Test(timeout = 4000) + public void test23() throws Throwable { + MsoHeatEnvironmentEntry msoHeatEnvironmentEntry0 = new MsoHeatEnvironmentEntry(); + PrivateAccess.callMethod((Class<MsoHeatEnvironmentEntry>) MsoHeatEnvironmentEntry.class, msoHeatEnvironmentEntry0, "getResourceRegistryRawEntry"); + assertTrue(msoHeatEnvironmentEntry0.isValid()); + } + + @Test(timeout = 4000) + public void test24() throws Throwable { + MsoHeatEnvironmentEntry msoHeatEnvironmentEntry0 = new MsoHeatEnvironmentEntry(); + LinkedHashSet<HeatTemplateParam> linkedHashSet0 = new LinkedHashSet<HeatTemplateParam>(); + MsoHeatEnvironmentParameter msoHeatEnvironmentParameter0 = new MsoHeatEnvironmentParameter(); + msoHeatEnvironmentParameter0.setValue("_BAD"); + HeatTemplateParam heatTemplateParam0 = new HeatTemplateParam(); + linkedHashSet0.add(heatTemplateParam0); + msoHeatEnvironmentEntry0.addParameter(msoHeatEnvironmentParameter0); + msoHeatEnvironmentEntry0.toFullStringExcludeNonParams(linkedHashSet0); + assertTrue(msoHeatEnvironmentEntry0.hasParameters()); + } + + @Test(timeout = 4000) + public void test25() throws Throwable { + MsoHeatEnvironmentEntry msoHeatEnvironmentEntry0 = new MsoHeatEnvironmentEntry(); + LinkedHashSet<HeatTemplateParam> linkedHashSet0 = new LinkedHashSet<HeatTemplateParam>(); + MsoHeatEnvironmentParameter msoHeatEnvironmentParameter0 = new MsoHeatEnvironmentParameter(); + msoHeatEnvironmentParameter0.setValue("t'N`.KI:L9"); + HeatTemplateParam heatTemplateParam0 = new HeatTemplateParam(); + linkedHashSet0.add(heatTemplateParam0); + msoHeatEnvironmentEntry0.addParameter(msoHeatEnvironmentParameter0); + msoHeatEnvironmentEntry0.toFullStringExcludeNonParams(linkedHashSet0); + assertTrue(msoHeatEnvironmentEntry0.hasParameters()); + } + + @Test(timeout = 4000) + public void test26() throws Throwable { + MsoHeatEnvironmentEntry msoHeatEnvironmentEntry0 = new MsoHeatEnvironmentEntry(); + LinkedHashSet<HeatTemplateParam> linkedHashSet0 = new LinkedHashSet<HeatTemplateParam>(); + MsoHeatEnvironmentParameter msoHeatEnvironmentParameter0 = new MsoHeatEnvironmentParameter(); + HeatTemplateParam heatTemplateParam0 = new HeatTemplateParam(); + linkedHashSet0.add(heatTemplateParam0); + msoHeatEnvironmentEntry0.addParameter(msoHeatEnvironmentParameter0); + // Undeclared exception! + try { + msoHeatEnvironmentEntry0.toFullStringExcludeNonParams(linkedHashSet0); + fail("Expecting exception: NullPointerException"); + + } catch(NullPointerException e) { + } + } + + @Test(timeout = 4000) + public void test27() throws Throwable { + MsoHeatEnvironmentEntry msoHeatEnvironmentEntry0 = new MsoHeatEnvironmentEntry(); + MsoHeatEnvironmentParameter msoHeatEnvironmentParameter0 = new MsoHeatEnvironmentParameter(""); + msoHeatEnvironmentEntry0.addParameter(msoHeatEnvironmentParameter0); + LinkedHashSet<HeatTemplateParam> linkedHashSet0 = new LinkedHashSet<HeatTemplateParam>(); + msoHeatEnvironmentEntry0.toFullStringExcludeNonParams(linkedHashSet0); + assertTrue(msoHeatEnvironmentEntry0.hasParameters()); + } + + @Test(timeout = 4000) + public void test28() throws Throwable { + MsoHeatEnvironmentEntry msoHeatEnvironmentEntry0 = new MsoHeatEnvironmentEntry(); + LinkedHashSet<HeatTemplateParam> linkedHashSet0 = new LinkedHashSet<HeatTemplateParam>(); + HeatTemplateParam heatTemplateParam0 = new HeatTemplateParam(); + linkedHashSet0.add(heatTemplateParam0); + msoHeatEnvironmentEntry0.toFullStringExcludeNonParams(linkedHashSet0); + assertTrue(msoHeatEnvironmentEntry0.isValid()); + } + + @Test(timeout = 4000) + public void test29() throws Throwable { + MsoHeatEnvironmentEntry msoHeatEnvironmentEntry0 = new MsoHeatEnvironmentEntry(); + assertFalse(msoHeatEnvironmentEntry0.hasParameters()); + + LinkedHashSet<HeatTemplateParam> linkedHashSet0 = new LinkedHashSet<HeatTemplateParam>(); + StringBuilder stringBuilder0 = msoHeatEnvironmentEntry0.toFullStringExcludeNonParams(linkedHashSet0); + PrivateAccess.setVariable((Class<MsoHeatEnvironmentEntry>) MsoHeatEnvironmentEntry.class, msoHeatEnvironmentEntry0, "rawEntry", (Object) stringBuilder0); + StringBuilder stringBuilder1 = (StringBuilder)PrivateAccess.callMethod((Class<MsoHeatEnvironmentEntry>) MsoHeatEnvironmentEntry.class, msoHeatEnvironmentEntry0, "getResourceRegistryRawEntry"); + assertTrue(msoHeatEnvironmentEntry0.isValid()); + assertNull(stringBuilder1); + } + + @Test(timeout = 4000) + public void test30() throws Throwable { + MsoHeatEnvironmentEntry msoHeatEnvironmentEntry0 = new MsoHeatEnvironmentEntry(); + MsoHeatEnvironmentParameter msoHeatEnvironmentParameter0 = new MsoHeatEnvironmentParameter(""); + msoHeatEnvironmentEntry0.addParameter(msoHeatEnvironmentParameter0); + boolean boolean0 = msoHeatEnvironmentEntry0.containsParameter("9MTP2Qt0FH.^", ""); + assertTrue(boolean0); + assertTrue(msoHeatEnvironmentEntry0.isValid()); + } + + @Test(timeout = 4000) + public void test31() throws Throwable { + MsoHeatEnvironmentEntry msoHeatEnvironmentEntry0 = new MsoHeatEnvironmentEntry(); + boolean boolean0 = msoHeatEnvironmentEntry0.containsParameter("dP:* hj", "dP:* hj"); + assertFalse(boolean0); + assertTrue(msoHeatEnvironmentEntry0.isValid()); + } + + @Test(timeout = 4000) + public void test32() throws Throwable { + MsoHeatEnvironmentEntry msoHeatEnvironmentEntry0 = new MsoHeatEnvironmentEntry(); + MsoHeatEnvironmentParameter msoHeatEnvironmentParameter0 = new MsoHeatEnvironmentParameter(""); + msoHeatEnvironmentEntry0.addParameter(msoHeatEnvironmentParameter0); + boolean boolean0 = msoHeatEnvironmentEntry0.containsParameter("", ""); + assertTrue(boolean0); + assertTrue(msoHeatEnvironmentEntry0.isValid()); + } + + @Test(timeout = 4000) + public void test33() throws Throwable { + MsoHeatEnvironmentEntry msoHeatEnvironmentEntry0 = new MsoHeatEnvironmentEntry(); + LinkedHashSet<MsoHeatEnvironmentParameter> linkedHashSet0 = new LinkedHashSet<MsoHeatEnvironmentParameter>(); + MsoHeatEnvironmentParameter msoHeatEnvironmentParameter0 = mock(MsoHeatEnvironmentParameter.class, new ViolatedAssumptionAnswer()); + linkedHashSet0.add(msoHeatEnvironmentParameter0); + msoHeatEnvironmentEntry0.setParameters(linkedHashSet0); + boolean boolean0 = msoHeatEnvironmentEntry0.containsParameter("kz`LZx"); + assertTrue(msoHeatEnvironmentEntry0.hasParameters()); + assertFalse(boolean0); + } + + @Test(timeout = 4000) + public void test34() throws Throwable { + MsoHeatEnvironmentEntry msoHeatEnvironmentEntry0 = new MsoHeatEnvironmentEntry(); + LinkedHashSet<MsoHeatEnvironmentParameter> linkedHashSet0 = new LinkedHashSet<MsoHeatEnvironmentParameter>(); + msoHeatEnvironmentEntry0.setParameters(linkedHashSet0); + boolean boolean0 = msoHeatEnvironmentEntry0.containsParameter("kz`LZx"); + assertFalse(boolean0); + assertTrue(msoHeatEnvironmentEntry0.isValid()); + } + + @Test(timeout = 4000) + public void test35() throws Throwable { + MsoHeatEnvironmentEntry msoHeatEnvironmentEntry0 = new MsoHeatEnvironmentEntry(); + boolean boolean0 = msoHeatEnvironmentEntry0.containsParameter(",=?%4z"); + assertTrue(msoHeatEnvironmentEntry0.isValid()); + assertFalse(boolean0); + } + + @Test(timeout = 4000) + public void test36() throws Throwable { + MsoHeatEnvironmentEntry msoHeatEnvironmentEntry0 = new MsoHeatEnvironmentEntry(); + LinkedHashSet<MsoHeatEnvironmentParameter> linkedHashSet0 = new LinkedHashSet<MsoHeatEnvironmentParameter>(); + MsoHeatEnvironmentParameter msoHeatEnvironmentParameter0 = mock(MsoHeatEnvironmentParameter.class, new ViolatedAssumptionAnswer()); + doReturn((String) null).when(msoHeatEnvironmentParameter0).getName(); + doReturn((String) null).when(msoHeatEnvironmentParameter0).getValue(); + linkedHashSet0.add(msoHeatEnvironmentParameter0); + msoHeatEnvironmentEntry0.setParameters(linkedHashSet0); + msoHeatEnvironmentEntry0.toFullString(); + assertTrue(msoHeatEnvironmentEntry0.hasParameters()); + } + + @Test(timeout = 4000) + public void test37() throws Throwable { + MsoHeatEnvironmentEntry msoHeatEnvironmentEntry0 = new MsoHeatEnvironmentEntry(); + MsoHeatEnvironmentResource msoHeatEnvironmentResource0 = new MsoHeatEnvironmentResource(""); + msoHeatEnvironmentEntry0.addResource(msoHeatEnvironmentResource0); + boolean boolean0 = msoHeatEnvironmentEntry0.hasResources(); + assertTrue(boolean0); + } + + @Test(timeout = 4000) + public void test38() throws Throwable { + MsoHeatEnvironmentEntry msoHeatEnvironmentEntry0 = new MsoHeatEnvironmentEntry(); + Set<MsoHeatEnvironmentResource> set0 = (Set<MsoHeatEnvironmentResource>) mock(Set.class, new ViolatedAssumptionAnswer()); + doReturn(0).when(set0).size(); + msoHeatEnvironmentEntry0.setResources(set0); + boolean boolean0 = msoHeatEnvironmentEntry0.hasResources(); + assertTrue(msoHeatEnvironmentEntry0.isValid()); + assertFalse(boolean0); + } + + @Test(timeout = 4000) + public void test39() throws Throwable { + MsoHeatEnvironmentEntry msoHeatEnvironmentEntry0 = new MsoHeatEnvironmentEntry(); + boolean boolean0 = msoHeatEnvironmentEntry0.hasResources(); + assertFalse(boolean0); + assertTrue(msoHeatEnvironmentEntry0.isValid()); + } + + @Test(timeout = 4000) + public void test40() throws Throwable { + MsoHeatEnvironmentEntry msoHeatEnvironmentEntry0 = new MsoHeatEnvironmentEntry(); + msoHeatEnvironmentEntry0.setResources((Set<MsoHeatEnvironmentResource>) null); + assertTrue(msoHeatEnvironmentEntry0.isValid()); + } + + @Test(timeout = 4000) + public void test41() throws Throwable { + MsoHeatEnvironmentEntry msoHeatEnvironmentEntry0 = new MsoHeatEnvironmentEntry(); + msoHeatEnvironmentEntry0.setParameters((Set<MsoHeatEnvironmentParameter>) null); + assertTrue(msoHeatEnvironmentEntry0.isValid()); + } + + + @Test(timeout = 4000) + public void test43() throws Throwable { + MsoHeatEnvironmentEntry msoHeatEnvironmentEntry0 = new MsoHeatEnvironmentEntry(); + // Undeclared exception! + try { + msoHeatEnvironmentEntry0.getNumberOfResources(); + fail("Expecting exception: NullPointerException"); + + } catch(NullPointerException e) { + // + // no message in exception (getMessage() returned null) + // + verifyException("org.openecomp.mso.openstack.utils.MsoHeatEnvironmentEntry", e); + } + } + + @Test(timeout = 4000) + public void test44() throws Throwable { + MsoHeatEnvironmentEntry msoHeatEnvironmentEntry0 = new MsoHeatEnvironmentEntry(); + boolean boolean0 = msoHeatEnvironmentEntry0.isValid(); + assertTrue(boolean0); + } + + @Test(timeout = 4000) + public void test45() throws Throwable { + MsoHeatEnvironmentEntry msoHeatEnvironmentEntry0 = new MsoHeatEnvironmentEntry((StringBuilder) null); + assertTrue(msoHeatEnvironmentEntry0.isValid()); + } + + @Test(timeout = 4000) + public void test46() throws Throwable { + MsoHeatEnvironmentEntry msoHeatEnvironmentEntry0 = new MsoHeatEnvironmentEntry(); + // Undeclared exception! + try { + msoHeatEnvironmentEntry0.getNumberOfParameters(); + fail("Expecting exception: NullPointerException"); + + } catch(NullPointerException e) { + // + // no message in exception (getMessage() returned null) + // + verifyException("org.openecomp.mso.openstack.utils.MsoHeatEnvironmentEntry", e); + } + } + + @Test(timeout = 4000) + public void test47() throws Throwable { + MsoHeatEnvironmentEntry msoHeatEnvironmentEntry0 = new MsoHeatEnvironmentEntry(); + msoHeatEnvironmentEntry0.getRawEntry(); + assertTrue(msoHeatEnvironmentEntry0.isValid()); + } + + @Test(timeout = 4000) + public void test48() throws Throwable { + MsoHeatEnvironmentEntry msoHeatEnvironmentEntry0 = new MsoHeatEnvironmentEntry(); + msoHeatEnvironmentEntry0.getParameters(); + assertTrue(msoHeatEnvironmentEntry0.isValid()); + } + + @Test(timeout = 4000) + public void test49() throws Throwable { + MsoHeatEnvironmentEntry msoHeatEnvironmentEntry0 = new MsoHeatEnvironmentEntry(); + msoHeatEnvironmentEntry0.getResources(); + assertTrue(msoHeatEnvironmentEntry0.isValid()); + } + + @Test(timeout = 4000) + public void test50() throws Throwable { + MsoHeatEnvironmentEntry msoHeatEnvironmentEntry0 = new MsoHeatEnvironmentEntry(); + msoHeatEnvironmentEntry0.getErrorString(); + assertTrue(msoHeatEnvironmentEntry0.isValid()); + } +} diff --git a/adapters/mso-adapter-utils/src/test/java/org/openecomp/mso/openstack/utils/MsoHeatEnvironmentParameterESTest.java b/adapters/mso-adapter-utils/src/test/java/org/openecomp/mso/openstack/utils/MsoHeatEnvironmentParameterESTest.java new file mode 100644 index 0000000000..6ec389b809 --- /dev/null +++ b/adapters/mso-adapter-utils/src/test/java/org/openecomp/mso/openstack/utils/MsoHeatEnvironmentParameterESTest.java @@ -0,0 +1,129 @@ +/* + * This file was automatically generated by EvoSuite + * Mon Nov 14 08:45:40 GMT 2016 + */ + +package org.openecomp.mso.openstack.utils; + +import org.junit.Test; +import static org.junit.Assert.*; + +import org.evosuite.runtime.EvoRunner; +import org.evosuite.runtime.EvoRunnerParameters; +import org.junit.runner.RunWith; + +@RunWith(EvoRunner.class) @EvoRunnerParameters(mockJVMNonDeterminism = true, useVFS = true, useVNET = true, resetStaticState = true, useJEE = true) +public class MsoHeatEnvironmentParameterESTest extends MsoHeatEnvironmentParameterESTestscaffolding { + + @Test(timeout = 4000) + public void test00() throws Throwable { + MsoHeatEnvironmentParameter msoHeatEnvironmentParameter0 = new MsoHeatEnvironmentParameter(); + msoHeatEnvironmentParameter0.hashCode(); + } + + @Test(timeout = 4000) + public void test01() throws Throwable { + MsoHeatEnvironmentParameter msoHeatEnvironmentParameter0 = new MsoHeatEnvironmentParameter(""); + boolean boolean0 = msoHeatEnvironmentParameter0.equals(msoHeatEnvironmentParameter0); + assertTrue(boolean0); + } + + @Test(timeout = 4000) + public void test02() throws Throwable { + MsoHeatEnvironmentParameter msoHeatEnvironmentParameter0 = new MsoHeatEnvironmentParameter(""); + msoHeatEnvironmentParameter0.setValue(""); + String string0 = msoHeatEnvironmentParameter0.getValue(); + assertEquals("", string0); + } + + @Test(timeout = 4000) + public void test03() throws Throwable { + MsoHeatEnvironmentParameter msoHeatEnvironmentParameter0 = new MsoHeatEnvironmentParameter(); + String string0 = msoHeatEnvironmentParameter0.getName(); + assertNull(string0); + } + + @Test(timeout = 4000) + public void test04() throws Throwable { + MsoHeatEnvironmentParameter msoHeatEnvironmentParameter0 = new MsoHeatEnvironmentParameter("<*+ogA@v;MO4'8{1"); + String string0 = msoHeatEnvironmentParameter0.getName(); + assertEquals("<*+ogA@v;MO4'8{1", string0); + } + + @Test(timeout = 4000) + public void test05() throws Throwable { + MsoHeatEnvironmentParameter msoHeatEnvironmentParameter0 = new MsoHeatEnvironmentParameter(""); + String string0 = msoHeatEnvironmentParameter0.getName(); + assertEquals("", string0); + } + + @Test(timeout = 4000) + public void test06() throws Throwable { + MsoHeatEnvironmentParameter msoHeatEnvironmentParameter0 = new MsoHeatEnvironmentParameter("", "-3Y=_MqzpVL7|^$8"); + String string0 = msoHeatEnvironmentParameter0.getValue(); + assertEquals("-3Y=_MqzpVL7|^$8", string0); + } + + @Test(timeout = 4000) + public void test07() throws Throwable { + MsoHeatEnvironmentParameter msoHeatEnvironmentParameter0 = new MsoHeatEnvironmentParameter(""); + MsoHeatEnvironmentParameter msoHeatEnvironmentParameter1 = new MsoHeatEnvironmentParameter("{Ox?zu\"*"); + boolean boolean0 = msoHeatEnvironmentParameter1.equals(msoHeatEnvironmentParameter0); + assertFalse(boolean0); + } + + @Test(timeout = 4000) + public void test08() throws Throwable { + MsoHeatEnvironmentParameter msoHeatEnvironmentParameter0 = new MsoHeatEnvironmentParameter("?.@!au:}y7xGSg|}8"); + boolean boolean0 = msoHeatEnvironmentParameter0.equals("?.@!au:}y7xGSg|}8"); + assertFalse(boolean0); + } + + @Test(timeout = 4000) + public void test09() throws Throwable { + MsoHeatEnvironmentParameter msoHeatEnvironmentParameter0 = new MsoHeatEnvironmentParameter(""); + msoHeatEnvironmentParameter0.setName(""); + assertEquals("", msoHeatEnvironmentParameter0.getName()); + } + + @Test(timeout = 4000) + public void test10() throws Throwable { + MsoHeatEnvironmentParameter msoHeatEnvironmentParameter0 = new MsoHeatEnvironmentParameter(""); + MsoHeatEnvironmentParameter msoHeatEnvironmentParameter1 = new MsoHeatEnvironmentParameter(""); + boolean boolean0 = msoHeatEnvironmentParameter0.equals(msoHeatEnvironmentParameter1); + assertTrue(boolean0); + } + + @Test(timeout = 4000) + public void test11() throws Throwable { + MsoHeatEnvironmentParameter msoHeatEnvironmentParameter0 = new MsoHeatEnvironmentParameter(""); + String string0 = msoHeatEnvironmentParameter0.getValue(); + assertNull(string0); + } + + @Test(timeout = 4000) + public void test12() throws Throwable { + MsoHeatEnvironmentParameter msoHeatEnvironmentParameter0 = new MsoHeatEnvironmentParameter(""); + msoHeatEnvironmentParameter0.hashCode(); + } + + @Test(timeout = 4000) + public void test13() throws Throwable { + MsoHeatEnvironmentParameter msoHeatEnvironmentParameter0 = new MsoHeatEnvironmentParameter(); + MsoHeatEnvironmentParameter msoHeatEnvironmentParameter1 = new MsoHeatEnvironmentParameter(); + // Undeclared exception! + try { + msoHeatEnvironmentParameter0.equals(msoHeatEnvironmentParameter1); + fail("Expecting exception: NullPointerException"); + + } catch(NullPointerException e) { + } + } + + @Test(timeout = 4000) + public void test14() throws Throwable { + MsoHeatEnvironmentParameter msoHeatEnvironmentParameter0 = new MsoHeatEnvironmentParameter(""); + String string0 = msoHeatEnvironmentParameter0.toString(); + assertEquals(": null", string0); + } +} diff --git a/adapters/mso-adapter-utils/src/test/java/org/openecomp/mso/openstack/utils/MsoHeatEnvironmentParameterESTestscaffolding.java b/adapters/mso-adapter-utils/src/test/java/org/openecomp/mso/openstack/utils/MsoHeatEnvironmentParameterESTestscaffolding.java new file mode 100644 index 0000000000..f7e33bb8ce --- /dev/null +++ b/adapters/mso-adapter-utils/src/test/java/org/openecomp/mso/openstack/utils/MsoHeatEnvironmentParameterESTestscaffolding.java @@ -0,0 +1,78 @@ +/** + * Scaffolding file used to store all the setups needed to run + * tests automatically generated by EvoSuite + * Mon Nov 14 08:45:40 GMT 2016 + */ + +package org.openecomp.mso.openstack.utils; + +import org.evosuite.runtime.annotation.EvoSuiteClassExclude; +import org.junit.BeforeClass; +import org.junit.Before; +import org.junit.After; +import org.junit.AfterClass; +import org.evosuite.runtime.sandbox.Sandbox; + +@EvoSuiteClassExclude +public class MsoHeatEnvironmentParameterESTestscaffolding { + + @org.junit.Rule + public org.evosuite.runtime.vnet.NonFunctionalRequirementRule nfr = new org.evosuite.runtime.vnet.NonFunctionalRequirementRule(); + + private static final java.util.Properties defaultProperties = (java.util.Properties) java.lang.System.getProperties().clone(); + + private org.evosuite.runtime.thread.ThreadStopper threadStopper = new org.evosuite.runtime.thread.ThreadStopper (org.evosuite.runtime.thread.KillSwitchHandler.getInstance(), 3000); + + @BeforeClass + public static void initEvoSuiteFramework() { + org.evosuite.runtime.RuntimeSettings.className = "org.openecomp.mso.openstack.utils.MsoHeatEnvironmentParameter"; + org.evosuite.runtime.GuiSupport.initialize(); + org.evosuite.runtime.RuntimeSettings.maxNumberOfThreads = 100; + org.evosuite.runtime.RuntimeSettings.maxNumberOfIterationsPerLoop = 10000; + org.evosuite.runtime.RuntimeSettings.mockSystemIn = true; + org.evosuite.runtime.RuntimeSettings.sandboxMode = org.evosuite.runtime.sandbox.Sandbox.SandboxMode.RECOMMENDED; + org.evosuite.runtime.sandbox.Sandbox.initializeSecurityManagerForSUT(); + org.evosuite.runtime.classhandling.JDKClassResetter.init(); + initializeClasses(); + org.evosuite.runtime.Runtime.getInstance().resetRuntime(); + } + + @AfterClass + public static void clearEvoSuiteFramework(){ + Sandbox.resetDefaultSecurityManager(); + java.lang.System.setProperties((java.util.Properties) defaultProperties.clone()); + } + + @Before + public void initTestCase(){ + threadStopper.storeCurrentThreads(); + threadStopper.startRecordingTime(); + org.evosuite.runtime.jvm.ShutdownHookHandler.getInstance().initHandler(); + org.evosuite.runtime.sandbox.Sandbox.goingToExecuteSUTCode(); + + org.evosuite.runtime.GuiSupport.setHeadless(); + org.evosuite.runtime.Runtime.getInstance().resetRuntime(); + org.evosuite.runtime.agent.InstrumentingAgent.activate(); + } + + @After + public void doneWithTestCase(){ + threadStopper.killAndJoinClientThreads(); + org.evosuite.runtime.jvm.ShutdownHookHandler.getInstance().safeExecuteAddedHooks(); + org.evosuite.runtime.classhandling.JDKClassResetter.reset(); + resetClasses(); + org.evosuite.runtime.sandbox.Sandbox.doneWithExecutingSUTCode(); + org.evosuite.runtime.agent.InstrumentingAgent.deactivate(); + org.evosuite.runtime.GuiSupport.restoreHeadlessMode(); + } + + + private static void initializeClasses() { + org.evosuite.runtime.classhandling.ClassStateSupport.initializeClasses(MsoHeatEnvironmentParameterESTestscaffolding.class.getClassLoader() , + "org.openecomp.mso.openstack.utils.MsoHeatEnvironmentParameter" + ); + } + + private static void resetClasses() { + } +} diff --git a/adapters/mso-adapter-utils/src/test/java/org/openecomp/mso/openstack/utils/MsoHeatEnvironmentResourceESTest.java b/adapters/mso-adapter-utils/src/test/java/org/openecomp/mso/openstack/utils/MsoHeatEnvironmentResourceESTest.java new file mode 100644 index 0000000000..d3e7d29717 --- /dev/null +++ b/adapters/mso-adapter-utils/src/test/java/org/openecomp/mso/openstack/utils/MsoHeatEnvironmentResourceESTest.java @@ -0,0 +1,129 @@ +/* + * This file was automatically generated by EvoSuite + * Mon Nov 14 08:45:54 GMT 2016 + */ + +package org.openecomp.mso.openstack.utils; + +import org.junit.Test; +import static org.junit.Assert.*; + +import org.evosuite.runtime.EvoRunner; +import org.evosuite.runtime.EvoRunnerParameters; +import org.junit.runner.RunWith; + +@RunWith(EvoRunner.class) @EvoRunnerParameters(mockJVMNonDeterminism = true, useVFS = true, useVNET = true, resetStaticState = true, useJEE = true) +public class MsoHeatEnvironmentResourceESTest extends MsoHeatEnvironmentResourceESTestscaffolding { + + @Test(timeout = 4000) + public void test00() throws Throwable { + MsoHeatEnvironmentResource msoHeatEnvironmentResource0 = new MsoHeatEnvironmentResource("", ""); + msoHeatEnvironmentResource0.hashCode(); + } + + @Test(timeout = 4000) + public void test01() throws Throwable { + MsoHeatEnvironmentResource msoHeatEnvironmentResource0 = new MsoHeatEnvironmentResource("8{,8]8v", "8{,8]8v"); + String string0 = msoHeatEnvironmentResource0.getValue(); + assertEquals("8{,8]8v", string0); + } + + @Test(timeout = 4000) + public void test02() throws Throwable { + MsoHeatEnvironmentResource msoHeatEnvironmentResource0 = new MsoHeatEnvironmentResource("", ""); + String string0 = msoHeatEnvironmentResource0.getValue(); + assertEquals("", string0); + } + + @Test(timeout = 4000) + public void test03() throws Throwable { + MsoHeatEnvironmentResource msoHeatEnvironmentResource0 = new MsoHeatEnvironmentResource("\"(_{*)._$D2+w8wk"); + String string0 = msoHeatEnvironmentResource0.getName(); + assertEquals("\"(_{*)._$D2+w8wk", string0); + } + + @Test(timeout = 4000) + public void test04() throws Throwable { + MsoHeatEnvironmentResource msoHeatEnvironmentResource0 = new MsoHeatEnvironmentResource(); + MsoHeatEnvironmentResource msoHeatEnvironmentResource1 = new MsoHeatEnvironmentResource(); + // Undeclared exception! + try { + msoHeatEnvironmentResource0.equals(msoHeatEnvironmentResource1); + fail("Expecting exception: NullPointerException"); + + } catch(NullPointerException e) { + } + } + + @Test(timeout = 4000) + public void test05() throws Throwable { + MsoHeatEnvironmentResource msoHeatEnvironmentResource0 = new MsoHeatEnvironmentResource("", ""); + MsoHeatEnvironmentResource msoHeatEnvironmentResource1 = new MsoHeatEnvironmentResource("", ""); + boolean boolean0 = msoHeatEnvironmentResource0.equals(msoHeatEnvironmentResource1); + assertTrue(boolean0); + } + + @Test(timeout = 4000) + public void test06() throws Throwable { + MsoHeatEnvironmentResource msoHeatEnvironmentResource0 = new MsoHeatEnvironmentResource("m"); + MsoHeatEnvironmentResource msoHeatEnvironmentResource1 = new MsoHeatEnvironmentResource("l", "l"); + boolean boolean0 = msoHeatEnvironmentResource0.equals(msoHeatEnvironmentResource1); + assertFalse(boolean0); + } + + @Test(timeout = 4000) + public void test07() throws Throwable { + MsoHeatEnvironmentResource msoHeatEnvironmentResource0 = new MsoHeatEnvironmentResource(); + boolean boolean0 = msoHeatEnvironmentResource0.equals("1Z^#74OJV(OBf<=#r"); + assertFalse(boolean0); + } + + @Test(timeout = 4000) + public void test08() throws Throwable { + MsoHeatEnvironmentResource msoHeatEnvironmentResource0 = new MsoHeatEnvironmentResource(); + boolean boolean0 = msoHeatEnvironmentResource0.equals(msoHeatEnvironmentResource0); + assertTrue(boolean0); + } + + @Test(timeout = 4000) + public void test09() throws Throwable { + MsoHeatEnvironmentResource msoHeatEnvironmentResource0 = new MsoHeatEnvironmentResource(); + String string0 = msoHeatEnvironmentResource0.getName(); + assertNull(string0); + } + + @Test(timeout = 4000) + public void test10() throws Throwable { + MsoHeatEnvironmentResource msoHeatEnvironmentResource0 = new MsoHeatEnvironmentResource(); + msoHeatEnvironmentResource0.setName(""); + String string0 = msoHeatEnvironmentResource0.getName(); + assertEquals("", string0); + } + + @Test(timeout = 4000) + public void test11() throws Throwable { + MsoHeatEnvironmentResource msoHeatEnvironmentResource0 = new MsoHeatEnvironmentResource(""); + String string0 = msoHeatEnvironmentResource0.getValue(); + assertNull(string0); + } + + @Test(timeout = 4000) + public void test12() throws Throwable { + MsoHeatEnvironmentResource msoHeatEnvironmentResource0 = new MsoHeatEnvironmentResource(); + msoHeatEnvironmentResource0.hashCode(); + } + + @Test(timeout = 4000) + public void test13() throws Throwable { + MsoHeatEnvironmentResource msoHeatEnvironmentResource0 = new MsoHeatEnvironmentResource(); + String string0 = msoHeatEnvironmentResource0.toString(); + assertEquals("\"null\": null", string0); + } + + @Test(timeout = 4000) + public void test14() throws Throwable { + MsoHeatEnvironmentResource msoHeatEnvironmentResource0 = new MsoHeatEnvironmentResource(); + msoHeatEnvironmentResource0.setValue(""); + assertNull(msoHeatEnvironmentResource0.getName()); + } +} diff --git a/adapters/mso-adapter-utils/src/test/java/org/openecomp/mso/openstack/utils/MsoHeatEnvironmentResourceESTestscaffolding.java b/adapters/mso-adapter-utils/src/test/java/org/openecomp/mso/openstack/utils/MsoHeatEnvironmentResourceESTestscaffolding.java new file mode 100644 index 0000000000..3917b8904c --- /dev/null +++ b/adapters/mso-adapter-utils/src/test/java/org/openecomp/mso/openstack/utils/MsoHeatEnvironmentResourceESTestscaffolding.java @@ -0,0 +1,78 @@ +/** + * Scaffolding file used to store all the setups needed to run + * tests automatically generated by EvoSuite + * Mon Nov 14 08:45:54 GMT 2016 + */ + +package org.openecomp.mso.openstack.utils; + +import org.evosuite.runtime.annotation.EvoSuiteClassExclude; +import org.junit.BeforeClass; +import org.junit.Before; +import org.junit.After; +import org.junit.AfterClass; +import org.evosuite.runtime.sandbox.Sandbox; + +@EvoSuiteClassExclude +public class MsoHeatEnvironmentResourceESTestscaffolding { + + @org.junit.Rule + public org.evosuite.runtime.vnet.NonFunctionalRequirementRule nfr = new org.evosuite.runtime.vnet.NonFunctionalRequirementRule(); + + private static final java.util.Properties defaultProperties = (java.util.Properties) java.lang.System.getProperties().clone(); + + private org.evosuite.runtime.thread.ThreadStopper threadStopper = new org.evosuite.runtime.thread.ThreadStopper (org.evosuite.runtime.thread.KillSwitchHandler.getInstance(), 3000); + + @BeforeClass + public static void initEvoSuiteFramework() { + org.evosuite.runtime.RuntimeSettings.className = "org.openecomp.mso.openstack.utils.MsoHeatEnvironmentResource"; + org.evosuite.runtime.GuiSupport.initialize(); + org.evosuite.runtime.RuntimeSettings.maxNumberOfThreads = 100; + org.evosuite.runtime.RuntimeSettings.maxNumberOfIterationsPerLoop = 10000; + org.evosuite.runtime.RuntimeSettings.mockSystemIn = true; + org.evosuite.runtime.RuntimeSettings.sandboxMode = org.evosuite.runtime.sandbox.Sandbox.SandboxMode.RECOMMENDED; + org.evosuite.runtime.sandbox.Sandbox.initializeSecurityManagerForSUT(); + org.evosuite.runtime.classhandling.JDKClassResetter.init(); + initializeClasses(); + org.evosuite.runtime.Runtime.getInstance().resetRuntime(); + } + + @AfterClass + public static void clearEvoSuiteFramework(){ + Sandbox.resetDefaultSecurityManager(); + java.lang.System.setProperties((java.util.Properties) defaultProperties.clone()); + } + + @Before + public void initTestCase(){ + threadStopper.storeCurrentThreads(); + threadStopper.startRecordingTime(); + org.evosuite.runtime.jvm.ShutdownHookHandler.getInstance().initHandler(); + org.evosuite.runtime.sandbox.Sandbox.goingToExecuteSUTCode(); + + org.evosuite.runtime.GuiSupport.setHeadless(); + org.evosuite.runtime.Runtime.getInstance().resetRuntime(); + org.evosuite.runtime.agent.InstrumentingAgent.activate(); + } + + @After + public void doneWithTestCase(){ + threadStopper.killAndJoinClientThreads(); + org.evosuite.runtime.jvm.ShutdownHookHandler.getInstance().safeExecuteAddedHooks(); + org.evosuite.runtime.classhandling.JDKClassResetter.reset(); + resetClasses(); + org.evosuite.runtime.sandbox.Sandbox.doneWithExecutingSUTCode(); + org.evosuite.runtime.agent.InstrumentingAgent.deactivate(); + org.evosuite.runtime.GuiSupport.restoreHeadlessMode(); + } + + + private static void initializeClasses() { + org.evosuite.runtime.classhandling.ClassStateSupport.initializeClasses(MsoHeatEnvironmentResourceESTestscaffolding.class.getClassLoader() , + "org.openecomp.mso.openstack.utils.MsoHeatEnvironmentResource" + ); + } + + private static void resetClasses() { + } +} diff --git a/adapters/mso-adapter-utils/src/test/resources/cloud_config.json b/adapters/mso-adapter-utils/src/test/resources/cloud_config.json new file mode 100644 index 0000000000..0230a7d4bf --- /dev/null +++ b/adapters/mso-adapter-utils/src/test/resources/cloud_config.json @@ -0,0 +1,80 @@ +{ "cloud_config": { + "identity_services": + { + "MT_KEYSTONE": + { + "identity_url": "http://localhost:5000/v2.0", + "mso_id": "john", + "mso_pass": "FD205490A48D48475607C36B9AD902BF", + "admin_tenant": "admin", + "member_role": "_member_", + "tenant_metadata": false, + "identity_server_type": "KEYSTONE", + "identity_authentication_type": "RACKSPACE_APIKEY" + }, + "DAN_KEYSTONE": + { + "identity_url": "http://localhost:5000/v2.0", + "mso_id": "mockId", + "mso_pass": "BC59F80E38208A42ABB81ECCDD4FB3E4", + "admin_tenant": "service", + "member_role": "_member_", + "tenant_metadata": false, + "identity_server_type": "KEYSTONE", + "identity_authentication_type": "USERNAME_PASSWORD" + }, + "MTINJVCC101_DCP": + { + "identity_url": "http://localhost:5000/v2.0", + "mso_id": "mockIdToo", + "mso_pass": "95604B9EAAC4D77D74786FAE54177206", + "admin_tenant": "service", + "member_role": "admin", + "tenant_metadata": true, + "identity_server_type": "KEYSTONE", + "identity_authentication_type": "USERNAME_PASSWORD" + }, + "MTSNJA3DCP1": + { + "identity_url": "https://localhost:5000/v2.0", + "mso_id": "mockIdToo", + "mso_pass": "1491DE07AC9D716A7966BB8C2848F031", + "admin_tenant": "service", + "member_role": "admin", + "tenant_metadata": true, + "identity_server_type": "KEYSTONE", + "identity_authentication_type": "USERNAME_PASSWORD" + } + + }, + "cloud_sites": + { + "MT": + { + "region_id": "regionOne", + "clli": "MT", + "aic_version": "2.5", + "identity_service_id": "MT_KEYSTONE" + }, + "DAN": + { + "region_id": "RegionOne", + "clli": "DAN", + "aic_version": "2.5", + "identity_service_id": "DAN_KEYSTONE" + }, + "MTINJVCC101": + { + "region_id": "regionTwo", + "clli": "MTINJVCC101", + "aic_version": "2.5", + "identity_service_id": "MTINJVCC101_DCP" + } + + } +} +} + + + + diff --git a/adapters/mso-adapter-utils/src/test/resources/logback-test.xml b/adapters/mso-adapter-utils/src/test/resources/logback-test.xml new file mode 100644 index 0000000000..d2c17192ea --- /dev/null +++ b/adapters/mso-adapter-utils/src/test/resources/logback-test.xml @@ -0,0 +1,48 @@ +<!-- + ============LICENSE_START======================================================= + ECOMP MSO + ================================================================================ + 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========================================================= + --> + +<configuration > + + + <appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender"> + <encoder> + <pattern>%d{MM/dd-HH:mm:ss.SSS}|%X{RequestId}|%X{ServiceInstanceId}|%thread|%X{ServiceName}|%X{InstanceUUID}|%.-5level|%X{AlertSeverity}||%X{ServerIPAddress}|%X{ServerFQDN}|%X{RemoteHost}||%X{Timer}|%msg%n</pattern> + </encoder> + </appender> + + + <logger name="com.att.eelf.audit" level="info" additivity="false"> + <appender-ref ref="STDOUT" /> + </logger> + + <logger name="com.att.eelf.metrics" level="info" additivity="false"> + <appender-ref ref="STDOUT" /> + </logger> + + <logger name="com.att.eelf.error" level="trace" additivity="false"> + <appender-ref ref="STDOUT" /> + </logger> + + <root level="info"> + <appender-ref ref="STDOUT" /> + </root> + + +</configuration> diff --git a/adapters/mso-adapter-utils/src/test/resources/mso.properties b/adapters/mso-adapter-utils/src/test/resources/mso.properties new file mode 100644 index 0000000000..d58521f1db --- /dev/null +++ b/adapters/mso-adapter-utils/src/test/resources/mso.properties @@ -0,0 +1,27 @@ +### +# ============LICENSE_START======================================================= +# ECOMP MSO +# ================================================================================ +# 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========================================================= +### + +ecomp.mso.cloud.1.cloudId=MT +ecomp.mso.cloud.1.keystoneUrl=http://localhost:5000/v2.0 +ecomp.mso.cloud.1.msoId=John +ecomp.mso.cloud.1.publicNetId=FD205490A48D48475607C36B9AD902BF +ecomp.mso.cloud.1.test=1234 +ecomp.mso.cloud.1.boolean=true +ecomp.mso.cloud.1.enum=enum1 diff --git a/adapters/mso-adapter-utils/src/test/resources/mso2.properties b/adapters/mso-adapter-utils/src/test/resources/mso2.properties new file mode 100644 index 0000000000..a47ce77146 --- /dev/null +++ b/adapters/mso-adapter-utils/src/test/resources/mso2.properties @@ -0,0 +1,21 @@ +### +# ============LICENSE_START======================================================= +# ECOMP MSO +# ================================================================================ +# 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========================================================= +### + +ecomp.mso.cloud.1.cloudId=MT2 |