First part of onap rename
[appc.git] / appc-adapters / appc-iaas-adapter / appc-iaas-adapter-bundle / src / main / java / org / openecomp / appc / adapter / iaas / provider / operation / impl / StartServer.java
index 41b0afd..1dbeacb 100644 (file)
@@ -1,10 +1,11 @@
 /*-
  * ============LICENSE_START=======================================================
- * openECOMP : APP-C
+ * ONAP : APPC
  * ================================================================================
- * Copyright (C) 2017 AT&T Intellectual Property. All rights
- *                                             reserved.
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
  * ================================================================================
+ * Copyright (C) 2017 Amdocs
+ * =============================================================================
  * 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
  * 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.
+ * 
+ * ECOMP is a trademark and service mark of AT&T Intellectual Property.
  * ============LICENSE_END=========================================================
  */
 
-package org.openecomp.appc.adapter.iaas.provider.operation.impl;
-
-import org.openecomp.appc.Constants;
-import org.openecomp.appc.adapter.iaas.ProviderAdapter;
-import org.openecomp.appc.adapter.iaas.impl.IdentityURL;
-import org.openecomp.appc.adapter.iaas.impl.RequestContext;
-import org.openecomp.appc.adapter.iaas.impl.RequestFailedException;
-import org.openecomp.appc.adapter.iaas.impl.VMURL;
-import org.openecomp.appc.adapter.iaas.provider.operation.common.enums.Operation;
-import org.openecomp.appc.adapter.iaas.provider.operation.impl.base.ProviderServerOperation;
-import org.openecomp.appc.exceptions.APPCException;
-import org.openecomp.appc.i18n.Msg;
+package org.onap.appc.adapter.iaas.provider.operation.impl;
+
+import org.onap.appc.Constants;
+import org.onap.appc.adapter.iaas.ProviderAdapter;
+import org.onap.appc.adapter.iaas.impl.IdentityURL;
+import org.onap.appc.adapter.iaas.impl.RequestContext;
+import org.onap.appc.adapter.iaas.impl.RequestFailedException;
+import org.onap.appc.adapter.iaas.impl.VMURL;
+import org.onap.appc.adapter.iaas.provider.operation.common.enums.Operation;
+import org.onap.appc.adapter.iaas.provider.operation.impl.base.ProviderServerOperation;
+import org.onap.appc.exceptions.APPCException;
+import org.onap.appc.i18n.Msg;
 import com.att.cdp.exceptions.ResourceNotFoundException;
 import com.att.cdp.zones.Context;
 import com.att.cdp.zones.model.ModelObject;
@@ -38,20 +41,19 @@ import com.att.cdp.zones.model.Server;
 import com.att.eelf.configuration.EELFLogger;
 import com.att.eelf.configuration.EELFManager;
 import com.att.eelf.i18n.EELFResourceManager;
-import org.openecomp.sdnc.sli.SvcLogicContext;
+import org.onap.ccsdk.sli.core.sli.SvcLogicContext;
 import org.glassfish.grizzly.http.util.HttpStatus;
-
 import java.util.Map;
