aboutsummaryrefslogtreecommitdiffstats
path: root/adapters/mso-tenant-adapter/src/main/java/org/openecomp
diff options
context:
space:
mode:
authorChrisC <cc697w@intl.att.com>2017-01-31 11:40:03 +0100
committerChrisC <cc697w@intl.att.com>2017-01-31 12:59:33 +0100
commit025301d08b061482c1f046d562bf017c8cbcfe8d (patch)
tree68a2a549736c9bf0f7cd4e71c76e40ef7e2606f2 /adapters/mso-tenant-adapter/src/main/java/org/openecomp
parent2754ad52f833278a5c925bd788a16d1dce16a598 (diff)
Initial OpenECOMP MSO commit
Change-Id: Ia6a7574859480717402cc2f22534d9973a78fa6d Signed-off-by: ChrisC <cc697w@intl.att.com>
Diffstat (limited to 'adapters/mso-tenant-adapter/src/main/java/org/openecomp')
-rw-r--r--adapters/mso-tenant-adapter/src/main/java/org/openecomp/mso/adapters/tenant/HealthCheckHandler.java59
-rw-r--r--adapters/mso-tenant-adapter/src/main/java/org/openecomp/mso/adapters/tenant/MsoTenantAdapter.java77
-rw-r--r--adapters/mso-tenant-adapter/src/main/java/org/openecomp/mso/adapters/tenant/MsoTenantAdapterImpl.java279
-rw-r--r--adapters/mso-tenant-adapter/src/main/java/org/openecomp/mso/adapters/tenant/TenantAdapterRest.java297
-rw-r--r--adapters/mso-tenant-adapter/src/main/java/org/openecomp/mso/adapters/tenant/exceptions/TenantAlreadyExists.java45
-rw-r--r--adapters/mso-tenant-adapter/src/main/java/org/openecomp/mso/adapters/tenant/exceptions/TenantException.java76
-rw-r--r--adapters/mso-tenant-adapter/src/main/java/org/openecomp/mso/adapters/tenant/exceptions/TenantExceptionBean.java64
7 files changed, 897 insertions, 0 deletions
diff --git a/adapters/mso-tenant-adapter/src/main/java/org/openecomp/mso/adapters/tenant/HealthCheckHandler.java b/adapters/mso-tenant-adapter/src/main/java/org/openecomp/mso/adapters/tenant/HealthCheckHandler.java
new file mode 100644
index 0000000000..7916be2aa9
--- /dev/null
+++ b/adapters/mso-tenant-adapter/src/main/java/org/openecomp/mso/adapters/tenant/HealthCheckHandler.java
@@ -0,0 +1,59 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * OPENECOMP - MSO
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.openecomp.mso.adapters.tenant;
+
+
+import javax.ws.rs.GET;
+import javax.ws.rs.HEAD;
+import javax.ws.rs.Path;
+import javax.ws.rs.Produces;
+import javax.ws.rs.QueryParam;
+import javax.ws.rs.core.Response;
+
+import org.openecomp.mso.logger.MsoLogger;
+import org.openecomp.mso.HealthCheckUtils;
+import org.openecomp.mso.utils.UUIDChecker;
+
+@Path("/")
+ public class HealthCheckHandler {
+
+ private static MsoLogger msoLogger = MsoLogger.getMsoLogger(MsoLogger.Catalog.RA);
+ @HEAD
+ @GET
+ @Path("/healthcheck")
+ @Produces("text/html")
+ public Response healthcheck (@QueryParam("requestId") String requestId) {
+ long startTime = System.currentTimeMillis ();
+ MsoLogger.setServiceName ("Healthcheck");
+ UUIDChecker.verifyOldUUID(requestId, msoLogger);
+ HealthCheckUtils healthCheck = new HealthCheckUtils ();
+ if (!healthCheck.siteStatusCheck(msoLogger, startTime)) {
+ return HealthCheckUtils.HEALTH_CHECK_NOK_RESPONSE;
+ }
+
+ if (!healthCheck.catalogDBCheck (msoLogger, startTime)) {
+ return HealthCheckUtils.NOT_STARTED_RESPONSE;
+ }
+ msoLogger.debug("healthcheck - Successful");
+ return HealthCheckUtils.HEALTH_CHECK_RESPONSE;
+ }
+
+}
diff --git a/adapters/mso-tenant-adapter/src/main/java/org/openecomp/mso/adapters/tenant/MsoTenantAdapter.java b/adapters/mso-tenant-adapter/src/main/java/org/openecomp/mso/adapters/tenant/MsoTenantAdapter.java
new file mode 100644
index 0000000000..a86c93828f
--- /dev/null
+++ b/adapters/mso-tenant-adapter/src/main/java/org/openecomp/mso/adapters/tenant/MsoTenantAdapter.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.adapters.tenant;
+
+
+import java.util.Map;
+
+import javax.jws.WebMethod;
+import javax.jws.WebParam;
+import javax.jws.WebParam.Mode;
+import javax.jws.WebService;
+import javax.xml.bind.annotation.XmlElement;
+import javax.xml.ws.Holder;
+
+import org.openecomp.mso.adapters.tenant.exceptions.TenantAlreadyExists;
+import org.openecomp.mso.adapters.tenant.exceptions.TenantException;
+import org.openecomp.mso.adapters.tenantrest.TenantRollback;
+import org.openecomp.mso.entity.MsoRequest;
+
+@WebService (name="TenantAdapter", targetNamespace="http://com.att.mso/tenant")
+public interface MsoTenantAdapter
+{
+ /**
+ * This is the "Create Tenant" Web Service Endpoint definition.
+ */
+ @WebMethod
+ public void createTenant (@WebParam(name="cloudSiteId") @XmlElement(required=true) String cloudSiteId,
+ @WebParam(name="tenantName") @XmlElement(required=true) String tenantName,
+ @WebParam(name="metadata") Map<String,String> metadata,
+ @WebParam(name="failIfExists") Boolean failIfExists,
+ @WebParam(name="backout") Boolean backout,
+ @WebParam(name="request") MsoRequest msoRequest,
+ @WebParam(name="tenantId", mode=Mode.OUT) Holder<String> tenantId,
+ @WebParam(name="rollback", mode=Mode.OUT) Holder<TenantRollback> rollback )
+ throws TenantException, TenantAlreadyExists;
+
+ @WebMethod
+ public void queryTenant (@WebParam(name="cloudSiteId") @XmlElement(required=true) String cloudSiteId,
+ @WebParam(name="tenantNameOrId") @XmlElement(required=true) String tenantNameOrId,
+ @WebParam(name="request") MsoRequest msoRequest,
+ @WebParam(name="tenantId", mode=Mode.OUT) Holder<String> tenantId,
+ @WebParam(name="tenantName", mode=Mode.OUT) Holder<String> tenantName,
+ @WebParam(name="metadata", mode=Mode.OUT) Holder<Map<String,String>> metadata )
+ throws TenantException;
+
+ @WebMethod
+ public void deleteTenant (@WebParam(name="cloudSiteId") @XmlElement(required=true) String cloudSiteId,
+ @WebParam(name="tenantId") @XmlElement(required=true) String tenantId,
+ @WebParam(name="request") MsoRequest msoRequest,
+ @WebParam(name="tenantDeleted", mode=Mode.OUT) Holder<Boolean> tenantDeleted)
+ throws TenantException;
+
+ @WebMethod
+ public void rollbackTenant (@WebParam(name="rollback") @XmlElement(required=true) TenantRollback rollback)
+ throws TenantException;
+
+ @WebMethod
+ public void healthCheck ();
+}
diff --git a/adapters/mso-tenant-adapter/src/main/java/org/openecomp/mso/adapters/tenant/MsoTenantAdapterImpl.java b/adapters/mso-tenant-adapter/src/main/java/org/openecomp/mso/adapters/tenant/MsoTenantAdapterImpl.java
new file mode 100644
index 0000000000..040c682b3d
--- /dev/null
+++ b/adapters/mso-tenant-adapter/src/main/java/org/openecomp/mso/adapters/tenant/MsoTenantAdapterImpl.java
@@ -0,0 +1,279 @@
+/*-
+ * ============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.adapters.tenant;
+
+
+import java.util.Map;
+
+import javax.annotation.Resource;
+import javax.jws.WebService;
+import javax.xml.ws.Holder;
+import javax.xml.ws.WebServiceContext;
+
+import org.openecomp.mso.properties.MsoPropertiesFactory;
+import org.openecomp.mso.adapters.tenant.exceptions.TenantAlreadyExists;
+import org.openecomp.mso.adapters.tenant.exceptions.TenantException;
+import org.openecomp.mso.adapters.tenantrest.TenantRollback;
+import org.openecomp.mso.cloud.CloudConfigFactory;
+import org.openecomp.mso.entity.MsoRequest;
+import org.openecomp.mso.logger.MessageEnum;
+import org.openecomp.mso.logger.MsoLogger;
+import org.openecomp.mso.openstack.beans.MsoTenant;
+import org.openecomp.mso.openstack.exceptions.MsoException;
+import org.openecomp.mso.openstack.utils.MsoTenantUtils;
+import org.openecomp.mso.openstack.utils.MsoTenantUtilsFactory;
+
+@WebService(serviceName = "TenantAdapter", endpointInterface = "org.openecomp.mso.adapters.tenant.MsoTenantAdapter", targetNamespace = "http://com.att.mso/tenant")
+public class MsoTenantAdapterImpl implements MsoTenantAdapter {
+
+ MsoPropertiesFactory msoPropertiesFactory = new MsoPropertiesFactory();
+ MsoTenantUtilsFactory tFactory = new MsoTenantUtilsFactory(MSO_PROP_TENANT_ADAPTER);
+
+ public static final String MSO_PROP_TENANT_ADAPTER="MSO_PROP_TENANT_ADAPTER";
+
+ @Resource
+ WebServiceContext wsContext;
+
+ private static MsoLogger LOGGER = MsoLogger.getMsoLogger (MsoLogger.Catalog.RA);
+ /**
+ * Health Check web method. Does nothing but return to show the adapter is deployed.
+ */
+ @Override
+ public void healthCheck () {
+ LOGGER.debug ("Health check call in Tenant Adapter");
+ }
+
+ /**
+ * This is the "Create Tenant" web service implementation. It will create
+ * a new Tenant in the specified cloud. If the tenant already exists, this
+ * can be considered a success or failure, depending on the value of the
+ * 'failIfExists' parameter.
+ *
+ * The method returns the tenantId (the Openstack ID), and a TenantRollback
+ * object. This last object can be passed as-is to the rollbackTenant method
+ * to undo what (if anything) was created. This is useful if a Tenant is
+ * successfully created but the orchestrator fails on a subsequent operation.
+ */
+ @Override
+ public void createTenant (String cloudSiteId,
+ String tenantName,
+ Map <String, String> metadata,
+ Boolean failIfExists,
+ Boolean backout,
+ MsoRequest msoRequest,
+ Holder <String> tenantId,
+ Holder <TenantRollback> rollback) throws TenantException, TenantAlreadyExists {
+ MsoLogger.setLogContext (msoRequest);
+ MsoLogger.setServiceName ("CreateTenant");
+
+ LOGGER.debug ("Call to MSO createTenant adapter. Creating Tenant: " + tenantName
+ + "in "
+ + cloudSiteId);
+
+ // Will capture total time for metrics
+ long startTime = System.currentTimeMillis ();
+
+ // Start building up rollback object
+ TenantRollback tenantRollback = new TenantRollback ();
+ tenantRollback.setCloudId (cloudSiteId);
+ tenantRollback.setMsoRequest (msoRequest);
+
+ MsoTenantUtils tUtils = tFactory.getTenantUtils (cloudSiteId);
+
+ MsoTenant newTenant = null;
+ String newTenantId = null;
+ long queryTenantStartTime = System.currentTimeMillis ();
+ try {
+ newTenant = tUtils.queryTenantByName (tenantName, cloudSiteId);
+ LOGGER.recordMetricEvent (queryTenantStartTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully received response from Open Stack", "OpenStack", "QueryTenant", null);
+ } catch (MsoException me) {
+ LOGGER.recordMetricEvent (queryTenantStartTime, MsoLogger.StatusCode.ERROR, MsoLogger.ResponseCode.CommunicationError, "Exception while communicate with Open Stack", "OpenStack", "QueryTenant", null);
+ String error = "Create Tenant " + tenantName + ": " + me;
+ LOGGER.error (MessageEnum.RA_CREATE_TENANT_ERR, me.getMessage(), "OpenStack", "createTenant", MsoLogger.ErrorCode.DataError, "Exception while communicate with Open Stack", me);
+ LOGGER.recordAuditEvent (startTime, MsoLogger.StatusCode.ERROR, MsoLogger.ResponseCode.CommunicationError, error);
+ throw new TenantException (me);
+ }
+ if (newTenant == null) {
+ if (backout == null)
+ backout = true;
+ long createTenantStartTime = System.currentTimeMillis ();
+ try {
+ newTenantId = tUtils.createTenant (tenantName, cloudSiteId, metadata, backout.booleanValue ());
+ LOGGER.recordMetricEvent (createTenantStartTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully received response from Open Stack", "OpenStack", "CreateTenant", null);
+ } catch (MsoException me) {
+ LOGGER.recordMetricEvent (createTenantStartTime, MsoLogger.StatusCode.ERROR, MsoLogger.ResponseCode.CommunicationError, "Exception while communicate with Open Stack", "OpenStack", "CreateTenant", null);
+ String error = "Create Tenant " + tenantName + ": " + me;
+ LOGGER.error (MessageEnum.RA_CREATE_TENANT_ERR, me.getMessage(), "OpenStack", "createTenant", MsoLogger.ErrorCode.DataError, "Exception while communicate with Open Stack", me);
+ LOGGER.recordAuditEvent (startTime, MsoLogger.StatusCode.ERROR, MsoLogger.ResponseCode.CommunicationError, error);
+ throw new TenantException (me);
+ }
+ tenantRollback.setTenantId (newTenantId);
+ tenantRollback.setTenantCreated (true);
+ LOGGER.debug ("Tenant " + tenantName + " successfully created with ID " + newTenantId);
+ } else {
+ if (failIfExists != null && failIfExists) {
+ String error = "CreateTenant: Tenant " + tenantName + " already exists in " + cloudSiteId;
+ LOGGER.error (MessageEnum.RA_TENANT_ALREADY_EXIST, tenantName, cloudSiteId, "OpenStack", "", MsoLogger.ErrorCode.DataError, "CreateTenant, Tenant already exists");
+ LOGGER.recordAuditEvent (startTime, MsoLogger.StatusCode.ERROR, MsoLogger.ResponseCode.DataError, error);
+ throw new TenantAlreadyExists (tenantName, cloudSiteId, newTenant.getTenantId ());
+ }
+
+ newTenantId = newTenant.getTenantId ();
+ tenantRollback.setTenantCreated (false);
+ LOGGER.debug ("Tenant " + tenantName + " already exists with ID " + newTenantId);
+ }
+
+
+ tenantId.value = newTenantId;
+ rollback.value = tenantRollback;
+ LOGGER.recordAuditEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully create tenant");
+ return;
+ }
+
+ @Override
+ public void queryTenant (String cloudSiteId,
+ String tenantNameOrId,
+ MsoRequest msoRequest,
+ Holder <String> tenantId,
+ Holder <String> tenantName,
+ Holder <Map <String, String>> metadata) throws TenantException {
+ MsoLogger.setLogContext (msoRequest);
+ MsoLogger.setServiceName ("QueryTenant");
+ LOGGER.debug ("Querying Tenant " + tenantNameOrId + " in " + cloudSiteId);
+
+ // Will capture execution time for metrics
+ long startTime = System.currentTimeMillis ();
+
+ MsoTenantUtils tUtils = tFactory.getTenantUtils (cloudSiteId);
+
+ MsoTenant qTenant = null;
+ long subStartTime = System.currentTimeMillis ();
+ try {
+ qTenant = tUtils.queryTenant (tenantNameOrId, cloudSiteId);
+ LOGGER.recordMetricEvent (subStartTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully received response from Open Stack", "OpenStack", "QueryTenant", null);
+ if (qTenant == null) {
+ // Not found by ID, Try by name.
+ qTenant = tUtils.queryTenantByName (tenantNameOrId, cloudSiteId);
+ }
+
+ if (qTenant == null) {
+ LOGGER.debug ("QueryTenant: Tenant " + tenantNameOrId + " not found");
+ tenantId.value = null;
+ tenantName.value = null;
+ metadata.value = null;
+ } else {
+ LOGGER.debug ("QueryTenant: Tenant " + tenantNameOrId + " found with ID " + qTenant.getTenantId ());
+ tenantId.value = qTenant.getTenantId ();
+ tenantName.value = qTenant.getTenantName ();
+ metadata.value = qTenant.getMetadata ();
+ }
+ } catch (MsoException me) {
+ String error = "Query Tenant " + tenantNameOrId + ": " + me;
+ LOGGER.recordMetricEvent (subStartTime, MsoLogger.StatusCode.ERROR, MsoLogger.ResponseCode.CommunicationError, error, "OpenStack", "QueryTenant", null);
+ LOGGER.error (MessageEnum.RA_GENERAL_EXCEPTION, me.getMessage(), "OpenStack", "", MsoLogger.ErrorCode.DataError, "Exception in queryTenant", me);
+ LOGGER.recordAuditEvent (startTime, MsoLogger.StatusCode.ERROR, MsoLogger.ResponseCode.CommunicationError, error);
+ throw new TenantException (me);
+ }
+ LOGGER.recordAuditEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully query tenant");
+ return;
+ }
+
+ @Override
+ public void deleteTenant (String cloudSiteId,
+ String tenantId,
+ MsoRequest msoRequest,
+ Holder <Boolean> tenantDeleted) throws TenantException {
+ MsoLogger.setLogContext (msoRequest);
+ MsoLogger.setServiceName ("DeleteTenant");
+
+ LOGGER.debug ("Deleting Tenant " + tenantId + " in " + cloudSiteId);
+
+ // Will capture execution time for metrics
+ long startTime = System.currentTimeMillis ();
+
+ // Delete the Tenant.
+ long subStartTime = System.currentTimeMillis ();
+ try {
+
+ MsoTenantUtils tUtils = tFactory.getTenantUtils (cloudSiteId);
+ boolean deleted = tUtils.deleteTenant (tenantId, cloudSiteId);
+ tenantDeleted.value = deleted;
+ LOGGER.recordMetricEvent (subStartTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully communicate with Open Stack", "OpenStack", "DeleteTenant", null);
+ } catch (MsoException me) {
+ String error = "Delete Tenant " + tenantId + ": " + me;
+ LOGGER.recordMetricEvent (subStartTime, MsoLogger.StatusCode.ERROR, MsoLogger.ResponseCode.CommunicationError, error, "OpenStack", "DeleteTenant", null);
+ LOGGER.error (MessageEnum.RA_DELETE_TEMAMT_ERR, me.getMessage(), "OpenStack", "", MsoLogger.ErrorCode.DataError, "Exception - DeleteTenant", me);
+ LOGGER.recordAuditEvent (startTime, MsoLogger.StatusCode.ERROR, MsoLogger.ResponseCode.CommunicationError, error);
+ throw new TenantException (me);
+ }
+
+ // On success, nothing is returned.
+ LOGGER.recordAuditEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully delete tenant");
+ return;
+ }
+
+ /**
+ * This web service endpoint will rollback a previous Create VNF operation.
+ * A rollback object is returned to the client in a successful creation
+ * response. The client can pass that object as-is back to the rollbackVnf
+ * operation to undo the creation.
+ *
+ * The rollback includes removing the VNF and deleting the tenant if the
+ * tenant did not exist prior to the VNF creation.
+ */
+ @Override
+ public void rollbackTenant (TenantRollback rollback) throws TenantException {
+ long startTime = System.currentTimeMillis ();
+ MsoLogger.setServiceName ("RollbackTenant");
+ // rollback may be null (e.g. if stack already existed when Create was called)
+ if (rollback == null) {
+ LOGGER.warn (MessageEnum.RA_ROLLBACK_NULL, "OpenStack", "rollbackTenant", MsoLogger.ErrorCode.DataError, "rollbackTenant, rollback is null");
+ return;
+ }
+
+ // Get the elements of the VnfRollback object for easier access
+ String cloudSiteId = rollback.getCloudId ();
+ String tenantId = rollback.getTenantId ();
+
+ MsoLogger.setLogContext (rollback.getMsoRequest ());
+ LOGGER.debug ("Rolling Back Tenant " + rollback.getTenantId () + " in " + cloudSiteId);
+
+ long subStartTime = System.currentTimeMillis ();
+ if (rollback.getTenantCreated ()) {
+ try {
+
+ MsoTenantUtils tUtils = tFactory.getTenantUtils (cloudSiteId);
+ tUtils.deleteTenant (tenantId, cloudSiteId);
+ LOGGER.recordMetricEvent (subStartTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully communicate with Open Stack", "OpenStack", "RollbackTenant", null);
+ } catch (MsoException me) {
+ me.addContext ("RollbackTenant");
+ // Failed to delete the tenant.
+ String error = "Rollback Tenant " + tenantId + ": " + me;
+ LOGGER.recordMetricEvent (subStartTime, MsoLogger.StatusCode.ERROR, MsoLogger.ResponseCode.CommunicationError, error, "OpenStack", "RollbackTenant", null);
+ LOGGER.error (MessageEnum.RA_ROLLBACK_TENANT_ERR, me.getMessage(), "OpenStack", "rollbackTenant", MsoLogger.ErrorCode.DataError, "Exception - rollbackTenant", me);
+ LOGGER.recordAuditEvent (startTime, MsoLogger.StatusCode.ERROR, MsoLogger.ResponseCode.CommunicationError, error);
+ throw new TenantException (me);
+ }
+ }
+ LOGGER.recordAuditEvent (startTime, MsoLogger.StatusCode.COMPLETE, MsoLogger.ResponseCode.Suc, "Successfully roll back tenant");
+ return;
+ }
+}
diff --git a/adapters/mso-tenant-adapter/src/main/java/org/openecomp/mso/adapters/tenant/TenantAdapterRest.java b/adapters/mso-tenant-adapter/src/main/java/org/openecomp/mso/adapters/tenant/TenantAdapterRest.java
new file mode 100644
index 0000000000..0c9993cd20
--- /dev/null
+++ b/adapters/mso-tenant-adapter/src/main/java/org/openecomp/mso/adapters/tenant/TenantAdapterRest.java
@@ -0,0 +1,297 @@
+/*-
+ * ============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.adapters.tenant;
+
+
+import java.util.Map;
+
+import javax.servlet.http.HttpServletResponse;
+import javax.ws.rs.Consumes;
+import javax.ws.rs.DELETE;
+import javax.ws.rs.GET;
+import javax.ws.rs.HEAD;
+import javax.ws.rs.POST;
+import javax.ws.rs.Path;
+import javax.ws.rs.PathParam;
+import javax.ws.rs.Produces;
+import javax.ws.rs.QueryParam;
+import javax.ws.rs.core.MediaType;
+import javax.ws.rs.core.Response;
+import javax.xml.ws.Holder;
+
+import org.openecomp.mso.adapters.tenant.exceptions.TenantAlreadyExists;
+import org.openecomp.mso.adapters.tenant.exceptions.TenantException;
+import org.openecomp.mso.adapters.tenantrest.CreateTenantError;
+import org.openecomp.mso.adapters.tenantrest.CreateTenantRequest;
+import org.openecomp.mso.adapters.tenantrest.CreateTenantResponse;
+import org.openecomp.mso.adapters.tenantrest.DeleteTenantError;
+import org.openecomp.mso.adapters.tenantrest.DeleteTenantRequest;
+import org.openecomp.mso.adapters.tenantrest.DeleteTenantResponse;
+import org.openecomp.mso.adapters.tenantrest.QueryTenantError;
+import org.openecomp.mso.adapters.tenantrest.QueryTenantResponse;
+import org.openecomp.mso.adapters.tenantrest.RollbackTenantError;
+import org.openecomp.mso.adapters.tenantrest.RollbackTenantRequest;
+import org.openecomp.mso.adapters.tenantrest.RollbackTenantResponse;
+import org.openecomp.mso.adapters.tenantrest.TenantRollback;
+import org.openecomp.mso.logger.MsoLogger;
+import org.openecomp.mso.openstack.beans.MsoTenant;
+import org.openecomp.mso.openstack.exceptions.MsoExceptionCategory;
+
+/**
+ * This class services calls to the REST interface for Tenants (http://host:port/vnfs/rest/v1/tenants)
+ * Both XML and JSON can be produced/consumed. Set Accept: and Content-Type: headers appropriately. XML is the default.
+ */
+@Path("/v1/tenants")
+public class TenantAdapterRest {
+ private static MsoLogger LOGGER = MsoLogger.getMsoLogger (MsoLogger.Catalog.RA);
+
+ //RAA? No logging in wrappers
+
+ @HEAD
+ @GET
+ @Path("/healthcheck")
+ @Produces(MediaType.TEXT_HTML)
+ public Response healthcheck () {
+ String CHECK_HTML = "<!DOCTYPE html><html><head><meta charset=\"ISO-8859-1\"><title>Health Check</title></head><body>Application ready</body></html>";
+ return Response.status (HttpServletResponse.SC_OK).entity (CHECK_HTML).build ();
+ }
+
+ /*
+ URL:
+ EP: http://host:8080/tenants/rest
+ Resource: v1/tenants
+ REQ - metadata?
+ {
+ "cloudSiteId": "DAN",
+ "tenantName": "RAA_1",
+ "failIfExists": true,
+ "msoRequest": {
+ "requestId": "ra1",
+ "serviceInstanceId": "sa1"
+ }}
+ RESP-
+ {
+ "cloudSiteId": "DAN",
+ "tenantId": "128e10b9996d43a7874f19bbc4eb6749",
+ "tenantCreated": true,
+ "tenantRollback": {
+ "tenantId": "128e10b9996d43a7874f19bbc4eb6749",
+ "cloudId": "DAN", // RAA? cloudId instead of cloudSiteId
+ "tenantCreated": true,
+ "msoRequest": {
+ "requestId": "ra1",
+ "serviceInstanceId": "sa1"
+ }
+ }
+ }
+ */
+ @POST
+ @Consumes({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
+ @Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
+ public Response createTenant(CreateTenantRequest req) {
+ LOGGER.debug("createTenant enter: " + req.toJsonString());
+
+ String newTenantId = null;
+ TenantRollback tenantRollback = new TenantRollback ();
+
+ try {
+ Holder<String> htenant = new Holder<String>();
+ Holder<TenantRollback> hrollback = new Holder<TenantRollback>();
+ MsoTenantAdapter impl = new MsoTenantAdapterImpl();
+ impl.createTenant(
+ req.getCloudSiteId(),
+ req.getTenantName(),
+ req.getMetadata(),
+ req.getFailIfExists(),
+ req.getBackout(),
+ req.getMsoRequest(),
+ htenant,
+ hrollback);
+ newTenantId = htenant.value;
+ tenantRollback = hrollback.value;
+// TenantAdapterCore TAImpl = new TenantAdapterCore();
+// newTenantId = TAImpl.createTenant (req.getCloudSiteId(),
+// req.getTenantName(),
+// req.getFailIfExists(),
+// req.getBackout(),
+// req.getMetadata(),
+// req.getMsoRequest(),
+// tenantRollback);
+ }
+ catch (TenantAlreadyExists tae) {
+ CreateTenantError exc = new CreateTenantError(tae.getMessage(), tae.getFaultInfo().getCategory(), Boolean.TRUE);
+ return Response.status(HttpServletResponse.SC_NOT_IMPLEMENTED).entity(exc).build();
+ }
+ catch (TenantException te) {
+ CreateTenantError exc = new CreateTenantError(te.getFaultInfo().getMessage(), te.getFaultInfo().getCategory(), Boolean.TRUE);
+ return Response.status(HttpServletResponse.SC_INTERNAL_SERVER_ERROR).entity(exc).build();
+ }
+ catch (Exception e) {
+ CreateTenantError exc = new CreateTenantError(e.getMessage(), MsoExceptionCategory.INTERNAL, Boolean.TRUE);
+ return Response.status(HttpServletResponse.SC_INTERNAL_SERVER_ERROR).entity(exc).build();
+ }
+
+ CreateTenantResponse resp = new CreateTenantResponse (req.getCloudSiteId(), newTenantId, tenantRollback.getTenantCreated(), tenantRollback);
+ return Response.status(HttpServletResponse.SC_OK).entity(resp).build();
+ }
+
+ /*
+ URL:
+ http://host:8080/tenants/rest
+ Resource: v1/tenant/tennatId
+ REQ:
+ {"cloudSiteId": "DAN",
+ "tenantId": "ca84cd3d3df44272845da554656b3ace",
+ "msoRequest": {
+ "requestId": "ra1",
+ "serviceInstanceId": "sa1"
+ }
+ }
+ RESP:
+ {"tenantDeleted": true}
+ */
+ @DELETE
+ @Path("{tenantId}")
+ @Consumes({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
+ @Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
+ public Response deleteTenant(
+ @PathParam("tenantId") String tenantId,
+ DeleteTenantRequest req)
+ {
+ boolean tenantDeleted = false;
+
+ try {
+ Holder<Boolean> deleted = new Holder<Boolean>();
+ MsoTenantAdapter impl = new MsoTenantAdapterImpl();
+ impl.deleteTenant(
+ req.getCloudSiteId(),
+ req.getTenantId(),
+ req.getMsoRequest(),
+ deleted);
+ tenantDeleted = deleted.value;
+ }
+ catch (TenantException te) {
+ DeleteTenantError exc = new DeleteTenantError(te.getFaultInfo().getMessage(), te.getFaultInfo().getCategory(), Boolean.TRUE);
+ return Response.status(HttpServletResponse.SC_INTERNAL_SERVER_ERROR).entity(exc).build();
+ }
+ catch (Exception e) {
+ DeleteTenantError exc = new DeleteTenantError(e.getMessage(), MsoExceptionCategory.INTERNAL, Boolean.TRUE);
+ return Response.status(HttpServletResponse.SC_INTERNAL_SERVER_ERROR).entity(exc).build();
+ }
+ DeleteTenantResponse resp = new DeleteTenantResponse();
+ resp.setTenantDeleted(tenantDeleted);
+ return Response.status(HttpServletResponse.SC_OK).entity(resp).build();
+ }
+
+ /*
+ URL
+ EP://http://host:8080/tenants/rest
+ Resource: /v1/tenants
+ Params:?tenantNameOrId=RAA_1&cloudSiteId=DAN
+ RESP
+ {
+ "tenantId": "214b428a1f554c02935e66330f6a5409",
+ "tenantName": "RAA_1",
+ "metadata": {}
+ }
+ */
+ @GET
+ @Path("{tenantId}")
+ @Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
+ public Response queryTenant(
+ @PathParam("tenantId") String tenantId,
+// @QueryParam("tenantNameOrId") String tenantNameOrId, //RAA? diff from doc
+ @QueryParam("cloudSiteId") String cloudSiteId,
+ @QueryParam("msoRequest.requestId") String requestId,
+ @QueryParam("msoRequest.serviceInstanceId") String serviceInstanceId)
+ {
+ MsoTenant tenant = null;
+ try {
+ Holder<String> htenant = new Holder<String>();
+ Holder<String> tenantName = new Holder<String>();
+ Holder<Map<String,String>> metadata = new Holder<Map<String,String>>();
+ MsoTenantAdapter impl = new MsoTenantAdapterImpl();
+ impl.queryTenant(
+ cloudSiteId,
+ tenantId,
+ null,
+ htenant,
+ tenantName,
+ metadata
+ );
+ tenant = new MsoTenant(htenant.value, tenantName.value, metadata.value);
+// TenantAdapterCore TAImpl = new TenantAdapterCore();
+// MsoRequest msoReq = new MsoRequest();
+// tenant = TAImpl.queryTenant (cloudSiteId, tenantId, msoReq);
+ }
+ catch (TenantException te) {
+ QueryTenantError exc = new QueryTenantError(te.getFaultInfo().getMessage(), te.getFaultInfo().getCategory());
+ return Response.status(HttpServletResponse.SC_INTERNAL_SERVER_ERROR).entity(exc).build();
+ }
+ catch (Exception e) {
+ QueryTenantError exc = new QueryTenantError(e.getMessage(), MsoExceptionCategory.INTERNAL);
+ return Response.status(HttpServletResponse.SC_INTERNAL_SERVER_ERROR).entity(exc).build();
+ }
+ QueryTenantResponse resp = new QueryTenantResponse(tenant.getTenantId(), tenant.getTenantName(), tenant.getMetadata());
+ return Response.status(HttpServletResponse.SC_OK).entity(resp).build();
+ }
+
+ /*
+ URL
+ EP: //http://host:8080/tenants/rest
+ Resource: /v1/tenants/rollback
+ REQ
+ {"cloudSiteId": "DAN",
+ "tenantId": "f58abb05041d4ff384d4d22d1ccd2a6c",
+ "msoRequest": {
+ "requestId": "ra1",
+ "serviceInstanceId": "sa1"
+ }
+ }
+ RESP:
+ {"tenantDeleted": true}
+ */
+ @DELETE
+ @Path("")
+ @Consumes({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
+ @Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
+ public Response rollbackTenant(
+ @QueryParam("rollback") String action, // WTF?
+ RollbackTenantRequest req)
+ {
+ try {
+ MsoTenantAdapter impl = new MsoTenantAdapterImpl();
+ impl.rollbackTenant(req.getTenantRollback());
+ }
+ catch (TenantException te) {
+ RollbackTenantError exc = new RollbackTenantError(te.getFaultInfo().getMessage(), te.getFaultInfo().getCategory(), Boolean.TRUE);
+ return Response.status(HttpServletResponse.SC_INTERNAL_SERVER_ERROR).entity(exc).build();
+ }
+ catch (Exception e) {
+ RollbackTenantError exc = new RollbackTenantError(e.getMessage(), MsoExceptionCategory.INTERNAL, Boolean.TRUE);
+ return Response.status(HttpServletResponse.SC_INTERNAL_SERVER_ERROR).entity(exc).build();
+ }
+
+ RollbackTenantResponse resp = new RollbackTenantResponse ();
+ resp.setTenantRolledback(req != null);
+ return Response.status(HttpServletResponse.SC_OK).entity(resp).build();
+ }
+}
diff --git a/adapters/mso-tenant-adapter/src/main/java/org/openecomp/mso/adapters/tenant/exceptions/TenantAlreadyExists.java b/adapters/mso-tenant-adapter/src/main/java/org/openecomp/mso/adapters/tenant/exceptions/TenantAlreadyExists.java
new file mode 100644
index 0000000000..cc80b949dd
--- /dev/null
+++ b/adapters/mso-tenant-adapter/src/main/java/org/openecomp/mso/adapters/tenant/exceptions/TenantAlreadyExists.java
@@ -0,0 +1,45 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * OPENECOMP - MSO
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.openecomp.mso.adapters.tenant.exceptions;
+
+
+
+import javax.xml.ws.WebFault;
+
+import org.openecomp.mso.openstack.exceptions.MsoExceptionCategory;
+
+
+/**
+ * This class reports an exception when trying to create a VNF when another
+ * VNF of the same name already exists in the target cloud/tenant. Note that
+ * the createVnf method suppresses this exception by default.
+ *
+ *
+ */
+@WebFault (name="TenantAlreadyExists", faultBean="org.openecomp.mso.adapters.tenant.exceptions.TenantExceptionBean", targetNamespace="http://com.att.mso/tenant")
+public class TenantAlreadyExists extends TenantException {
+
+ private static final long serialVersionUID = 1L;
+
+ public TenantAlreadyExists (String name, String cloudId, String tenantId) {
+ super("Tenant " + name + " already exists in " + cloudId + " with ID " + tenantId, MsoExceptionCategory.USERDATA);
+ }
+}
diff --git a/adapters/mso-tenant-adapter/src/main/java/org/openecomp/mso/adapters/tenant/exceptions/TenantException.java b/adapters/mso-tenant-adapter/src/main/java/org/openecomp/mso/adapters/tenant/exceptions/TenantException.java
new file mode 100644
index 0000000000..f68b0fa65b
--- /dev/null
+++ b/adapters/mso-tenant-adapter/src/main/java/org/openecomp/mso/adapters/tenant/exceptions/TenantException.java
@@ -0,0 +1,76 @@
+/*-
+ * ============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.adapters.tenant.exceptions;
+
+
+
+import javax.xml.ws.WebFault;
+
+import org.openecomp.mso.adapters.tenant.exceptions.TenantExceptionBean;
+import org.openecomp.mso.openstack.exceptions.MsoException;
+import org.openecomp.mso.openstack.exceptions.MsoExceptionCategory;
+
+/**
+ * This class simply extends Exception (without addition additional functionality)
+ * to provide an identifier for Tenant related exceptions on create, delete, query.
+ *
+ *
+ */
+@WebFault (name="TenantException", faultBean="org.openecomp.mso.adapters.tenant.exceptions.TenantExceptionBean", targetNamespace="http://com.att.mso/tenant")
+public class TenantException extends Exception {
+
+ private static final long serialVersionUID = 1L;
+
+ private TenantExceptionBean faultInfo;
+
+ public TenantException (String msg) {
+ super(msg);
+ faultInfo = new TenantExceptionBean (msg);
+ }
+
+ public TenantException (String msg, Throwable e) {
+ super (msg, e);
+ faultInfo = new TenantExceptionBean (msg);
+ }
+
+ public TenantException (String msg, MsoExceptionCategory category) {
+ super(msg);
+ faultInfo = new TenantExceptionBean (msg, category);
+ }
+
+ public TenantException (String msg, MsoExceptionCategory category, Throwable e) {
+ super (msg, e);
+ faultInfo = new TenantExceptionBean (msg, category);
+ }
+
+ public TenantException (MsoException e) {
+ super (e);
+ faultInfo = new TenantExceptionBean (e.getContextMessage(), e.getCategory());
+ }
+
+ public TenantExceptionBean getFaultInfo() {
+ return faultInfo;
+ }
+
+ public void setFaultInfo(TenantExceptionBean faultInfo) {
+ this.faultInfo = faultInfo;
+ }
+}
diff --git a/adapters/mso-tenant-adapter/src/main/java/org/openecomp/mso/adapters/tenant/exceptions/TenantExceptionBean.java b/adapters/mso-tenant-adapter/src/main/java/org/openecomp/mso/adapters/tenant/exceptions/TenantExceptionBean.java
new file mode 100644
index 0000000000..61c8f331df
--- /dev/null
+++ b/adapters/mso-tenant-adapter/src/main/java/org/openecomp/mso/adapters/tenant/exceptions/TenantExceptionBean.java
@@ -0,0 +1,64 @@
+/*-
+ * ============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.adapters.tenant.exceptions;
+
+
+import java.io.Serializable;
+
+import org.openecomp.mso.openstack.exceptions.MsoExceptionCategory;
+
+/**
+ * Jax-WS Fault Bean for Network Exceptions
+ */
+public class TenantExceptionBean implements Serializable {
+
+ private static final long serialVersionUID = -9062290006520066109L;
+
+ private String message;
+ private MsoExceptionCategory category;
+
+ public TenantExceptionBean () {}
+
+ public TenantExceptionBean (String message) {
+ this.message = message;
+ }
+
+ public TenantExceptionBean (String message, MsoExceptionCategory category) {
+ this.message = message;
+ this.category = category;
+ }
+
+ public String getMessage() {
+ return message;
+ }
+
+ public void setMessage(String message) {
+ this.message = message;
+ }
+
+ public MsoExceptionCategory getCategory () {
+ return category;
+ }
+
+ public void setCategory (MsoExceptionCategory category) {
+ this.category = category;
+ }
+}