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