aboutsummaryrefslogtreecommitdiffstats
path: root/adapters/mso-adapter-utils/src/main/java/org/openecomp/mso/cloud
diff options
context:
space:
mode:
Diffstat (limited to 'adapters/mso-adapter-utils/src/main/java/org/openecomp/mso/cloud')
-rw-r--r--adapters/mso-adapter-utils/src/main/java/org/openecomp/mso/cloud/CloudConfig.java262
-rw-r--r--adapters/mso-adapter-utils/src/main/java/org/openecomp/mso/cloud/CloudConfigFactory.java226
-rw-r--r--adapters/mso-adapter-utils/src/main/java/org/openecomp/mso/cloud/CloudIdentity.java316
-rw-r--r--adapters/mso-adapter-utils/src/main/java/org/openecomp/mso/cloud/CloudSite.java160
4 files changed, 964 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);
+ }
+ }
+}