summaryrefslogtreecommitdiffstats
path: root/adapters/mso-adapter-utils/src/main/java/org
diff options
context:
space:
mode:
Diffstat (limited to 'adapters/mso-adapter-utils/src/main/java/org')
-rw-r--r--adapters/mso-adapter-utils/src/main/java/org/openecomp/mso/cloud/CloudConfigIdentityMapper.java29
-rw-r--r--adapters/mso-adapter-utils/src/main/java/org/openecomp/mso/cloud/CloudIdentity.java114
-rw-r--r--adapters/mso-adapter-utils/src/main/java/org/openecomp/mso/cloud/IdentityAuthenticationTypeAbstract.java75
-rw-r--r--adapters/mso-adapter-utils/src/main/java/org/openecomp/mso/cloud/IdentityAuthenticationTypeJsonDeserializer.java44
-rw-r--r--adapters/mso-adapter-utils/src/main/java/org/openecomp/mso/cloud/IdentityAuthenticationTypeJsonSerializer.java38
-rw-r--r--adapters/mso-adapter-utils/src/main/java/org/openecomp/mso/cloud/IdentityServerTypeAbstract.java77
-rw-r--r--adapters/mso-adapter-utils/src/main/java/org/openecomp/mso/cloud/IdentityServerTypeJsonDeserializer.java44
-rw-r--r--adapters/mso-adapter-utils/src/main/java/org/openecomp/mso/cloud/IdentityServerTypeJsonSerializer.java38
-rw-r--r--adapters/mso-adapter-utils/src/main/java/org/openecomp/mso/cloud/authentication/AuthenticationMethodFactory.java79
-rw-r--r--adapters/mso-adapter-utils/src/main/java/org/openecomp/mso/cloud/authentication/AuthenticationWrapper.java58
-rw-r--r--adapters/mso-adapter-utils/src/main/java/org/openecomp/mso/cloud/authentication/models/RackspaceAuthentication.java99
-rw-r--r--adapters/mso-adapter-utils/src/main/java/org/openecomp/mso/cloud/authentication/wrappers/RackspaceAPIKeyWrapper.java55
-rw-r--r--adapters/mso-adapter-utils/src/main/java/org/openecomp/mso/cloud/authentication/wrappers/UsernamePasswordWrapper.java55
-rw-r--r--adapters/mso-adapter-utils/src/main/java/org/openecomp/mso/openstack/beans/VnfRollback.java24
-rw-r--r--adapters/mso-adapter-utils/src/main/java/org/openecomp/mso/openstack/utils/CloudConfigInitializer.java16
-rw-r--r--adapters/mso-adapter-utils/src/main/java/org/openecomp/mso/openstack/utils/MsoHeatUtils.java101
-rw-r--r--adapters/mso-adapter-utils/src/main/java/org/openecomp/mso/openstack/utils/MsoKeystoneUtils.java9
-rw-r--r--adapters/mso-adapter-utils/src/main/java/org/openecomp/mso/openstack/utils/MsoNeutronUtils.java4
-rw-r--r--adapters/mso-adapter-utils/src/main/java/org/openecomp/mso/openstack/utils/MsoTenantUtils.java6
-rw-r--r--adapters/mso-adapter-utils/src/main/java/org/openecomp/mso/openstack/utils/MsoTenantUtilsFactory.java17
20 files changed, 912 insertions, 70 deletions
diff --git a/adapters/mso-adapter-utils/src/main/java/org/openecomp/mso/cloud/CloudConfigIdentityMapper.java b/adapters/mso-adapter-utils/src/main/java/org/openecomp/mso/cloud/CloudConfigIdentityMapper.java
new file mode 100644
index 0000000000..a765f8004e
--- /dev/null
+++ b/adapters/mso-adapter-utils/src/main/java/org/openecomp/mso/cloud/CloudConfigIdentityMapper.java
@@ -0,0 +1,29 @@
+/*-
+ * ============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;
+
+/**
+ * This interface provides the method signature for mapping registration.
+ * All mappings should be registered by the implementing class.
+ */
+public interface CloudConfigIdentityMapper {
+
+ public void registerAllMappings();
+}
diff --git a/adapters/mso-adapter-utils/src/main/java/org/openecomp/mso/cloud/CloudIdentity.java b/adapters/mso-adapter-utils/src/main/java/org/openecomp/mso/cloud/CloudIdentity.java
index a777e4133c..db6ccde46c 100644
--- a/adapters/mso-adapter-utils/src/main/java/org/openecomp/mso/cloud/CloudIdentity.java
+++ b/adapters/mso-adapter-utils/src/main/java/org/openecomp/mso/cloud/CloudIdentity.java
@@ -1,32 +1,56 @@
-/*-
- * ============LICENSE_START=======================================================
- * OPENECOMP - MSO
- * ================================================================================
- * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
- * ================================================================================
+/*
+ * ============LICENSE_START==========================================
+ * ===================================================================
+ * 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
- *
+ *
+ * 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=========================================================
+ * ============LICENSE_END============================================
+ *
+ * ECOMP and OpenECOMP are trademarks
+ * and service marks of AT&T Intellectual Property.
+ *
*/
package org.openecomp.mso.cloud;
+import java.io.IOException;
+import java.net.URISyntaxException;
import java.security.GeneralSecurityException;
+import java.util.Map;
+import java.util.concurrent.ConcurrentHashMap;
import org.codehaus.jackson.annotate.JsonProperty;
+import org.codehaus.jackson.map.JsonSerializer;
+import org.codehaus.jackson.JsonGenerator;
+import org.codehaus.jackson.map.SerializerProvider;
+import org.codehaus.jackson.map.annotate.JsonDeserialize;
+import org.codehaus.jackson.map.annotate.JsonSerialize;
+import org.codehaus.jackson.JsonProcessingException;
+
+import org.openecomp.mso.openstack.exceptions.MsoAdapterException;
import org.openecomp.mso.openstack.exceptions.MsoException;
+import org.openecomp.mso.openstack.utils.MsoCommonUtils;
+import org.openecomp.mso.openstack.utils.MsoKeystoneUtils;
+import org.openecomp.mso.openstack.utils.MsoTenantUtils;
+import org.openecomp.mso.openstack.utils.MsoTenantUtilsFactory;
+import org.openecomp.mso.cloud.authentication.AuthenticationMethodFactory;
+import org.openecomp.mso.cloud.authentication.AuthenticationWrapper;
+import org.openecomp.mso.cloud.authentication.models.RackspaceAuthentication;
+import org.openecomp.mso.cloud.authentication.wrappers.RackspaceAPIKeyWrapper;
+import org.openecomp.mso.cloud.authentication.wrappers.UsernamePasswordWrapper;
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;
@@ -43,11 +67,39 @@ import com.woorea.openstack.keystone.model.Authentication;
*/
public class CloudIdentity {
+ // This block is needed to trigger the class loader so that static initialization
+ // of both inner static classes occur. This is required when the Json Deserializer
+ // gets called and no access to any of these inner classes happened yet.
+ static {
+ IdentityServerType.bootstrap();
+ IdentityAuthenticationType.bootstrap();
+ }
+
private static MsoLogger LOGGER = MsoLogger.getMsoLogger (MsoLogger.Catalog.RA);
-
- public enum IdentityServerType {KEYSTONE};
- public enum IdentityAuthenticationType { USERNAME_PASSWORD, RACKSPACE_APIKEY };
+ public final static class IdentityServerType extends IdentityServerTypeAbstract {
+
+ public static final IdentityServerType KEYSTONE = new IdentityServerType("KEYSTONE", MsoKeystoneUtils.class);
+
+ public IdentityServerType(String serverType, Class<? extends MsoTenantUtils> utilsClass) {
+ super(serverType, utilsClass);
+ }
+
+ public static final void bootstrap() {}
+ }
+
+ public static final class IdentityAuthenticationType extends IdentityAuthenticationTypeAbstract {
+
+ public static final IdentityAuthenticationType USERNAME_PASSWORD = new IdentityAuthenticationType("USERNAME_PASSWORD", UsernamePasswordWrapper.class);
+
+ public static final IdentityAuthenticationType RACKSPACE_APIKEY = new IdentityAuthenticationType("RACKSPACE_APIKEY", RackspaceAPIKeyWrapper.class);
+
+ public IdentityAuthenticationType(String identityType, Class<? extends AuthenticationWrapper> wrapperClass) {
+ super(identityType, wrapperClass);
+ }
+
+ public static final void bootstrap() {}
+ }
@JsonProperty
private String id;
@@ -64,8 +116,12 @@ public class CloudIdentity {
@JsonProperty("tenant_metadata")
private Boolean tenantMetadata;
@JsonProperty("identity_server_type")
+ @JsonSerialize(using=IdentityServerTypeJsonSerializer.class)
+ @JsonDeserialize(using=IdentityServerTypeJsonDeserializer.class)
private IdentityServerType identityServerType;
@JsonProperty("identity_authentication_type")
+ @JsonSerialize(using=IdentityAuthenticationTypeJsonSerializer.class)
+ @JsonDeserialize(using=IdentityAuthenticationTypeJsonDeserializer.class)
private IdentityAuthenticationType identityAuthenticationType;
private static String cloudKey = "aa3871669d893c7fb8abbcda31b88b4f";
@@ -92,26 +148,34 @@ public class CloudIdentity {
public String getKeystoneUrl (String regionId, String msoPropID) throws MsoException {
if (IdentityServerType.KEYSTONE.equals(this.identityServerType)) {
return this.identityUrl;
- }
- else {
- return null;
+ } else {
+ if (this.identityServerType == null) {
+ return null;
+ }
+ MsoTenantUtils tenantUtils = new MsoTenantUtilsFactory(msoPropID).getTenantUtilsByServerType(this.identityServerType.toString());
+ if (tenantUtils != null) {
+ return tenantUtils.getKeystoneUrl(regionId, msoPropID, this);
+ } 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 ());
+ if (this.getIdentityAuthenticationType() != null) {
+ try {
+ return AuthenticationMethodFactory.getAuthenticationFor(this);
+ } catch (IllegalAccessException | InstantiationException | ClassNotFoundException | IOException | URISyntaxException e) {
+ throw new MsoAdapterException("Could not retrieve authentication for " + this.identityAuthenticationType, e);
+ }
+ } else { // Fallback
+ return new UsernamePassword(this.getMsoId(), this.getMsoPass());
}
-
}
public void setKeystoneUrl (String url) {
if (IdentityServerType.KEYSTONE.equals(this.identityServerType)) {
- this.identityUrl = url;
+ this.identityUrl = url;
}
}
diff --git a/adapters/mso-adapter-utils/src/main/java/org/openecomp/mso/cloud/IdentityAuthenticationTypeAbstract.java b/adapters/mso-adapter-utils/src/main/java/org/openecomp/mso/cloud/IdentityAuthenticationTypeAbstract.java
new file mode 100644
index 0000000000..45a79730ad
--- /dev/null
+++ b/adapters/mso-adapter-utils/src/main/java/org/openecomp/mso/cloud/IdentityAuthenticationTypeAbstract.java
@@ -0,0 +1,75 @@
+/*-
+ * ============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.util.Map;
+import java.util.concurrent.ConcurrentHashMap;
+
+import org.openecomp.mso.cloud.authentication.AuthenticationWrapper;
+
+public abstract class IdentityAuthenticationTypeAbstract {
+
+ // This map will prevent duplicates (as if it was an Enum).
+ // Without this, using an instance specific field for the class could allow
+ // different classes bound to the same entry name.
+ private static final Map<String, IdentityAuthenticationTypeAbstract> entries = new ConcurrentHashMap<>();
+
+ private String identityType;
+
+ private Class<? extends AuthenticationWrapper> wrapperClass;
+
+ protected IdentityAuthenticationTypeAbstract(String identityType, Class<? extends AuthenticationWrapper> wrapperClass) {
+ try {
+ this.identityType = identityType;
+ this.wrapperClass = wrapperClass;
+ entries.put(identityType, this);
+ AuthenticationWrapper.register(this.toString(), wrapperClass);
+ } catch (IllegalAccessException | InstantiationException e) {
+ // Do not add the class if an exception occurs as we won't get the class anyway
+ }
+ }
+
+ public static final IdentityAuthenticationTypeAbstract valueOf(String serverType) {
+ return entries.get(serverType);
+ }
+
+ @Override
+ public final String toString() {
+ return this.identityType;
+ }
+
+ public final String name() {
+ return this.identityType;
+ }
+
+ public static final IdentityAuthenticationTypeAbstract[] values() {
+ return (IdentityAuthenticationTypeAbstract[]) entries.values().stream().toArray(IdentityAuthenticationTypeAbstract[]::new);
+ }
+
+ public final Class<? extends AuthenticationWrapper> getWrapperClass() {
+ return this.wrapperClass;
+ }
+
+ @Override
+ public final boolean equals(Object other) {
+ return ((this.identityType != null) && (other != null) && (other instanceof IdentityAuthenticationTypeAbstract) && (this.identityType.equals(other.toString())));
+ }
+
+}
diff --git a/adapters/mso-adapter-utils/src/main/java/org/openecomp/mso/cloud/IdentityAuthenticationTypeJsonDeserializer.java b/adapters/mso-adapter-utils/src/main/java/org/openecomp/mso/cloud/IdentityAuthenticationTypeJsonDeserializer.java
new file mode 100644
index 0000000000..c7b2c14cb8
--- /dev/null
+++ b/adapters/mso-adapter-utils/src/main/java/org/openecomp/mso/cloud/IdentityAuthenticationTypeJsonDeserializer.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.cloud;
+
+import java.io.IOException;
+
+import org.codehaus.jackson.JsonParser;
+import org.codehaus.jackson.JsonProcessingException;
+import org.codehaus.jackson.JsonToken;
+import org.codehaus.jackson.map.DeserializationContext;
+import org.codehaus.jackson.map.JsonDeserializer;
+import org.openecomp.mso.cloud.CloudIdentity.IdentityServerType;
+
+
+public class IdentityAuthenticationTypeJsonDeserializer extends JsonDeserializer<IdentityAuthenticationTypeAbstract> {
+
+ @Override
+ public IdentityAuthenticationTypeAbstract deserialize(JsonParser jsonParser, DeserializationContext deserializationContext)
+ throws IOException, JsonProcessingException {
+ JsonToken token = jsonParser.getCurrentToken();
+ if (JsonToken.VALUE_STRING.equals(token)) {
+ return IdentityAuthenticationTypeAbstract.valueOf(jsonParser.getText());
+ } else {
+ return null;
+ }
+ }
+}
diff --git a/adapters/mso-adapter-utils/src/main/java/org/openecomp/mso/cloud/IdentityAuthenticationTypeJsonSerializer.java b/adapters/mso-adapter-utils/src/main/java/org/openecomp/mso/cloud/IdentityAuthenticationTypeJsonSerializer.java
new file mode 100644
index 0000000000..06d877d4fa
--- /dev/null
+++ b/adapters/mso-adapter-utils/src/main/java/org/openecomp/mso/cloud/IdentityAuthenticationTypeJsonSerializer.java
@@ -0,0 +1,38 @@
+/*-
+ * ============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 org.codehaus.jackson.JsonGenerator;
+import org.codehaus.jackson.JsonProcessingException;
+import org.codehaus.jackson.map.JsonSerializer;
+import org.codehaus.jackson.map.SerializerProvider;
+import org.openecomp.mso.cloud.CloudIdentity.IdentityServerType;
+
+
+public class IdentityAuthenticationTypeJsonSerializer extends JsonSerializer<IdentityAuthenticationTypeAbstract> {
+
+ @Override
+ public void serialize(IdentityAuthenticationTypeAbstract tmpObj, JsonGenerator jsonGenerator, SerializerProvider serializerProvider)
+ throws IOException, JsonProcessingException {
+ jsonGenerator.writeObject(tmpObj.toString());
+ }
+}
diff --git a/adapters/mso-adapter-utils/src/main/java/org/openecomp/mso/cloud/IdentityServerTypeAbstract.java b/adapters/mso-adapter-utils/src/main/java/org/openecomp/mso/cloud/IdentityServerTypeAbstract.java
new file mode 100644
index 0000000000..38f1f87ddc
--- /dev/null
+++ b/adapters/mso-adapter-utils/src/main/java/org/openecomp/mso/cloud/IdentityServerTypeAbstract.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.cloud;
+
+import java.util.Map;
+import java.util.concurrent.ConcurrentHashMap;
+
+import org.openecomp.mso.openstack.utils.MsoTenantUtils;
+
+
+public abstract class IdentityServerTypeAbstract {
+
+ // This map will prevent duplicates (as if it was an Enum).
+ // Without this, using an instance specific field for the class could allow
+ // different classes bound to the same entry name.
+ private static final Map<String, IdentityServerTypeAbstract> entries = new ConcurrentHashMap<>();
+
+ private String serverType;
+
+ private Class<? extends MsoTenantUtils> utilsClass;
+
+ protected IdentityServerTypeAbstract(String serverType, Class<? extends MsoTenantUtils> utilsClass) {
+ if ((serverType == null) || (serverType.isEmpty())) {
+ throw new IllegalArgumentException("Server Type name cannot be null or empty, provided value was " + serverType);
+ }
+ if (entries.containsKey(serverType)) {
+ throw new IllegalArgumentException("Duplicate Server Type entry for registration: " + serverType);
+ }
+ this.serverType = serverType;
+ this.utilsClass = utilsClass;
+ entries.put(serverType, this);
+ }
+
+ public static final IdentityServerTypeAbstract valueOf(String serverType) {
+ return entries.get(serverType);
+ }
+
+ @Override
+ public final String toString() {
+ return this.serverType;
+ }
+
+ public final String name() {
+ return this.serverType;
+ }
+
+ public static final IdentityServerTypeAbstract[] values() {
+ return (IdentityServerTypeAbstract[]) entries.values().stream().toArray(IdentityServerTypeAbstract[]::new);
+ }
+
+ public final Class<? extends MsoTenantUtils> getMsoTenantUtilsClass() {
+ return this.utilsClass;
+ }
+
+ @Override
+ public final boolean equals(Object other) {
+ return ((this.serverType != null) && (other != null) && (other instanceof IdentityServerTypeAbstract) && (this.serverType.equals(other.toString())));
+ }
+
+}
diff --git a/adapters/mso-adapter-utils/src/main/java/org/openecomp/mso/cloud/IdentityServerTypeJsonDeserializer.java b/adapters/mso-adapter-utils/src/main/java/org/openecomp/mso/cloud/IdentityServerTypeJsonDeserializer.java
new file mode 100644
index 0000000000..8b9da1a3f4
--- /dev/null
+++ b/adapters/mso-adapter-utils/src/main/java/org/openecomp/mso/cloud/IdentityServerTypeJsonDeserializer.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.cloud;
+
+import java.io.IOException;
+
+import org.codehaus.jackson.JsonParser;
+import org.codehaus.jackson.JsonProcessingException;
+import org.codehaus.jackson.JsonToken;
+import org.codehaus.jackson.map.DeserializationContext;
+import org.codehaus.jackson.map.JsonDeserializer;
+import org.openecomp.mso.cloud.CloudIdentity.IdentityServerType;
+
+
+public class IdentityServerTypeJsonDeserializer extends JsonDeserializer<IdentityServerTypeAbstract> {
+
+ @Override
+ public IdentityServerTypeAbstract deserialize(JsonParser jsonParser, DeserializationContext deserializationContext)
+ throws IOException, JsonProcessingException {
+ JsonToken token = jsonParser.getCurrentToken();
+ if (JsonToken.VALUE_STRING.equals(token)) {
+ return IdentityServerTypeAbstract.valueOf(jsonParser.getText());
+ } else {
+ return null;
+ }
+ }
+}
diff --git a/adapters/mso-adapter-utils/src/main/java/org/openecomp/mso/cloud/IdentityServerTypeJsonSerializer.java b/adapters/mso-adapter-utils/src/main/java/org/openecomp/mso/cloud/IdentityServerTypeJsonSerializer.java
new file mode 100644
index 0000000000..c008860264
--- /dev/null
+++ b/adapters/mso-adapter-utils/src/main/java/org/openecomp/mso/cloud/IdentityServerTypeJsonSerializer.java
@@ -0,0 +1,38 @@
+/*-
+ * ============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 org.codehaus.jackson.JsonGenerator;
+import org.codehaus.jackson.JsonProcessingException;
+import org.codehaus.jackson.map.JsonSerializer;
+import org.codehaus.jackson.map.SerializerProvider;
+import org.openecomp.mso.cloud.CloudIdentity.IdentityServerType;
+
+
+public class IdentityServerTypeJsonSerializer extends JsonSerializer<IdentityServerTypeAbstract> {
+
+ @Override
+ public void serialize(IdentityServerTypeAbstract tmpObj, JsonGenerator jsonGenerator, SerializerProvider serializerProvider)
+ throws IOException, JsonProcessingException {
+ jsonGenerator.writeObject(tmpObj.toString());
+ }
+}
diff --git a/adapters/mso-adapter-utils/src/main/java/org/openecomp/mso/cloud/authentication/AuthenticationMethodFactory.java b/adapters/mso-adapter-utils/src/main/java/org/openecomp/mso/cloud/authentication/AuthenticationMethodFactory.java
new file mode 100644
index 0000000000..feaafd3c07
--- /dev/null
+++ b/adapters/mso-adapter-utils/src/main/java/org/openecomp/mso/cloud/authentication/AuthenticationMethodFactory.java
@@ -0,0 +1,79 @@
+/*
+ * ============LICENSE_START==========================================
+ * ===================================================================
+ * 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 and OpenECOMP are trademarks
+ * and service marks of AT&T Intellectual Property.
+ *
+ */
+
+package org.openecomp.mso.cloud.authentication;
+
+import java.io.IOException;
+import java.net.URISyntaxException;
+import java.util.Map;
+import java.util.concurrent.ConcurrentHashMap;
+
+import org.openecomp.mso.cloud.CloudIdentity;
+
+import com.woorea.openstack.keystone.model.Authentication;
+
+/**
+ * This factory manages all the wrappers associated to authentication types.
+ *
+ */
+public final class AuthenticationMethodFactory {
+
+ private static Map<String, AuthenticationWrapper> authWrappers = new ConcurrentHashMap<>();
+
+ /**
+ *
+ */
+ private AuthenticationMethodFactory() {}
+
+ /**
+ * Function to be called by classes implementing the abstract {@link AuthenticationWrapper#register(String, Class)}.
+ */
+ static final synchronized void register(String authenticationType, Class<? extends AuthenticationWrapper> wrapperClass) throws InstantiationException, IllegalAccessException {
+ if ((authenticationType == null) || ("".equals(authenticationType))) {
+ throw new IllegalArgumentException("Authentication Type to register cannot be null or an empty name string, provided value is " + authenticationType + ".");
+ }
+ if (wrapperClass == null) {
+ throw new IllegalArgumentException("Wrapper Class to register for Authentication cannot be null");
+ }
+
+ if (!authWrappers.containsKey(authenticationType)) {
+ authWrappers.put(authenticationType, wrapperClass.newInstance());
+ }
+ }
+
+ public static final synchronized Authentication getAuthenticationFor(CloudIdentity cloudIdentity) throws InstantiationException, IllegalAccessException, ClassNotFoundException, IOException, URISyntaxException {
+ if (cloudIdentity == null) {
+ throw new IllegalArgumentException("Cloud identity cannot be null");
+ }
+ if ((cloudIdentity.getIdentityAuthenticationType() == null) || ("".equals(cloudIdentity.getIdentityAuthenticationType().toString()))) {
+ throw new IllegalArgumentException("Cloud identity authentication type cannot be null or empty, provided value is " + cloudIdentity.getIdentityAuthenticationType() + ".");
+ }
+ String authenticationType = cloudIdentity.getIdentityAuthenticationType().toString();
+
+ if (authWrappers.containsKey(authenticationType)) {
+ return authWrappers.get(authenticationType).getAuthentication(cloudIdentity);
+ } else {
+ throw new IllegalArgumentException("Provided authentication type (" + authenticationType + ") is not implemented by any wrapper.");
+ }
+ }
+}
diff --git a/adapters/mso-adapter-utils/src/main/java/org/openecomp/mso/cloud/authentication/AuthenticationWrapper.java b/adapters/mso-adapter-utils/src/main/java/org/openecomp/mso/cloud/authentication/AuthenticationWrapper.java
new file mode 100644
index 0000000000..8b3725cd41
--- /dev/null
+++ b/adapters/mso-adapter-utils/src/main/java/org/openecomp/mso/cloud/authentication/AuthenticationWrapper.java
@@ -0,0 +1,58 @@
+/*
+ * ============LICENSE_START==========================================
+ * ===================================================================
+ * 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 and OpenECOMP are trademarks
+ * and service marks of AT&T Intellectual Property.
+ *
+ */
+
+package org.openecomp.mso.cloud.authentication;
+
+import org.openecomp.mso.cloud.CloudIdentity;
+
+import com.woorea.openstack.keystone.model.Authentication;
+
+/**
+ * This abstract class provides the necessary method for registering authentication
+ * types with wrapper classes, and also defines the contract for providing
+ * Openstack-compatible Authentication implementations for said authentication types.
+ *
+ */
+public abstract class AuthenticationWrapper {
+
+ /**
+ * Registers the implementing class to the list of Authentication Wrappers.
+ *
+ * @param authenticationType The authentication type that is provided by the implementing class
+ * @param wrapperClass The implementing class Class object
+ * @throws InstantiationException If the provided implementing class cannot be instantiated
+ * @throws IllegalAccessException If the provided implementing class cannot be instantiated
+ */
+ public static final void register(String authenticationType, Class<? extends AuthenticationWrapper> wrapperClass) throws InstantiationException, IllegalAccessException {
+ AuthenticationMethodFactory.register(authenticationType, wrapperClass);
+ }
+
+ /**
+ * Returns an OpenStack Authentication object for the provided CloudIdentity.
+ *
+ * @param cloudIdentity The input Cloud Identity instance
+ * @return the OpenStack Authentication associated with this cloud identity instance
+ */
+ protected abstract Authentication getAuthentication(CloudIdentity cloudIdentity);
+
+}
diff --git a/adapters/mso-adapter-utils/src/main/java/org/openecomp/mso/cloud/authentication/models/RackspaceAuthentication.java b/adapters/mso-adapter-utils/src/main/java/org/openecomp/mso/cloud/authentication/models/RackspaceAuthentication.java
new file mode 100644
index 0000000000..2b8da9f641
--- /dev/null
+++ b/adapters/mso-adapter-utils/src/main/java/org/openecomp/mso/cloud/authentication/models/RackspaceAuthentication.java
@@ -0,0 +1,99 @@
+/*
+ * ============LICENSE_START==========================================
+ * ===================================================================
+ * 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 and OpenECOMP are trademarks
+ * and service marks of AT&T Intellectual Property.
+ *
+ */
+
+package org.openecomp.mso.cloud.authentication.models;
+
+import org.codehaus.jackson.annotate.JsonIgnore;
+import org.codehaus.jackson.annotate.JsonProperty;
+import org.codehaus.jackson.map.annotate.JsonRootName;
+import com.woorea.openstack.keystone.model.Authentication;
+
+@JsonRootName("auth")
+public class RackspaceAuthentication extends Authentication {
+
+ /**
+ *
+ */
+ private static final long serialVersionUID = 5451283386875662918L;
+
+ @JsonIgnore
+ private String tenantId;
+
+ @JsonIgnore
+ private String tenantName;
+
+ public static final class Token {
+
+ private String username;
+ private String apiKey;
+
+ /**
+ * @return the username
+ */
+ public String getUsername() {
+ return username;
+ }
+ /**
+ * @param username the username to set
+ */
+ public void setUsername(String username) {
+ this.username = username;
+ }
+ /**
+ * @return the apiKey
+ */
+ public String getApiKey() {
+ return apiKey;
+ }
+ /**
+ * @param apiKey the apiKey to set
+ */
+ public void setApiKey(String apiKey) {
+ this.apiKey = apiKey;
+ }
+ }
+
+ @JsonProperty("RAX-KSKEY:apiKeyCredentials")
+ private Token token = new Token();
+
+ public RackspaceAuthentication (String username, String apiKey) {
+ this.token.username = username;
+ this.token.apiKey = apiKey;
+
+ }
+
+ /**
+ * @return the token
+ */
+ public Token getToken() {
+ return token;
+ }
+
+ /**
+ * @param token the token to set
+ */
+ public void setToken(Token token) {
+ this.token = token;
+ }
+
+}
diff --git a/adapters/mso-adapter-utils/src/main/java/org/openecomp/mso/cloud/authentication/wrappers/RackspaceAPIKeyWrapper.java b/adapters/mso-adapter-utils/src/main/java/org/openecomp/mso/cloud/authentication/wrappers/RackspaceAPIKeyWrapper.java
new file mode 100644
index 0000000000..87ff2582de
--- /dev/null
+++ b/adapters/mso-adapter-utils/src/main/java/org/openecomp/mso/cloud/authentication/wrappers/RackspaceAPIKeyWrapper.java
@@ -0,0 +1,55 @@
+/*
+ * ============LICENSE_START==========================================
+ * ===================================================================
+ * 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 and OpenECOMP are trademarks
+ * and service marks of AT&T Intellectual Property.
+ *
+ */
+
+package org.openecomp.mso.cloud.authentication.wrappers;
+
+import org.openecomp.mso.cloud.CloudIdentity;
+import org.openecomp.mso.cloud.authentication.AuthenticationWrapper;
+import org.openecomp.mso.cloud.authentication.models.RackspaceAuthentication;
+
+import com.woorea.openstack.keystone.model.Authentication;
+
+/**
+ * This class implements the authentication wrapper for Rackspace Authentication.
+ *
+ */
+public class RackspaceAPIKeyWrapper extends AuthenticationWrapper {
+
+ /**
+ *
+ */
+ public RackspaceAPIKeyWrapper() {
+ // TODO Auto-generated constructor stub
+ }
+
+ /* (non-Javadoc)
+ * @see org.openecomp.mso.cloud.authentication.AuthenticationWrapper#getAuthentication(org.openecomp.mso.cloud.CloudIdentity)
+ */
+ @Override
+ public Authentication getAuthentication(CloudIdentity cloudIdentity) {
+ if (cloudIdentity == null) {
+ throw new IllegalArgumentException("Provided cloud identity is null, cannot extract username and password");
+ }
+ return new RackspaceAuthentication (cloudIdentity.getMsoId (), cloudIdentity.getMsoPass ());
+ }
+}
diff --git a/adapters/mso-adapter-utils/src/main/java/org/openecomp/mso/cloud/authentication/wrappers/UsernamePasswordWrapper.java b/adapters/mso-adapter-utils/src/main/java/org/openecomp/mso/cloud/authentication/wrappers/UsernamePasswordWrapper.java
new file mode 100644
index 0000000000..2eebbb7d4b
--- /dev/null
+++ b/adapters/mso-adapter-utils/src/main/java/org/openecomp/mso/cloud/authentication/wrappers/UsernamePasswordWrapper.java
@@ -0,0 +1,55 @@
+/*
+ * ============LICENSE_START==========================================
+ * ===================================================================
+ * 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 and OpenECOMP are trademarks
+ * and service marks of AT&T Intellectual Property.
+ *
+ */
+
+package org.openecomp.mso.cloud.authentication.wrappers;
+
+import org.openecomp.mso.cloud.CloudIdentity;
+import org.openecomp.mso.cloud.authentication.AuthenticationWrapper;
+
+import com.woorea.openstack.keystone.model.Authentication;
+import com.woorea.openstack.keystone.model.authentication.UsernamePassword;
+
+/**
+ * This class implements the authentication wrapper for Openstack provided for
+ * user name and password authentication.
+ *
+ */
+public class UsernamePasswordWrapper extends AuthenticationWrapper {
+
+ /**
+ *
+ */
+ public UsernamePasswordWrapper() {
+ }
+
+ /* (non-Javadoc)
+ * @see org.openecomp.mso.cloud.authentication.AuthenticationWrapper#getAuthentication(org.openecomp.mso.cloud.CloudIdentity)
+ */
+ @Override
+ public Authentication getAuthentication(CloudIdentity cloudIdentity) {
+ if (cloudIdentity == null) {
+ throw new IllegalArgumentException("Provided cloud identity is null, cannot extract username and password");
+ }
+ return new UsernamePassword (cloudIdentity.getMsoId (), cloudIdentity.getMsoPass ());
+ }
+}
diff --git a/adapters/mso-adapter-utils/src/main/java/org/openecomp/mso/openstack/beans/VnfRollback.java b/adapters/mso-adapter-utils/src/main/java/org/openecomp/mso/openstack/beans/VnfRollback.java
index b6e4a6e855..fc148746a0 100644
--- a/adapters/mso-adapter-utils/src/main/java/org/openecomp/mso/openstack/beans/VnfRollback.java
+++ b/adapters/mso-adapter-utils/src/main/java/org/openecomp/mso/openstack/beans/VnfRollback.java
@@ -7,9 +7,9 @@
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
- *
+ *
* http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -42,13 +42,14 @@ public class VnfRollback {
private String baseGroupHeatStackId;
private boolean isBase = false;
private String vfModuleStackId;
+ private String modelCustomizationUuid; //NOTE: this is the vfModule's modelCustomizationUuid
public VnfRollback() {}
-
+
public VnfRollback(String vnfId, String tenantId, String cloudSiteId,
boolean tenantCreated, boolean vnfCreated,
MsoRequest msoRequest,
- String volumeGroupName, String volumeGroupId, String requestType) {
+ String volumeGroupName, String volumeGroupId, String requestType, String modelCustomizationUuid) {
super();
this.vnfId = vnfId;
this.tenantId = tenantId;
@@ -59,6 +60,7 @@ public class VnfRollback {
this.volumeGroupName = volumeGroupName;
this.volumeGroupId = volumeGroupId;
this.requestType = requestType;
+ this.modelCustomizationUuid = modelCustomizationUuid;
}
public String getVnfId() {
@@ -122,14 +124,14 @@ public class VnfRollback {
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;
}
@@ -142,11 +144,17 @@ public class VnfRollback {
public void setVfModuleStackId(String vfModuleStackId) {
this.vfModuleStackId = vfModuleStackId;
}
-
+ public String getModelCustomizationUuid() {
+ return this.modelCustomizationUuid;
+ }
+ public void setModelCustomizationUuid(String modelCustomizationUuid) {
+ this.modelCustomizationUuid = modelCustomizationUuid;
+ }
@Override
public String toString() {
return "VnfRollback: cloud=" + cloudSiteId + ", tenant=" + tenantId +
", vnf=" + vnfId + ", tenantCreated=" + tenantCreated +
- ", vnfCreated=" + vnfCreated + ", requestType = " + requestType;
+ ", vnfCreated=" + vnfCreated + ", requestType = " + requestType
+ + ", modelCustomizationUuid=" + this.modelCustomizationUuid;
}
}
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
index 3d9c23cc32..05d9a70a2d 100644
--- 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
@@ -27,6 +27,7 @@ import javax.servlet.ServletContextListener;
import javax.servlet.annotation.WebListener;
import org.openecomp.mso.cloud.CloudConfigFactory;
+import org.openecomp.mso.cloud.CloudConfigIdentityMapper;
import org.openecomp.mso.logger.MessageEnum;
import org.openecomp.mso.logger.MsoLogger;
@@ -73,6 +74,21 @@ public class CloudConfigInitializer implements ServletContextListener
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);
}
}
+
+ // Second, obtain class name that will register all mappings
+ String msoMapperClassParam = event.getServletContext().getInitParameter("mso.cloud_config.mapper.class");
+ if (msoMapperClassParam != null) {
+ Class<?> mapperClass = Class.forName(msoMapperClassParam);
+ if (CloudConfigIdentityMapper.class.isAssignableFrom(mapperClass)) {
+ ((CloudConfigIdentityMapper)mapperClass.newInstance()).registerAllMappings();
+ initLogger.info(MessageEnum.RA_CONFIG_LOAD,msoMapperClassParam+"(Openstack authentication mapper class)","","");
+ } else {
+ initLogger.info(MessageEnum.RA_CONFIG_LOAD,msoMapperClassParam+"(Openstack authentication mapper class not an implementation of CloudConfigIdentityMapper)","","");
+ }
+ } else {
+ initLogger.info(MessageEnum.RA_CONFIG_LOAD,"Openstack authentication mapper class not specified in web.xml (ONLY core authentication mechanisms will be loaded)","","");
+ }
+
}
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/MsoHeatUtils.java b/adapters/mso-adapter-utils/src/main/java/org/openecomp/mso/openstack/utils/MsoHeatUtils.java
index 9309f05c40..99d5863819 100644
--- a/adapters/mso-adapter-utils/src/main/java/org/openecomp/mso/openstack/utils/MsoHeatUtils.java
+++ b/adapters/mso-adapter-utils/src/main/java/org/openecomp/mso/openstack/utils/MsoHeatUtils.java
@@ -7,9 +7,9 @@
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
- *
+ *
* http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -58,6 +58,7 @@ 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.Stack.Output;
import com.woorea.openstack.heat.model.Stacks;
import com.woorea.openstack.keystone.Keystone;
import com.woorea.openstack.keystone.model.Access;
@@ -69,7 +70,7 @@ 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";
@@ -103,7 +104,7 @@ public class MsoHeatUtils extends MsoCommonUtils {
private int deletePollIntervalDefault = 15;
private int deletePollTimeoutDefault = 300;
private String msoPropID;
-
+
private static final ObjectMapper JSON_MAPPER = new ObjectMapper();
/**
@@ -127,7 +128,7 @@ public class MsoHeatUtils extends MsoCommonUtils {
}
cloudConfig = cloudConfigFactory.getCloudConfig ();
LOGGER.debug("MsoHeatUtils:" + msoPropID);
-
+
}
@@ -201,7 +202,7 @@ public class MsoHeatUtils extends MsoCommonUtils {
null,
true);
}
-
+
// This method has environment, files, heatfiles
public StackInfo createStack (String cloudSiteId,
String tenantId,
@@ -413,6 +414,11 @@ public class MsoHeatUtils extends MsoCommonUtils {
try {
heatStack = queryHeatStack (heatClient, canonicalName);
LOGGER.debug (heatStack.getStackStatus () + " (" + canonicalName + ")");
+ try {
+ LOGGER.debug("Current stack " + this.getOutputsAsStringBuilder(heatStack).toString());
+ } catch (Exception e) {
+ LOGGER.debug("an error occurred trying to print out the current outputs of the stack");
+ }
if ("CREATE_IN_PROGRESS".equals (heatStack.getStackStatus ())) {
// Stack creation is still running.
@@ -443,7 +449,7 @@ public class MsoHeatUtils extends MsoCommonUtils {
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 {
@@ -451,7 +457,7 @@ public class MsoHeatUtils extends MsoCommonUtils {
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?
+ // get another one, n'est-ce pas?
boolean deleted = false;
while (!deleted) {
try {
@@ -460,8 +466,8 @@ public class MsoHeatUtils extends MsoCommonUtils {
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,
+ LOGGER.error (MessageEnum.RA_CREATE_STACK_TIMEOUT, cloudSiteId, tenantId, stackName,
+ heatStack.getStackStatus (), "", "", MsoLogger.ErrorCode.AvailabilityError,
"Rollback: DELETE stack timeout");
break;
} else {
@@ -486,11 +492,11 @@ public class MsoHeatUtils extends MsoCommonUtils {
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) {
@@ -529,8 +535,8 @@ public class MsoHeatUtils extends MsoCommonUtils {
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,
+ LOGGER.error (MessageEnum.RA_CREATE_STACK_TIMEOUT, cloudSiteId, tenantId, stackName,
+ heatStack.getStackStatus (), "", "", MsoLogger.ErrorCode.AvailabilityError,
"Rollback: DELETE stack timeout");
break;
} else {
@@ -561,13 +567,13 @@ public class MsoHeatUtils extends MsoCommonUtils {
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) {
@@ -588,7 +594,7 @@ public class MsoHeatUtils extends MsoCommonUtils {
// 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());
@@ -949,10 +955,10 @@ public class MsoHeatUtils extends MsoCommonUtils {
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) {
@@ -984,10 +990,6 @@ public class MsoHeatUtils extends MsoCommonUtils {
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 ());
@@ -1119,7 +1121,7 @@ public class MsoHeatUtils extends MsoCommonUtils {
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)");
@@ -1208,7 +1210,7 @@ public class MsoHeatUtils extends MsoCommonUtils {
}
return sb;
}
-
+
private String convertNode(final JsonNode node) {
try {
final Object obj = JSON_MAPPER.treeToValue(node, Object.class);
@@ -1221,4 +1223,53 @@ public class MsoHeatUtils extends MsoCommonUtils {
}
return "[Error converting json to string]";
}
+
+
+ private StringBuilder getOutputsAsStringBuilder(Stack heatStack) {
+ // This should only be used as a utility to print out the stack outputs
+ // to the log
+ StringBuilder sb = new StringBuilder("");
+ if (heatStack == null) {
+ sb.append("(heatStack is null)");
+ return sb;
+ }
+ List<Output> outputList = heatStack.getOutputs();
+ if (outputList == null || outputList.isEmpty()) {
+ sb.append("(outputs is empty)");
+ return sb;
+ }
+ Map<String, Object> outputs = new HashMap<String,Object>();
+ for (Output outputItem : outputList) {
+ outputs.put(outputItem.getOutputKey(), outputItem.getOutputValue());
+ }
+ int counter = 0;
+ sb.append("OUTPUTS:");
+ for (String key : outputs.keySet()) {
+ sb.append("outputs[" + counter++ + "]: " + key + "=");
+ Object obj = outputs.get(key);
+ if (obj instanceof String) {
+ sb.append((String)obj);
+ } else if (obj instanceof JsonNode) {
+ sb.append(this.convertNode((JsonNode)obj));
+ } else if (obj instanceof java.util.LinkedHashMap) {
+ try {
+ String str = JSON_MAPPER.writeValueAsString(obj);
+ sb.append(str);
+ } catch (Exception e) {
+ sb.append("(a LinkedHashMap value that would not convert nicely)");
+ }
+ } else {
+ String str = "";
+ try {
+ str = (String) obj;
+ } catch (Exception e) {
+ str = "(a value unable to be cast as a String)";
+ }
+ sb.append(str);
+ }
+ sb.append("; ");
+ }
+ sb.append("[END]");
+ return sb;
+ }
}
diff --git a/adapters/mso-adapter-utils/src/main/java/org/openecomp/mso/openstack/utils/MsoKeystoneUtils.java b/adapters/mso-adapter-utils/src/main/java/org/openecomp/mso/openstack/utils/MsoKeystoneUtils.java
index 8375b973c9..e387ec4023 100644
--- a/adapters/mso-adapter-utils/src/main/java/org/openecomp/mso/openstack/utils/MsoKeystoneUtils.java
+++ b/adapters/mso-adapter-utils/src/main/java/org/openecomp/mso/openstack/utils/MsoKeystoneUtils.java
@@ -454,10 +454,6 @@ public class MsoKeystoneUtils extends MsoTenantUtils {
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.
@@ -685,4 +681,9 @@ public class MsoKeystoneUtils extends MsoTenantUtils {
public static void adminCacheReset () {
adminClientCache = new HashMap <String, KeystoneCacheEntry> ();
}
+
+ @Override
+ public String getKeystoneUrl(String regionId, String msoPropID, CloudIdentity cloudIdentity) throws MsoException {
+ return cloudIdentity.getIdentityUrl();
+ }
}
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
index f3281e3f1c..5c21913a66 100644
--- 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
@@ -425,10 +425,6 @@ public class MsoNeutronUtils extends MsoCommonUtils
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());
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
index 41104707cb..5af535f2b5 100644
--- 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
@@ -28,6 +28,7 @@ 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.logger.MsoAlarmLogger;
import org.openecomp.mso.logger.MsoLogger;
import org.openecomp.mso.logger.MessageEnum;
@@ -75,5 +76,8 @@ public abstract class MsoTenantUtils extends MsoCommonUtils {
public abstract boolean deleteTenant (String tenantId, String cloudSiteId)
throws MsoException;
-
+
+ public abstract String getKeystoneUrl (String regionId, String msoPropID, CloudIdentity cloudIdentity)
+ 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
index 6fd7a6364a..2a5b3ad994 100644
--- a/adapters/mso-adapter-utils/src/main/java/org/openecomp/mso/openstack/utils/MsoTenantUtilsFactory.java
+++ b/adapters/mso-adapter-utils/src/main/java/org/openecomp/mso/openstack/utils/MsoTenantUtilsFactory.java
@@ -20,6 +20,7 @@
package org.openecomp.mso.openstack.utils;
+import java.lang.reflect.InvocationTargetException;
import org.openecomp.mso.cloud.CloudConfig;
import org.openecomp.mso.cloud.CloudConfigFactory;
import org.openecomp.mso.cloud.CloudIdentity;
@@ -36,7 +37,7 @@ public class MsoTenantUtilsFactory {
protected CloudConfig cloudConfig;
protected MsoJavaProperties msoProps = null;
private String msoPropID;
-
+
public MsoTenantUtilsFactory (String msoPropID) {
this.msoPropID = msoPropID;
}
@@ -48,10 +49,20 @@ public class MsoTenantUtilsFactory {
cloudConfig = cloudConfigFactory.getCloudConfig();
CloudSite cloudSite = cloudConfig.getCloudSite (cloudSiteId);
+ return getTenantUtilsByServerType(cloudSite.getIdentityService().getIdentityServerType().toString());
+ }
+
+ public MsoTenantUtils getTenantUtilsByServerType(String serverType) {
+
MsoTenantUtils tenantU = null;
- if (cloudSite.getIdentityService().getIdentityServerType() == CloudIdentity.IdentityServerType.KEYSTONE)
- {
+ if (CloudIdentity.IdentityServerType.KEYSTONE.equals(serverType)) {
tenantU = new MsoKeystoneUtils (msoPropID);
+ } else {
+ try {
+ tenantU = CloudIdentity.IdentityServerType.valueOf(serverType).getMsoTenantUtilsClass().getConstructor(String.class).newInstance(msoPropID);
+ } catch (InvocationTargetException | InstantiationException | NoSuchMethodException | IllegalAccessException e) {
+ throw new RuntimeException("Could not instantiate an MsoTenantUtils class for " + serverType, e);
+ }
}
return tenantU;
}