2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
6 * Copyright (C) 2017 Amdocs
7 * ================================================================================
8 * Licensed under the Apache License, Version 2.0 (the "License");
9 * you may not use this file except in compliance with the License.
10 * You may obtain a copy of the License at
12 * http://www.apache.org/licenses/LICENSE-2.0
14 * Unless required by applicable law or agreed to in writing, software
15 * distributed under the License is distributed on an "AS IS" BASIS,
16 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 * See the License for the specific language governing permissions and
18 * limitations under the License.
19 * ============LICENSE_END=========================================================
20 * ECOMP is a trademark and service mark of AT&T Intellectual Property.
23 package org.openecomp.appc.adapter.iaas.provider.operation.impl;
25 import org.openecomp.appc.Constants;
26 import org.openecomp.appc.adapter.iaas.ProviderAdapter;
27 import org.openecomp.appc.adapter.iaas.impl.IdentityURL;
28 import org.openecomp.appc.adapter.iaas.impl.RequestContext;
29 import org.openecomp.appc.adapter.iaas.impl.RequestFailedException;
30 import org.openecomp.appc.adapter.iaas.impl.VMURL;
31 import org.openecomp.appc.adapter.iaas.provider.operation.common.enums.Operation;
32 import org.openecomp.appc.adapter.iaas.provider.operation.common.enums.Outcome;
33 import org.openecomp.appc.adapter.iaas.provider.operation.impl.base.ProviderOperation;
34 import org.openecomp.appc.adapter.iaas.provider.operation.impl.base.ProviderServerOperation;
35 import org.openecomp.appc.configuration.Configuration;
36 import org.openecomp.appc.configuration.ConfigurationFactory;
37 import org.openecomp.appc.exceptions.UnknownProviderException;
38 import org.openecomp.appc.i18n.Msg;
39 import com.att.cdp.exceptions.ResourceNotFoundException;
40 import com.att.cdp.zones.Context;
41 import com.att.cdp.zones.model.ModelObject;
42 import com.att.cdp.zones.model.Server;
43 import com.att.eelf.configuration.EELFLogger;
44 import com.att.eelf.configuration.EELFManager;
45 import com.att.eelf.i18n.EELFResourceManager;
46 import org.openecomp.sdnc.sli.SvcLogicContext;
47 import org.glassfish.grizzly.http.util.HttpStatus;
52 import static org.openecomp.appc.adapter.iaas.provider.operation.common.enums.Operation.RESTART_SERVICE;
53 import static org.openecomp.appc.adapter.utils.Constants.ADAPTER_NAME;
54 import static com.att.eelf.configuration.Configuration.MDC_SERVICE_NAME;
57 public class VmStatuschecker extends ProviderServerOperation {
59 private static final EELFLogger logger = EELFManager.getInstance().getLogger(VmStatuschecker.class);
60 private static final Configuration configuration = ConfigurationFactory.getConfiguration();
62 /* *********************************************************************************/
63 /* DEVEN PANCHAL: This method is used to check the status of the VM */
64 /**********************************************************************************/
65 public Server vmStatuschecker(Map<String, String> params, SvcLogicContext ctx) throws UnknownProviderException, IllegalArgumentException {
67 RequestContext rc = new RequestContext(ctx);
70 String appName = configuration.getProperty(Constants.PROPERTY_APPLICATION_NAME);
73 validateParametersExist(params, ProviderAdapter.PROPERTY_INSTANCE_URL,
74 ProviderAdapter.PROPERTY_PROVIDER_NAME);
76 String vm_url = params.get(ProviderAdapter.PROPERTY_INSTANCE_URL);
78 VMURL vm = VMURL.parseURL(vm_url);
79 if (validateVM(rc, appName, vm_url, vm)) return null;
81 IdentityURL ident = IdentityURL.parseURL(params.get(ProviderAdapter.PROPERTY_IDENTITY_URL));
82 String identStr = (ident == null) ? null : ident.toString();
84 Context context = null;
86 context = getContext(rc, vm_url, identStr);
87 if (context != null) {
88 server = lookupServer(rc, context, vm.getServerId());
89 logger.debug(Msg.SERVER_FOUND, vm_url, context.getTenantName(), server.getStatus().toString());
92 switch (server.getStatus()) {
114 statusvm = "suspended";
118 statusvm = "pending";
122 statusvm = "default-unknown state-should never occur";
127 String statusofVM = statusvm;
129 SvcLogicContext svcLogic = rc.getSvcLogicContext();
130 svcLogic.setStatus(Outcome.SUCCESS.toString());
131 svcLogic.setAttribute("org.openecomp.statusofvm", statusofVM);
132 svcLogic.setAttribute(Constants.STATUS_OF_VM, statusofVM);
133 svcLogic.setAttribute(Constants.ATTRIBUTE_ERROR_CODE, Integer.toString(HttpStatus.OK_200.getStatusCode()));
135 } catch (ResourceNotFoundException e) {
136 String msg = EELFResourceManager.format(Msg.SERVER_NOT_FOUND, e, vm_url);
138 doFailure(rc, HttpStatus.NOT_FOUND_404, msg);
139 } catch (Throwable t) {
140 String msg = EELFResourceManager.format(Msg.SERVER_OPERATION_EXCEPTION, t, t.getClass().getSimpleName(),
141 RESTART_SERVICE.toString(), vm_url, context == null ? "Unknown" : context.getTenantName());
142 logger.error(msg, t);
143 doFailure(rc, HttpStatus.INTERNAL_SERVER_ERROR_500, msg);
145 } catch (RequestFailedException e) {
146 doFailure(rc, e.getStatus(), e.getMessage());
152 /* *********************************************************************************/
155 protected ModelObject executeProviderOperation(Map<String, String> params, SvcLogicContext context) throws UnknownProviderException {
157 setMDC(Operation.VMSTATUSCHECK_SERVICE.toString(), "App-C IaaS Adapter:VmStatusCheck", ADAPTER_NAME);
158 logOperation(Msg.CHECKING_SERVER, params, context);
159 return vmStatuschecker(params, context);