-
-import static org.openecomp.appc.adapter.iaas.provider.operation.common.enums.Operation.START_SERVICE;
-import static org.openecomp.appc.adapter.utils.Constants.ADAPTER_NAME;
+import static org.onap.appc.adapter.iaas.provider.operation.common.enums.Operation.START_SERVICE;
+import static org.onap.appc.adapter.utils.Constants.ADAPTER_NAME;
 
 public class StartServer extends ProviderServerOperation {
 
     private static final EELFLogger logger = EELFManager.getInstance().getLogger(StartServer.class);
 
     /**
-     * @see org.openecomp.appc.adapter.iaas.ProviderAdapter#startServer(java.util.Map, org.openecomp.sdnc.sli.SvcLogicContext)
+     * @see org.onap.appc.adapter.iaas.ProviderAdapter#startServer(java.util.Map,
+     *      org.openecomp.sdnc.sli.SvcLogicContext)
      */
     @SuppressWarnings("nls")
     public Server startServer(Map<String, String> params, SvcLogicContext ctx) throws APPCException {
@@ -68,7 +70,8 @@ public class StartServer extends ProviderServerOperation {
             String vm_url = params.get(ProviderAdapter.PROPERTY_INSTANCE_URL);
 
             VMURL vm = VMURL.parseURL(vm_url);
-            if (validateVM(rc, appName, vm_url, vm)) return null;
+            if (validateVM(rc, appName, vm_url, vm))
+                return null;
 
             IdentityURL ident = IdentityURL.parseURL(params.get(ProviderAdapter.PROPERTY_IDENTITY_URL));
             String identStr = (ident == null) ? null : ident.toString();
@@ -83,17 +86,15 @@ public class StartServer extends ProviderServerOperation {
                     logger.debug(Msg.SERVER_FOUND, vm_url, context.getTenantName(), server.getStatus().toString());
                     String msg;
 
-                       /*
-                        * We determine what to do based on the current state of the server
-                        */
+                    /*
+                     * We determine what to do based on the current state of the server
+                     */
 
-                       /*
-                        * Pending is a bit of a special case. If we find the server is in a
-                        * pending state, then the provider is in the process of changing state
-                        * of the server. So, lets try to wait a little bit and see if the state
-                        * settles down to one we can deal with. If not, then we have to fail
-                        * the request.
-                        */
+                    /*
+                     * Pending is a bit of a special case. If we find the server is in a pending state, then the
+                     * provider is in the process of changing state of the server. So, lets try to wait a little bit and
+                     * see if the state settles down to one we can deal with. If not, then we have to fail the request.
+                     */
 
                     if (server.getStatus().equals(Server.Status.PENDING)) {
                         waitForStateChange(rc, server, Server.Status.READY, Server.Status.RUNNING, Server.Status.ERROR,
@@ -106,8 +107,8 @@ public class StartServer extends ProviderServerOperation {
                             msg = EELFResourceManager.format(Msg.SERVER_DELETED, server.getName(), server.getId(),
                                     server.getTenantId(), "started");
                             logger.error(msg);
-                            //                                 metricsLogger.error(msg);
-                            throw new RequestFailedException("Start Server", msg, HttpStatus.METHOD_NOT_ALLOWED_405, server);
+                            throw new RequestFailedException("Start Server", msg, HttpStatus.METHOD_NOT_ALLOWED_405,
+                                    server);
 
                         case RUNNING:
                             // Nothing to do, the server is already running
@@ -119,8 +120,8 @@ public class StartServer extends ProviderServerOperation {
                             msg = EELFResourceManager.format(Msg.SERVER_ERROR_STATE, server.getName(), server.getId(),
                                     server.getTenantId(), "start");
                             logger.error(msg);
-                            //                                 metricsLogger.error(msg);
-                            throw new RequestFailedException("Start Server", msg, HttpStatus.METHOD_NOT_ALLOWED_405, server);
+                            throw new RequestFailedException("Start Server", msg, HttpStatus.METHOD_NOT_ALLOWED_405,
+                                    server);
 
                         case READY:
                             // Server is stopped attempt to start the server
@@ -132,14 +133,12 @@ public class StartServer extends ProviderServerOperation {
                             // if paused, un-pause it
                             rc.reset();
                             unpauseServer(rc, server);
-                            //                                 metricsLogger.info("Server status: PAUSED");
                             break;
 
                         case SUSPENDED:
                             // Attempt to resume the suspended server
                             rc.reset();
                             resumeServer(rc, server);
-                            //                                 metricsLogger.info("Server status: SUSPENDED");
                             break;
 
                         default:
@@ -148,25 +147,24 @@ public class StartServer extends ProviderServerOperation {
                                     server.getTenantId(), server.getStatus().name());
                             generateEvent(rc, false, msg);
                             logger.error(msg);
-                            //                                 metricsLogger.error(msg);
-                            throw new RequestFailedException("Start Server", msg, HttpStatus.METHOD_NOT_ALLOWED_405, server);
+                            throw new RequestFailedException("Start Server", msg, HttpStatus.METHOD_NOT_ALLOWED_405,
+                                    server);
                     }
                     context.close();
                     doSuccess(rc);
                     ctx.setAttribute("START_STATUS", "SUCCESS");
-                }
-                else
-                {
+                } else {
                     ctx.setAttribute("START_STATUS", "CONTEXT_NOT_FOUND");
                 }
             } catch (ResourceNotFoundException e) {
                 String msg = EELFResourceManager.format(Msg.SERVER_NOT_FOUND, e, vm_url);
                 logger.error(msg);
                 doFailure(rc, HttpStatus.NOT_FOUND_404, msg);
-            } catch (Throwable t) {
-                String msg = EELFResourceManager.format(Msg.SERVER_OPERATION_EXCEPTION, t, t.getClass().getSimpleName(),
-                        START_SERVICE.toString(), vm_url, context == null ? "Unknown" : context.getTenantName());
-                logger.error(msg, t);
+            } catch (Exception e1) {
+                String msg = EELFResourceManager.format(Msg.SERVER_OPERATION_EXCEPTION, e1,
+                        e1.getClass().getSimpleName(), START_SERVICE.toString(), vm_url,
+                        context == null ? "Unknown" : context.getTenantName());
+                logger.error(msg, e1);
                 doFailure(rc, HttpStatus.INTERNAL_SERVER_ERROR_500, msg);
             }
         } catch (RequestFailedException e) {
@@ -177,8 +175,8 @@ public class StartServer extends ProviderServerOperation {
     }
 
     @Override
-    protected ModelObject executeProviderOperation(Map<String, String> params, SvcLogicContext context) throws APPCException {
-
+    protected ModelObject executeProviderOperation(Map<String, String> params, SvcLogicContext context)
+            throws APPCException {
         setMDC(Operation.START_SERVICE.toString(), "App-C IaaS Adapter:Start", ADAPTER_NAME);
         logOperation(Msg.STARTING_SERVER, params, context);
         return startServer(params, context);