aboutsummaryrefslogtreecommitdiffstats
path: root/adapters/mso-adapter-utils/src
diff options
context:
space:
mode:
authorSmokowski, Steven <steve.smokowski@att.com>2019-05-15 14:19:49 -0400
committerBenjamin, Max (mb388a) <mb388a@us.att.com>2019-05-15 14:19:58 -0400
commite4687eeb77d9fddf14935894026aec0b1c9e3ac9 (patch)
tree47c85cd95c71d36a404da6c83fbbb5d11fb0fb2c /adapters/mso-adapter-utils/src
parentf9c309fb9e789225ccd6b02ec9ab4777bbd4021c (diff)
store openstack request status in requestdb
Openstack request status now stored in request db Change-Id: Ida8f4f613d406c2b834ab190e01d5aaf2f16dd3d Issue-ID: SO-1867 Signed-off-by: Benjamin, Max (mb388a) <mb388a@us.att.com>
Diffstat (limited to 'adapters/mso-adapter-utils/src')
-rw-r--r--adapters/mso-adapter-utils/src/main/java/org/onap/so/cloud/authentication/KeystoneAuthHolder.java2
-rw-r--r--adapters/mso-adapter-utils/src/main/java/org/onap/so/cloud/authentication/KeystoneV3Authentication.java2
-rw-r--r--adapters/mso-adapter-utils/src/main/java/org/onap/so/openstack/utils/CinderClientException.java34
-rw-r--r--adapters/mso-adapter-utils/src/main/java/org/onap/so/openstack/utils/CinderClientImpl.java100
-rw-r--r--adapters/mso-adapter-utils/src/main/java/org/onap/so/openstack/utils/GlanceClientException.java34
-rw-r--r--adapters/mso-adapter-utils/src/main/java/org/onap/so/openstack/utils/GlanceClientImpl.java84
-rw-r--r--adapters/mso-adapter-utils/src/main/java/org/onap/so/openstack/utils/HeatClientException.java37
-rw-r--r--adapters/mso-adapter-utils/src/main/java/org/onap/so/openstack/utils/MsoCommonUtils.java129
-rw-r--r--adapters/mso-adapter-utils/src/main/java/org/onap/so/openstack/utils/MsoHeatUtils.java174
-rw-r--r--adapters/mso-adapter-utils/src/main/java/org/onap/so/openstack/utils/NeutronClientException.java33
-rw-r--r--adapters/mso-adapter-utils/src/main/java/org/onap/so/openstack/utils/NeutronClientImpl.java113
-rw-r--r--adapters/mso-adapter-utils/src/main/java/org/onap/so/openstack/utils/NovaClientException.java33
-rw-r--r--adapters/mso-adapter-utils/src/main/java/org/onap/so/openstack/utils/NovaClientImpl.java186
-rw-r--r--adapters/mso-adapter-utils/src/main/java/org/onap/so/openstack/utils/StackStatusHandler.java43
-rw-r--r--adapters/mso-adapter-utils/src/test/java/org/onap/so/cloud/authentication/KeystoneAuthHolderTest.java2
15 files changed, 869 insertions, 137 deletions
diff --git a/adapters/mso-adapter-utils/src/main/java/org/onap/so/cloud/authentication/KeystoneAuthHolder.java b/adapters/mso-adapter-utils/src/main/java/org/onap/so/cloud/authentication/KeystoneAuthHolder.java
index 4df8a91515..eadbc511d0 100644
--- a/adapters/mso-adapter-utils/src/main/java/org/onap/so/cloud/authentication/KeystoneAuthHolder.java
+++ b/adapters/mso-adapter-utils/src/main/java/org/onap/so/cloud/authentication/KeystoneAuthHolder.java
@@ -51,7 +51,7 @@ public class KeystoneAuthHolder implements Serializable {
return serviceUrl;
}
- public void setHeatUrl(String serviceUrl) {
+ public void setServiceUrl(String serviceUrl) {
this.serviceUrl = serviceUrl;
}
}
diff --git a/adapters/mso-adapter-utils/src/main/java/org/onap/so/cloud/authentication/KeystoneV3Authentication.java b/adapters/mso-adapter-utils/src/main/java/org/onap/so/cloud/authentication/KeystoneV3Authentication.java
index 35c928c3b5..42d200a130 100644
--- a/adapters/mso-adapter-utils/src/main/java/org/onap/so/cloud/authentication/KeystoneV3Authentication.java
+++ b/adapters/mso-adapter-utils/src/main/java/org/onap/so/cloud/authentication/KeystoneV3Authentication.java
@@ -85,7 +85,7 @@ public class KeystoneV3Authentication {
KeystoneAuthHolder result = new KeystoneAuthHolder();
result.setId(id);
result.setexpiration(token.getExpiresAt());
- result.setHeatUrl(findEndpointURL(token.getCatalog(), type, region, "public"));
+ result.setServiceUrl(findEndpointURL(token.getCatalog(), type, region, "public"));
return result;
}
diff --git a/adapters/mso-adapter-utils/src/main/java/org/onap/so/openstack/utils/CinderClientException.java b/adapters/mso-adapter-utils/src/main/java/org/onap/so/openstack/utils/CinderClientException.java
new file mode 100644
index 0000000000..f7f521e6f7
--- /dev/null
+++ b/adapters/mso-adapter-utils/src/main/java/org/onap/so/openstack/utils/CinderClientException.java
@@ -0,0 +1,34 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * ONAP - SO
+ * ================================================================================
+ * Copyright (C) 2019 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.onap.so.openstack.utils;
+
+public class CinderClientException extends Exception {
+
+ /**
+ *
+ */
+ private static final long serialVersionUID = -6865047344405492982L;
+
+ public CinderClientException(String errorMessage, Exception e) {
+ super(errorMessage, e);
+ }
+
+}
diff --git a/adapters/mso-adapter-utils/src/main/java/org/onap/so/openstack/utils/CinderClientImpl.java b/adapters/mso-adapter-utils/src/main/java/org/onap/so/openstack/utils/CinderClientImpl.java
new file mode 100644
index 0000000000..567f849b36
--- /dev/null
+++ b/adapters/mso-adapter-utils/src/main/java/org/onap/so/openstack/utils/CinderClientImpl.java
@@ -0,0 +1,100 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * ONAP - SO
+ * ================================================================================
+ * Copyright (C) 2019 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.onap.so.openstack.utils;
+
+import org.onap.so.cloud.authentication.KeystoneAuthHolder;
+import org.onap.so.openstack.exceptions.MsoCloudSiteNotFound;
+import org.onap.so.openstack.exceptions.MsoException;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.stereotype.Component;
+import com.woorea.openstack.base.client.OpenStackRequest;
+import com.woorea.openstack.cinder.Cinder;
+import com.woorea.openstack.cinder.model.Volume;
+import com.woorea.openstack.cinder.model.Volumes;
+
+
+
+@Component
+public class CinderClientImpl extends MsoCommonUtils {
+
+ private static final Logger logger = LoggerFactory.getLogger(CinderClientImpl.class);
+
+ /**
+ * Gets the Cinder client.
+ *
+ * @param cloudSite the cloud site
+ * @param tenantId the tenant id
+ * @return the glance client
+ * @throws MsoException the mso exception
+ */
+ private Cinder getCinderClient(String cloudSiteId, String tenantId) throws MsoException {
+ KeystoneAuthHolder keystone = getKeystoneAuthHolder(cloudSiteId, tenantId, "volumev2");
+ Cinder cinderClient = new Cinder(keystone.getServiceUrl());
+ cinderClient.token(keystone.getId());
+ return cinderClient;
+ }
+
+
+ /**
+ * Query images
+ *
+ *
+ * @param cloudSiteId the cloud site id
+ * @param tenantId the tenant id
+ * @param limit limits the number of records returned
+ * @param visibility visibility in the image in openstack
+ * @param marker the last viewed record
+ * @param name the image names
+ * @return the list of images in openstack
+ * @throws MsoCloudSiteNotFound the mso cloud site not found
+ * @throws CinderClientException the glance client exception
+ */
+ public Volumes queryVolumes(String cloudSiteId, String tenantId, int limit, String marker)
+ throws MsoCloudSiteNotFound, CinderClientException {
+ try {
+ Cinder cinderClient = getCinderClient(cloudSiteId, tenantId);
+ // list is set to false, otherwise an invalid URL is appended
+ OpenStackRequest<Volumes> request =
+ cinderClient.volumes().list(false).queryParam("limit", limit).queryParam("marker", marker);
+ return executeAndRecordOpenstackRequest(request);
+ } catch (MsoException e) {
+ logger.error("Error building Cinder Client", e);
+ throw new CinderClientException("Error building Cinder Client", e);
+ }
+ }
+
+
+ public Volume queryVolume(String cloudSiteId, String tenantId, String volumeId)
+ throws MsoCloudSiteNotFound, CinderClientException {
+ try {
+ Cinder cinderClient = getCinderClient(cloudSiteId, tenantId);
+ // list is set to false, otherwise an invalid URL is appended
+ OpenStackRequest<Volume> request = cinderClient.volumes().show(volumeId);
+ return executeAndRecordOpenstackRequest(request);
+ } catch (MsoException e) {
+ logger.error("Error building Cinder Client", e);
+ throw new CinderClientException("Error building Cinder Client", e);
+ }
+ }
+
+}
diff --git a/adapters/mso-adapter-utils/src/main/java/org/onap/so/openstack/utils/GlanceClientException.java b/adapters/mso-adapter-utils/src/main/java/org/onap/so/openstack/utils/GlanceClientException.java
new file mode 100644
index 0000000000..065fb83844
--- /dev/null
+++ b/adapters/mso-adapter-utils/src/main/java/org/onap/so/openstack/utils/GlanceClientException.java
@@ -0,0 +1,34 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * ONAP - SO
+ * ================================================================================
+ * Copyright (C) 2019 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.onap.so.openstack.utils;
+
+public class GlanceClientException extends Exception {
+
+ /**
+ *
+ */
+ private static final long serialVersionUID = -5202512087480589226L;
+
+ public GlanceClientException(String errorMessage, Exception e) {
+ super(errorMessage, e);
+ }
+
+}
diff --git a/adapters/mso-adapter-utils/src/main/java/org/onap/so/openstack/utils/GlanceClientImpl.java b/adapters/mso-adapter-utils/src/main/java/org/onap/so/openstack/utils/GlanceClientImpl.java
new file mode 100644
index 0000000000..57faaac717
--- /dev/null
+++ b/adapters/mso-adapter-utils/src/main/java/org/onap/so/openstack/utils/GlanceClientImpl.java
@@ -0,0 +1,84 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * ONAP - SO
+ * ================================================================================
+ * Copyright (C) 2019 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.onap.so.openstack.utils;
+
+import org.onap.so.cloud.authentication.KeystoneAuthHolder;
+import org.onap.so.openstack.exceptions.MsoCloudSiteNotFound;
+import org.onap.so.openstack.exceptions.MsoException;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.stereotype.Component;
+import com.woorea.openstack.base.client.OpenStackRequest;
+import com.woorea.openstack.glance.Glance;
+import com.woorea.openstack.glance.model.Images;
+
+
+@Component
+public class GlanceClientImpl extends MsoCommonUtils {
+
+ /** The Constant logger. */
+ private static final Logger logger = LoggerFactory.getLogger(GlanceClientImpl.class);
+
+ /**
+ * Gets the glance client.
+ *
+ * @param cloudSite the cloud site
+ * @param tenantId the tenant id
+ * @return the glance client
+ * @throws MsoException the mso exception
+ */
+ private Glance getGlanceClient(String cloudSiteId, String tenantId) throws MsoException {
+ KeystoneAuthHolder keystone = getKeystoneAuthHolder(cloudSiteId, tenantId, "image");
+ Glance glanceClient = new Glance(keystone.getServiceUrl() + "/v2.0/");
+ glanceClient.token(keystone.getId());
+ return glanceClient;
+ }
+
+
+ /**
+ * Query images
+ *
+ *
+ * @param cloudSiteId the cloud site id
+ * @param tenantId the tenant id
+ * @param limit limits the number of records returned
+ * @param visibility visibility in the image in openstack
+ * @param marker the last viewed record
+ * @param name the image names
+ * @return the list of images in openstack
+ * @throws MsoCloudSiteNotFound the mso cloud site not found
+ * @throws GlanceClientException the glance client exception
+ */
+ public Images queryImages(String cloudSiteId, String tenantId, int limit, String visibility, String marker,
+ String name) throws MsoCloudSiteNotFound, GlanceClientException {
+ try {
+ Glance glanceClient = getGlanceClient(cloudSiteId, tenantId);
+ // list is set to false, otherwise an invalid URL is appended
+ OpenStackRequest<Images> request = glanceClient.images().list(false).queryParam("visibility", visibility)
+ .queryParam("limit", limit).queryParam("marker", marker).queryParam("name", name);
+ return executeAndRecordOpenstackRequest(request);
+ } catch (MsoException e) {
+ logger.error("Error building Glance Client", e);
+ throw new GlanceClientException("Error building Glance Client", e);
+ }
+ }
+
+}
diff --git a/adapters/mso-adapter-utils/src/main/java/org/onap/so/openstack/utils/HeatClientException.java b/adapters/mso-adapter-utils/src/main/java/org/onap/so/openstack/utils/HeatClientException.java
new file mode 100644
index 0000000000..b49d632fdb
--- /dev/null
+++ b/adapters/mso-adapter-utils/src/main/java/org/onap/so/openstack/utils/HeatClientException.java
@@ -0,0 +1,37 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * ONAP - SO
+ * ================================================================================
+ * Copyright (C) 2019 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.onap.so.openstack.utils;
+
+public class HeatClientException extends Exception {
+
+ /**
+ *
+ */
+ private static final long serialVersionUID = -3143699004848022343L;
+
+ public HeatClientException(String errorMessage, Exception e) {
+ super(errorMessage, e);
+ }
+
+ public HeatClientException(String error) {
+ super(error);
+ }
+
+}
diff --git a/adapters/mso-adapter-utils/src/main/java/org/onap/so/openstack/utils/MsoCommonUtils.java b/adapters/mso-adapter-utils/src/main/java/org/onap/so/openstack/utils/MsoCommonUtils.java
index 79c042b10b..a6a2f8402f 100644
--- a/adapters/mso-adapter-utils/src/main/java/org/onap/so/openstack/utils/MsoCommonUtils.java
+++ b/adapters/mso-adapter-utils/src/main/java/org/onap/so/openstack/utils/MsoCommonUtils.java
@@ -24,24 +24,23 @@
package org.onap.so.openstack.utils;
-import com.fasterxml.jackson.core.type.TypeReference;
-import com.fasterxml.jackson.databind.ObjectMapper;
-import com.woorea.openstack.base.client.OpenStackBaseException;
-import com.woorea.openstack.base.client.OpenStackConnectException;
-import com.woorea.openstack.base.client.OpenStackRequest;
-import com.woorea.openstack.base.client.OpenStackResponseException;
-import com.woorea.openstack.heat.model.CreateStackParam;
-import com.woorea.openstack.heat.model.Explanation;
-import com.woorea.openstack.keystone.model.Error;
-import com.woorea.openstack.quantum.model.NeutronError;
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;
import java.util.Map.Entry;
+import org.onap.so.cloud.CloudConfig;
+import org.onap.so.cloud.authentication.AuthenticationMethodFactory;
+import org.onap.so.cloud.authentication.KeystoneAuthHolder;
+import org.onap.so.cloud.authentication.KeystoneV3Authentication;
+import org.onap.so.cloud.authentication.ServiceEndpointNotFoundException;
import org.onap.so.config.beans.PoConfig;
+import org.onap.so.db.catalog.beans.CloudIdentity;
+import org.onap.so.db.catalog.beans.CloudSite;
+import org.onap.so.db.catalog.beans.ServerType;
import org.onap.so.logger.ErrorCode;
import org.onap.so.logger.MessageEnum;
import org.onap.so.openstack.exceptions.MsoAdapterException;
+import org.onap.so.openstack.exceptions.MsoCloudSiteNotFound;
import org.onap.so.openstack.exceptions.MsoException;
import org.onap.so.openstack.exceptions.MsoExceptionCategory;
import org.onap.so.openstack.exceptions.MsoIOException;
@@ -50,15 +49,48 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
+import com.fasterxml.jackson.core.type.TypeReference;
+import com.fasterxml.jackson.databind.ObjectMapper;
+import com.woorea.openstack.base.client.OpenStackBaseException;
+import com.woorea.openstack.base.client.OpenStackConnectException;
+import com.woorea.openstack.base.client.OpenStackRequest;
+import com.woorea.openstack.base.client.OpenStackResponseException;
+import com.woorea.openstack.heat.model.CreateStackParam;
+import com.woorea.openstack.heat.model.Explanation;
+import com.woorea.openstack.keystone.Keystone;
+import com.woorea.openstack.keystone.model.Access;
+import com.woorea.openstack.keystone.model.Authentication;
+import com.woorea.openstack.keystone.model.Error;
+import com.woorea.openstack.keystone.utils.KeystoneUtils;
+import com.woorea.openstack.quantum.model.NeutronError;
@Component("CommonUtils")
public class MsoCommonUtils {
private static Logger logger = LoggerFactory.getLogger(MsoCommonUtils.class);
+ /** The Constant TOKEN_AUTH. */
+ protected static final String TOKEN_AUTH = "TokenAuth";
+ /** The cloud config. */
@Autowired
- private PoConfig poConfig;
+ protected CloudConfig cloudConfig;
+
+ /** The authentication method factory. */
+ @Autowired
+ protected AuthenticationMethodFactory authenticationMethodFactory;
+
+ /** The tenant utils factory. */
+ @Autowired
+ protected MsoTenantUtilsFactory tenantUtilsFactory;
+
+ /** The keystone V 3 authentication. */
+ @Autowired
+ protected KeystoneV3Authentication keystoneV3Authentication;
+
+ @Autowired
+ protected PoConfig poConfig;
+
/*
* Method to execute an Openstack command and track its execution time. For the metrics log, a category of
* "Openstack" is used along with a sub-category that identifies the specific call (using the real
@@ -401,4 +433,79 @@ public class MsoCommonUtils {
return stack;
}
+
+ /**
+ * Gets the Nova client
+ *
+ * @param cloudSite the cloud site
+ * @param tenantId the tenant id
+ * @return the Neutron client
+ * @throws MsoException the mso exception
+ */
+ protected KeystoneAuthHolder getKeystoneAuthHolder(String cloudSiteId, String tenantId, String serviceName)
+ throws MsoException {
+ CloudSite cloudSite =
+ cloudConfig.getCloudSite(cloudSiteId).orElseThrow(() -> new MsoCloudSiteNotFound(cloudSiteId));
+ String cloudId = cloudSite.getId();
+ String region = cloudSite.getRegionId();
+ CloudIdentity cloudIdentity = cloudSite.getIdentityService();
+ MsoTenantUtils tenantUtils =
+ tenantUtilsFactory.getTenantUtilsByServerType(cloudIdentity.getIdentityServerType());
+ String keystoneUrl = tenantUtils.getKeystoneUrl(cloudId, cloudIdentity);
+ try {
+ if (ServerType.KEYSTONE.equals(cloudIdentity.getIdentityServerType())) {
+ Access access = getKeystone(tenantId, cloudIdentity, keystoneUrl);
+ try {
+ KeystoneAuthHolder keystoneAuthV2 = new KeystoneAuthHolder();
+ keystoneAuthV2.setServiceUrl(
+ KeystoneUtils.findEndpointURL(access.getServiceCatalog(), serviceName, region, "public"));
+ keystoneAuthV2.setId(access.getToken().getId());
+ return keystoneAuthV2;
+ } catch (RuntimeException e) {
+ String error = "Openstack did not match an orchestration service for: region=" + region + ",cloud="
+ + cloudIdentity.getIdentityUrl();
+ throw new MsoAdapterException(error, e);
+ }
+ } else if (ServerType.KEYSTONE_V3.equals(cloudIdentity.getIdentityServerType())) {
+ try {
+ return keystoneV3Authentication.getToken(cloudSite, tenantId, serviceName);
+ } catch (ServiceEndpointNotFoundException e) {
+ String error = "cloud did not match an orchestration service for: region=" + region + ",cloud="
+ + cloudIdentity.getIdentityUrl();
+ throw new MsoAdapterException(error, e);
+ }
+ } else {
+ throw new MsoAdapterException("Unknown Keystone Server Type");
+ }
+ } catch (OpenStackResponseException e) {
+ if (e.getStatus() == 401) {
+ String error = "Authentication Failure: tenant=" + tenantId + ",cloud=" + cloudIdentity.getId();
+ throw new MsoAdapterException(error);
+ } else {
+ throw keystoneErrorToMsoException(e, TOKEN_AUTH);
+ }
+ } catch (OpenStackConnectException e) {
+ MsoIOException me = new MsoIOException(e.getMessage(), e);
+ me.addContext(TOKEN_AUTH);
+ throw me;
+ } catch (RuntimeException e) {
+ throw runtimeExceptionToMsoException(e, TOKEN_AUTH);
+ }
+ }
+
+ /**
+ * @param tenantId
+ * @param cloudIdentity
+ * @param keystoneUrl
+ * @return
+ */
+ protected Access getKeystone(String tenantId, CloudIdentity cloudIdentity, String keystoneUrl) {
+ Keystone keystoneTenantClient = new Keystone(keystoneUrl);
+ Access access = null;
+ Authentication credentials = authenticationMethodFactory.getAuthenticationFor(cloudIdentity);
+ OpenStackRequest<Access> request =
+ keystoneTenantClient.tokens().authenticate(credentials).withTenantId(tenantId);
+ access = executeAndRecordOpenstackRequest(request);
+ return access;
+ }
}
diff --git a/adapters/mso-adapter-utils/src/main/java/org/onap/so/openstack/utils/MsoHeatUtils.java b/adapters/mso-adapter-utils/src/main/java/org/onap/so/openstack/utils/MsoHeatUtils.java
index 8093f045eb..376ed20ed0 100644
--- a/adapters/mso-adapter-utils/src/main/java/org/onap/so/openstack/utils/MsoHeatUtils.java
+++ b/adapters/mso-adapter-utils/src/main/java/org/onap/so/openstack/utils/MsoHeatUtils.java
@@ -23,26 +23,9 @@
package org.onap.so.openstack.utils;
-import com.fasterxml.jackson.core.JsonProcessingException;
-import com.fasterxml.jackson.databind.JsonNode;
-import com.fasterxml.jackson.databind.ObjectMapper;
-import com.woorea.openstack.base.client.OpenStackConnectException;
-import com.woorea.openstack.base.client.OpenStackRequest;
-import com.woorea.openstack.base.client.OpenStackResponseException;
-import com.woorea.openstack.heat.Heat;
-import com.woorea.openstack.heat.model.CreateStackParam;
-import com.woorea.openstack.heat.model.Resources;
-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;
-import com.woorea.openstack.keystone.model.Authentication;
-import com.woorea.openstack.keystone.utils.KeystoneUtils;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;
-import java.util.Calendar;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@@ -92,6 +75,22 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Primary;
import org.springframework.core.env.Environment;
import org.springframework.stereotype.Component;
+import com.fasterxml.jackson.databind.JsonNode;
+import com.fasterxml.jackson.databind.ObjectMapper;
+import com.woorea.openstack.base.client.OpenStackConnectException;
+import com.woorea.openstack.base.client.OpenStackRequest;
+import com.woorea.openstack.base.client.OpenStackResponseException;
+import com.woorea.openstack.heat.Heat;
+import com.woorea.openstack.heat.model.CreateStackParam;
+import com.woorea.openstack.heat.model.Events;
+import com.woorea.openstack.heat.model.Resources;
+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;
+import com.woorea.openstack.keystone.model.Authentication;
+import com.woorea.openstack.keystone.utils.KeystoneUtils;
@Primary
@Component
@@ -130,6 +129,9 @@ public class MsoHeatUtils extends MsoCommonUtils implements VduPlugin {
@Autowired
RequestsDbClient requestDBClient;
+ @Autowired
+ StackStatusHandler statusHandler;
+
private static final Logger logger = LoggerFactory.getLogger(MsoHeatUtils.class);
// Properties names and variables (with default values)
@@ -317,6 +319,7 @@ public class MsoHeatUtils extends MsoCommonUtils implements VduPlugin {
while (true) {
try {
heatStack = queryHeatStack(heatClient, canonicalName);
+ statusHandler.updateStackStatus(heatStack, MDC.get(ONAPLogConstants.MDCs.REQUEST_ID));
logger.debug("{} ({})", heatStack.getStackStatus(), canonicalName);
try {
logger.debug("Current stack {}", this.getOutputsAsStringBuilder(heatStack).toString());
@@ -358,6 +361,7 @@ public class MsoHeatUtils extends MsoCommonUtils implements VduPlugin {
while (!deleted) {
try {
heatStack = queryHeatStack(heatClient, canonicalName);
+ statusHandler.updateStackStatus(heatStack, MDC.get(ONAPLogConstants.MDCs.REQUEST_ID));
if (heatStack != null) {
logger.debug(heatStack.getStackStatus());
if ("DELETE_IN_PROGRESS".equals(heatStack.getStackStatus())) {
@@ -579,24 +583,15 @@ public class MsoHeatUtils extends MsoCommonUtils implements VduPlugin {
*/
public StackInfo deleteStack(String tenantId, String cloudOwner, String cloudSiteId, String stackName,
boolean pollForCompletion) throws MsoException {
- // Obtain the cloud site information where we will create the stack
CloudSite cloudSite =
cloudConfig.getCloudSite(cloudSiteId).orElseThrow(() -> new MsoCloudSiteNotFound(cloudSiteId));
- logger.debug(FOUND, cloudSite.toString());
-
- // Get a Heat client. They are cached between calls (keyed by tenantId:cloudId)
Heat heatClient = null;
try {
heatClient = getHeatClient(cloudSite, tenantId);
- if (heatClient != null) {
- logger.debug(FOUND, heatClient.toString());
- }
} catch (MsoTenantNotFound e) {
- // Tenant doesn't exist, so stack doesn't either
logger.debug("Tenant with id " + tenantId + "not found.", e);
return new StackInfo(stackName, HeatStatus.NOTFOUND);
} catch (MsoException me) {
- // Got an Openstack error. Propagate it
logger.error("{} {} Openstack Exception on Token request: ", MessageEnum.RA_CONNECTION_EXCEPTION,
ErrorCode.AvailabilityError.getValue(), me);
me.addContext(DELETE_STACK);
@@ -610,8 +605,6 @@ public class MsoHeatUtils extends MsoCommonUtils implements VduPlugin {
return new StackInfo(stackName, HeatStatus.NOTFOUND);
}
- // Delete the stack.
-
// Use canonical name "<stack name>/<stack-id>" to delete.
// Otherwise, deletion by name returns a 302 redirect.
// NOTE: This is specific to the v1 Orchestration API.
@@ -624,7 +617,6 @@ public class MsoHeatUtils extends MsoCommonUtils implements VduPlugin {
} else {
logger.debug("Heat Client is NULL");
}
-
executeAndRecordOpenstackRequest(request);
} catch (OpenStackResponseException e) {
if (e.getStatus() == 404) {
@@ -645,15 +637,13 @@ public class MsoHeatUtils extends MsoCommonUtils implements VduPlugin {
// Requery the stack for current status.
// It will probably still exist with "DELETE_IN_PROGRESS" status.
heatStack = queryHeatStack(heatClient, canonicalName);
-
+ statusHandler.updateStackStatus(heatStack, MDC.get(ONAPLogConstants.MDCs.REQUEST_ID));
if (pollForCompletion) {
- // Set a timeout on polling
-
int pollInterval = Integer
.parseInt(this.environment.getProperty(deletePollIntervalProp, "" + DELETE_POLL_INTERVAL_DEFAULT));
int pollTimeout = Integer
.parseInt(this.environment.getProperty(deletePollTimeoutProp, "" + DELETE_POLL_INTERVAL_DEFAULT));
-
+ statusHandler.updateStackStatus(heatStack, MDC.get(ONAPLogConstants.MDCs.REQUEST_ID));
// When querying by canonical name, Openstack returns DELETE_COMPLETE status
// instead of "404" (which would result from query by stack name).
while (heatStack != null && !"DELETE_COMPLETE".equals(heatStack.getStackStatus())) {
@@ -698,11 +688,9 @@ public class MsoHeatUtils extends MsoCommonUtils implements VduPlugin {
// The stack is gone when this point is reached
return new StackInfo(stackName, HeatStatus.NOTFOUND);
}
-
// Return the current status (if not polling, the delete may still be in progress)
StackInfo stackInfo = new StackInfoMapper(heatStack).map();
stackInfo.setName(stackName);
-
return stackInfo;
}
@@ -841,7 +829,6 @@ public class MsoHeatUtils extends MsoCommonUtils implements VduPlugin {
logger.debug("keystoneUrl={}", keystoneUrl);
String heatUrl = null;
String tokenId = null;
-
try {
if (ServerType.KEYSTONE.equals(cloudIdentity.getIdentityServerType())) {
Keystone keystoneTenantClient = new Keystone(keystoneUrl);
@@ -855,19 +842,7 @@ public class MsoHeatUtils extends MsoCommonUtils implements VduPlugin {
access = executeAndRecordOpenstackRequest(request);
try {
- // Isolate trying to printout the region IDs
- try {
- logger.debug("access={}", access.toString());
- for (Access.Service service : access.getServiceCatalog()) {
- List<Access.Service.Endpoint> endpoints = service.getEndpoints();
- for (Access.Service.Endpoint endpoint : endpoints) {
- logger.debug("AIC returned region={}", endpoint.getRegion());
- }
- }
- } catch (Exception e) {
- logger.debug("Encountered an error trying to printout Access object returned from AIC. {}",
- e.getMessage(), e);
- }
+ logger.debug("access={}", access.toString());
heatUrl = KeystoneUtils.findEndpointURL(access.getServiceCatalog(), "orchestration", region,
"public");
logger.debug("heatUrl={}, region={}", heatUrl, region);
@@ -878,12 +853,10 @@ public class MsoHeatUtils extends MsoCommonUtils implements VduPlugin {
throw new MsoAdapterException(error, e);
}
tokenId = access.getToken().getId();
-
} else if (ServerType.KEYSTONE_V3.equals(cloudIdentity.getIdentityServerType())) {
try {
KeystoneAuthHolder holder = keystoneV3Authentication.getToken(cloudSite, tenantId, "orchestration");
tokenId = holder.getId();
-
heatUrl = holder.getServiceUrl();
} catch (ServiceEndpointNotFoundException e) {
// This comes back for not found (probably an incorrect region ID)
@@ -933,7 +906,7 @@ public class MsoHeatUtils extends MsoCommonUtils implements VduPlugin {
*
* @throws MsoOpenstackException Thrown if the Openstack API call returns an exception
*/
- protected Stack queryHeatStack(Heat heatClient, String stackName) throws MsoException {
+ public Stack queryHeatStack(Heat heatClient, String stackName) throws MsoException {
if (stackName == null) {
return null;
}
@@ -1364,77 +1337,6 @@ public class MsoHeatUtils extends MsoCommonUtils implements VduPlugin {
return keystoneUrl;
}
- /*
- * Create a string suitable for being dumped to a debug log that creates a pseudo-JSON request dumping what's being
- * sent to Openstack API in the create or update request
- */
-
- private String printStackRequest(String tenantId, Map<String, Object> heatFiles,
- Map<String, Object> nestedTemplates, String environment, Map<String, Object> inputs, String vfModuleName,
- String template, int timeoutMinutes, boolean backout, String cloudSiteId) {
- StringBuilder sb = new StringBuilder();
- sb.append("CREATE STACK REQUEST (formatted for readability)\n");
- sb.append("tenant=" + tenantId + ", cloud=" + cloudSiteId);
- sb.append("{\n");
- sb.append(" \"stack_name\": \"" + vfModuleName + "\",\n");
- sb.append(" \"disable_rollback\": " + backout + ",\n");
- sb.append(" \"timeout_mins\": " + timeoutMinutes + ",\n");
- sb.append(" \"template\": {\n");
- sb.append(template);
- sb.append(" },\n");
- sb.append(" \"environment\": {\n");
- if (environment == null)
- sb.append("<none>");
- else
- sb.append(environment);
- sb.append(" },\n");
- sb.append(" \"files\": {\n");
- int filesCounter = 0;
- if (heatFiles != null) {
- for (String key : heatFiles.keySet()) {
- filesCounter++;
- if (filesCounter > 1) {
- sb.append(",\n");
- }
- sb.append(" \"" + key + "\": {\n");
- sb.append(heatFiles.get(key).toString() + "\n }");
- }
- }
- if (nestedTemplates != null) {
- for (String key : nestedTemplates.keySet()) {
- filesCounter++;
- if (filesCounter > 1) {
- sb.append(",\n");
- }
- sb.append(" \"" + key + "\": {\n");
- sb.append(nestedTemplates.get(key).toString() + "\n }");
- }
- }
- sb.append("\n },\n");
- sb.append(" \"parameters\": {\n");
- int paramCounter = 0;
- for (String name : inputs.keySet()) {
- paramCounter++;
- if (paramCounter > 1) {
- sb.append(",\n");
- }
- Object o = inputs.get(name);
- if (o instanceof java.lang.String) {
- sb.append(" \"" + name + "\": \"" + inputs.get(name).toString() + "\"");
- } else if (o instanceof Integer) {
- sb.append(" \"" + name + "\": " + inputs.get(name).toString());
- } else if (o instanceof ArrayList) {
- sb.append(" \"" + name + "\": " + inputs.get(name).toString());
- } else if (o instanceof Boolean) {
- sb.append(" \"" + name + "\": " + inputs.get(name).toString());
- } else {
- sb.append(" \"" + name + "\": " + "\"(there was an issue trying to dump this value...)\"");
- }
- }
- sb.append("\n }\n}\n");
-
- return sb.toString();
- }
/*******************************************************************************
*
@@ -1613,6 +1515,32 @@ public class MsoHeatUtils extends MsoCommonUtils implements VduPlugin {
return executeAndRecordOpenstackRequest(request);
}
+ public Events queryStackEvents(String cloudSiteId, String tenantId, String stackName, String stackId,
+ int nestedDepth) throws MsoException {
+ CloudSite cloudSite =
+ cloudConfig.getCloudSite(cloudSiteId).orElseThrow(() -> new MsoCloudSiteNotFound(cloudSiteId));
+ Heat heatClient = getHeatClient(cloudSite, tenantId);
+ OpenStackRequest<Events> request =
+ heatClient.getEvents().listEvents(stackName, stackId).queryParam("nested_depth", nestedDepth);
+ return executeAndRecordOpenstackRequest(request);
+ }
+
+ public Stacks queryStacks(String cloudSiteId, String tenantId, int limit, String marker)
+ throws MsoCloudSiteNotFound, HeatClientException {
+ CloudSite cloudSite =
+ cloudConfig.getCloudSite(cloudSiteId).orElseThrow(() -> new MsoCloudSiteNotFound(cloudSiteId));
+ Heat heatClient;
+ try {
+ heatClient = getHeatClient(cloudSite, tenantId);
+ } catch (MsoException e) {
+ logger.error("Error Creating Heat Client", e);
+ throw new HeatClientException("Error Creating Heat Client", e);
+ }
+ OpenStackRequest<Stacks> request =
+ heatClient.getStacks().list().queryParam("limit", limit).queryParam("marker", marker);
+ return executeAndRecordOpenstackRequest(request);
+ }
+
public <R> R executeHeatClientRequest(String url, String cloudSiteId, String tenantId, Class<R> returnType)
throws MsoException {
CloudSite cloudSite =
diff --git a/adapters/mso-adapter-utils/src/main/java/org/onap/so/openstack/utils/NeutronClientException.java b/adapters/mso-adapter-utils/src/main/java/org/onap/so/openstack/utils/NeutronClientException.java
new file mode 100644
index 0000000000..e2c917c6eb
--- /dev/null
+++ b/adapters/mso-adapter-utils/src/main/java/org/onap/so/openstack/utils/NeutronClientException.java
@@ -0,0 +1,33 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * ONAP - SO
+ * ================================================================================
+ * Copyright (C) 2019 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.onap.so.openstack.utils;
+
+public class NeutronClientException extends Exception {
+
+ /**
+ *
+ */
+ private static final long serialVersionUID = -9047340957886416022L;
+
+ public NeutronClientException(String error, Exception e) {
+ super(error, e);
+ }
+
+}
diff --git a/adapters/mso-adapter-utils/src/main/java/org/onap/so/openstack/utils/NeutronClientImpl.java b/adapters/mso-adapter-utils/src/main/java/org/onap/so/openstack/utils/NeutronClientImpl.java
new file mode 100644
index 0000000000..93745de54a
--- /dev/null
+++ b/adapters/mso-adapter-utils/src/main/java/org/onap/so/openstack/utils/NeutronClientImpl.java
@@ -0,0 +1,113 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * ONAP - SO
+ * ================================================================================
+ * Copyright (C) 2019 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.onap.so.openstack.utils;
+
+import org.onap.so.cloud.authentication.KeystoneAuthHolder;
+import org.onap.so.openstack.exceptions.MsoCloudSiteNotFound;
+import org.onap.so.openstack.exceptions.MsoException;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.stereotype.Component;
+import com.woorea.openstack.base.client.OpenStackRequest;
+import com.woorea.openstack.quantum.Quantum;
+import com.woorea.openstack.quantum.model.Networks;
+import com.woorea.openstack.quantum.model.Subnets;
+
+
+
+@Component
+public class NeutronClientImpl extends MsoCommonUtils {
+
+ /** The Constant logger. */
+ private static final Logger logger = LoggerFactory.getLogger(NeutronClientImpl.class);
+
+ /**
+ * Gets the Neutron client, using old object named Quantum, now renamed Neutron
+ *
+ * @param cloudSite the cloud site
+ * @param tenantId the tenant id
+ * @return the Neutron client
+ * @throws MsoException the mso exception
+ */
+ private Quantum getNeutronClient(String cloudSiteId, String tenantId) throws MsoException {
+ KeystoneAuthHolder keystone = getKeystoneAuthHolder(cloudSiteId, tenantId, "network");
+ Quantum neutronClient = new Quantum(keystone.getServiceUrl() + "/v2.0/");
+ neutronClient.token(keystone.getId());
+ return neutronClient;
+ }
+
+
+ /**
+ * Query Networks
+ *
+ *
+ * @param cloudSiteId the cloud site id
+ * @param tenantId the tenant id
+ * @param limit limits the number of records returned
+ * @param marker the last viewed record
+ * @param name of the newtork
+ * @param id of the network
+ * @return the list of networks in openstack
+ * @throws MsoCloudSiteNotFound the mso cloud site not found
+ * @throws NeutronClientException if the client cannot be built this is thrown
+ */
+ public Networks queryNetworks(String cloudSiteId, String tenantId, int limit, String marker, String name, String id)
+ throws MsoCloudSiteNotFound, NeutronClientException {
+ try {
+ Quantum neutronClient = getNeutronClient(cloudSiteId, tenantId);
+ OpenStackRequest<Networks> request = neutronClient.networks().list().queryParam("id", id)
+ .queryParam("limit", limit).queryParam("marker", marker).queryParam("name", name);
+ return executeAndRecordOpenstackRequest(request);
+ } catch (MsoException e) {
+ logger.error("Error building Neutron Client", e);
+ throw new NeutronClientException("Error building Neutron Client", e);
+ }
+ }
+
+
+ /**
+ * Query Networks
+ *
+ *
+ * @param cloudSiteId the cloud site id
+ * @param tenantId the tenant id
+ * @param limit limits the number of records returned
+ * @param marker the last viewed record
+ * @param name of the subnet
+ * @param id of the subnet
+ * @return the list of subnets in openstack
+ * @throws MsoCloudSiteNotFound the mso cloud site not found
+ * @throws NeutronClientException if the client cannot be built this is thrown
+ */
+ public Subnets querySubnets(String cloudSiteId, String tenantId, int limit, String marker, String name, String id)
+ throws MsoCloudSiteNotFound, NeutronClientException {
+ try {
+ Quantum neutronClient = getNeutronClient(cloudSiteId, tenantId);
+ OpenStackRequest<Subnets> request = neutronClient.subnets().list().queryParam("id", id)
+ .queryParam("limit", limit).queryParam("marker", marker).queryParam("name", name);
+ return executeAndRecordOpenstackRequest(request);
+ } catch (MsoException e) {
+ logger.error("Error building Neutron Client", e);
+ throw new NeutronClientException("Error building Neutron Client", e);
+ }
+ }
+
+}
diff --git a/adapters/mso-adapter-utils/src/main/java/org/onap/so/openstack/utils/NovaClientException.java b/adapters/mso-adapter-utils/src/main/java/org/onap/so/openstack/utils/NovaClientException.java
new file mode 100644
index 0000000000..c5b6563dff
--- /dev/null
+++ b/adapters/mso-adapter-utils/src/main/java/org/onap/so/openstack/utils/NovaClientException.java
@@ -0,0 +1,33 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * ONAP - SO
+ * ================================================================================
+ * Copyright (C) 2019 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.onap.so.openstack.utils;
+
+public class NovaClientException extends Exception {
+
+ public NovaClientException(String error, Exception e) {
+ super(error, e);
+ }
+
+ /**
+ *
+ */
+ private static final long serialVersionUID = -1920095376579954885L;
+
+}
diff --git a/adapters/mso-adapter-utils/src/main/java/org/onap/so/openstack/utils/NovaClientImpl.java b/adapters/mso-adapter-utils/src/main/java/org/onap/so/openstack/utils/NovaClientImpl.java
new file mode 100644
index 0000000000..a342f770ef
--- /dev/null
+++ b/adapters/mso-adapter-utils/src/main/java/org/onap/so/openstack/utils/NovaClientImpl.java
@@ -0,0 +1,186 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * ONAP - SO
+ * ================================================================================
+ * Copyright (C) 2019 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.onap.so.openstack.utils;
+
+import org.onap.so.cloud.authentication.KeystoneAuthHolder;
+import org.onap.so.openstack.exceptions.MsoCloudSiteNotFound;
+import org.onap.so.openstack.exceptions.MsoException;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.stereotype.Component;
+import com.woorea.openstack.base.client.OpenStackRequest;
+import com.woorea.openstack.nova.Nova;
+import com.woorea.openstack.nova.model.Flavor;
+import com.woorea.openstack.nova.model.Flavors;
+import com.woorea.openstack.nova.model.HostAggregate;
+import com.woorea.openstack.nova.model.HostAggregates;
+import com.woorea.openstack.nova.model.QuotaSet;
+
+
+@Component
+public class NovaClientImpl extends MsoCommonUtils {
+
+
+ /** The logger. */
+ private static final Logger logger = LoggerFactory.getLogger(NovaClientImpl.class);
+
+ /**
+ * Gets the Nova client
+ *
+ * @param cloudSiteId id of the cloud site
+ * @param tenantId the tenant id
+ * @return the Nova client
+ * @throws MsoException the mso exception
+ */
+ private Nova getNovaClient(String cloudSiteId, String tenantId) throws MsoException {
+ KeystoneAuthHolder keystone = getKeystoneAuthHolder(cloudSiteId, tenantId, "compute");
+ Nova novaClient = new Nova(keystone.getServiceUrl());
+ novaClient.token(keystone.getId());
+ return novaClient;
+ }
+
+
+ /**
+ * Query Networks
+ *
+ *
+ * @param cloudSiteId the cloud site id
+ * @param tenantId the tenant id
+ * @param limit limits the number of records returned
+ * @param marker the last viewed record
+ * @param name of the newtork
+ * @param id of the network
+ * @return the list of networks in openstack
+ * @throws MsoCloudSiteNotFound the mso cloud site not found
+ * @throws NeutronClientException if the client cannot be built this is thrown
+ */
+ public Flavors queryFlavors(String cloudSiteId, String tenantId, int limit, String marker)
+ throws MsoCloudSiteNotFound, NovaClientException {
+ try {
+ Nova novaClient = getNovaClient(cloudSiteId, tenantId);
+ OpenStackRequest<Flavors> request =
+ novaClient.flavors().list(false).queryParam("limit", limit).queryParam("marker", marker);
+ return executeAndRecordOpenstackRequest(request);
+ } catch (MsoException e) {
+ logger.error("Error building Nova Client", e);
+ throw new NovaClientException("Error building Nova Client", e);
+ }
+
+ }
+
+ /**
+ * Query Networks
+ *
+ *
+ * @param cloudSiteId the cloud site id
+ * @param tenantId the tenant id
+ * @param id of the network
+ * @return the the flavor from openstack
+ * @throws MsoCloudSiteNotFound the mso cloud site not found
+ * @throws NeutronClientException if the client cannot be built this is thrown
+ */
+ public Flavor queryFlavorById(String cloudSiteId, String tenantId, String id)
+ throws MsoCloudSiteNotFound, NovaClientException {
+ try {
+ Nova novaClient = getNovaClient(cloudSiteId, tenantId);
+ novaClient = getNovaClient(cloudSiteId, tenantId);
+ OpenStackRequest<Flavor> request = novaClient.flavors().show(id);
+ return executeAndRecordOpenstackRequest(request);
+ } catch (MsoException e) {
+ logger.error("Error building Nova Client", e);
+ throw new NovaClientException("Error building Nova Client", e);
+ }
+ }
+
+ /**
+ * Query Host Aggregates
+ *
+ *
+ * @param cloudSiteId the cloud site id
+ * @param tenantId the tenant id
+ * @param limit limits the number of records returned
+ * @param marker the last viewed record
+ * @return the list of host aggregates found in openstack
+ * @throws MsoCloudSiteNotFound the mso cloud site not found
+ * @throws NeutronClientException if the client cannot be built this is thrown
+ */
+ public HostAggregates queryHostAggregates(String cloudSiteId, String tenantId, int limit, String marker)
+ throws MsoCloudSiteNotFound, NovaClientException {
+ try {
+ Nova novaClient = getNovaClient(cloudSiteId, tenantId);
+ OpenStackRequest<HostAggregates> request =
+ novaClient.aggregates().list().queryParam("limit", limit).queryParam("marker", marker);
+ return executeAndRecordOpenstackRequest(request);
+ } catch (MsoException e) {
+ logger.error("Error building Nova Client", e);
+ throw new NovaClientException("Error building Nova Client", e);
+ }
+ }
+
+ /**
+ * Query Host Aggregate
+ *
+ *
+ * @param cloudSiteId the cloud site id
+ * @param tenantId the tenant id
+ * @param limit limits the number of records returned
+ * @param marker the last viewed record
+ * @return a host aggregate
+ * @throws MsoCloudSiteNotFound the mso cloud site not found
+ * @throws NeutronClientException if the client cannot be built this is thrown
+ */
+ public HostAggregate queryHostAggregateById(String cloudSiteId, String tenantId, String id)
+ throws MsoCloudSiteNotFound, NovaClientException {
+ try {
+ Nova novaClient = getNovaClient(cloudSiteId, tenantId);
+ OpenStackRequest<HostAggregate> request = novaClient.aggregates().showAggregate(id);
+ return executeAndRecordOpenstackRequest(request);
+ } catch (MsoException e) {
+ logger.error("Error building Nova Client", e);
+ throw new NovaClientException("Error building Nova Client", e);
+ }
+ }
+
+ /**
+ * Query OS Quota Set
+ *
+ *
+ * @param cloudSiteId the cloud site id
+ * @param tenantId the tenant id
+ * @param limit limits the number of records returned
+ * @param marker the last viewed record
+ * @return a host aggregate
+ * @throws MsoCloudSiteNotFound the mso cloud site not found
+ * @throws NeutronClientException if the client cannot be built this is thrown
+ */
+ public QuotaSet queryOSQuotaSet(String cloudSiteId, String tenantId)
+ throws MsoCloudSiteNotFound, NovaClientException {
+ try {
+ Nova novaClient = getNovaClient(cloudSiteId, tenantId);
+ OpenStackRequest<QuotaSet> request = novaClient.quotaSets().showQuota(tenantId);
+ return executeAndRecordOpenstackRequest(request);
+ } catch (MsoException e) {
+ logger.error("Error building Nova Client", e);
+ throw new NovaClientException("Error building Nova Client", e);
+ }
+ }
+
+}
diff --git a/adapters/mso-adapter-utils/src/main/java/org/onap/so/openstack/utils/StackStatusHandler.java b/adapters/mso-adapter-utils/src/main/java/org/onap/so/openstack/utils/StackStatusHandler.java
new file mode 100644
index 0000000000..990e9a4543
--- /dev/null
+++ b/adapters/mso-adapter-utils/src/main/java/org/onap/so/openstack/utils/StackStatusHandler.java
@@ -0,0 +1,43 @@
+package org.onap.so.openstack.utils;
+
+
+import org.onap.so.db.request.beans.RequestProcessingData;
+import org.onap.so.db.request.client.RequestsDbClient;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.scheduling.annotation.Async;
+import org.springframework.stereotype.Component;
+import com.fasterxml.jackson.databind.ObjectMapper;
+import com.woorea.openstack.heat.model.Stack;
+
+@Component
+public class StackStatusHandler {
+
+ private static final Logger logger = LoggerFactory.getLogger(StackStatusHandler.class);
+ private static final ObjectMapper mapper = new ObjectMapper();
+
+ @Autowired
+ private RequestsDbClient requestDBClient;
+
+ @Async
+ public void updateStackStatus(Stack stack, String requestId) {
+ try {
+ String stackStatus = mapper.writeValueAsString(stack);
+ RequestProcessingData requestProcessingData =
+ requestDBClient.getRequestProcessingDataBySoRequestIdAndNameAndGrouping(requestId, stack.getId(),
+ stack.getStackName());
+ if (requestProcessingData == null) {
+ requestProcessingData = new RequestProcessingData();
+ requestProcessingData.setGroupingId(stack.getId());
+ requestProcessingData.setName(stack.getStackName());
+ requestProcessingData.setTag("StackInformation");
+ requestProcessingData.setSoRequestId(requestId);
+ }
+ requestProcessingData.setValue(stackStatus);
+ requestDBClient.saveRequestProcessingData(requestProcessingData);
+ } catch (Exception e) {
+ logger.warn("Error adding stack status to request database", e);
+ }
+ }
+}
diff --git a/adapters/mso-adapter-utils/src/test/java/org/onap/so/cloud/authentication/KeystoneAuthHolderTest.java b/adapters/mso-adapter-utils/src/test/java/org/onap/so/cloud/authentication/KeystoneAuthHolderTest.java
index 5bd77d8e10..0137148835 100644
--- a/adapters/mso-adapter-utils/src/test/java/org/onap/so/cloud/authentication/KeystoneAuthHolderTest.java
+++ b/adapters/mso-adapter-utils/src/test/java/org/onap/so/cloud/authentication/KeystoneAuthHolderTest.java
@@ -65,7 +65,7 @@ public class KeystoneAuthHolderTest {
@Test
public void testGetServiceUrl() {
- keystoneAuthHolder.setHeatUrl("testURL");
+ keystoneAuthHolder.setServiceUrl("testURL");
assertEquals("testURL", keystoneAuthHolder.getServiceUrl());
}