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 com.att.cdp.exceptions.ResourceNotFoundException;
28 import com.att.cdp.zones.Context;
29 import com.att.cdp.zones.model.ModelObject;
30 import com.att.cdp.zones.model.Server;
31 import com.att.eelf.configuration.EELFLogger;
32 import com.att.eelf.configuration.EELFManager;
33 import com.att.eelf.i18n.EELFResourceManager;
34 import org.glassfish.grizzly.http.util.HttpStatus;
35 import org.openecomp.appc.Constants;
36 import org.openecomp.appc.adapter.iaas.ProviderAdapter;
37 import org.openecomp.appc.adapter.iaas.impl.IdentityURL;
38 import org.openecomp.appc.adapter.iaas.impl.RequestContext;
39 import org.openecomp.appc.adapter.iaas.impl.RequestFailedException;
40 import org.openecomp.appc.adapter.iaas.impl.VMURL;
41 import org.openecomp.appc.adapter.iaas.provider.operation.common.enums.Operation;
42 import org.openecomp.appc.adapter.iaas.provider.operation.common.enums.Outcome;
43 import org.openecomp.appc.adapter.iaas.provider.operation.impl.base.ProviderServerOperation;
44 import org.openecomp.appc.configuration.Configuration;
45 import org.openecomp.appc.configuration.ConfigurationFactory;
46 import org.openecomp.appc.exceptions.UnknownProviderException;
47 import org.openecomp.appc.i18n.Msg;
48 import org.openecomp.sdnc.sli.SvcLogicContext;
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;
55 public class VmStatuschecker extends ProviderServerOperation {
57 private static final EELFLogger logger = EELFManager.getInstance().getLogger(VmStatuschecker.class);
58 private static final Configuration configuration = ConfigurationFactory.getConfiguration();
61 * to check the status of the VM
63 public Server vmStatuschecker(Map<String, String> params, SvcLogicContext ctx)
64 throws UnknownProviderException, IllegalArgumentException {
66 RequestContext rc = new RequestContext(ctx);
69 String appName = configuration.getProperty(Constants.PROPERTY_APPLICATION_NAME);
72 validateParametersExist(params, ProviderAdapter.PROPERTY_INSTANCE_URL,
73 ProviderAdapter.PROPERTY_PROVIDER_NAME);
75 String vm_url = params.get(ProviderAdapter.PROPERTY_INSTANCE_URL);
77 VMURL vm = VMURL.parseURL(vm_url);
78 if (validateVM(rc, appName, vm_url, vm)) return null;
80 IdentityURL ident = IdentityURL.parseURL(params.get(ProviderAdapter.PROPERTY_IDENTITY_URL));
81 String identStr = (ident == null) ? null : ident.toString();
83 Context context = null;
85 context = getContext(rc, vm_url, identStr);
86 if (context != null) {
87 server = lookupServer(rc, context, vm.getServerId());
88 logger.debug(Msg.SERVER_FOUND, vm_url, context.getTenantName(), server.getStatus().toString());
91 switch (server.getStatus()) {
113 statusvm = "suspended";
117 statusvm = "pending";
121 statusvm = "default-unknown state-should never occur";
126 String statusofVM = statusvm;
128 SvcLogicContext svcLogic = rc.getSvcLogicContext();
129 svcLogic.setStatus(Outcome.SUCCESS.toString());
130 svcLogic.setAttribute("org.openecomp.statusofvm", statusofVM);
131 svcLogic.setAttribute(Constants.STATUS_OF_VM, statusofVM);
132 svcLogic.setAttribute(Constants.ATTRIBUTE_ERROR_CODE,
133 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 (Exception e1) {
140 String msg = EELFResourceManager.format(Msg.SERVER_OPERATION_EXCEPTION,
141 e1, e1.getClass().getSimpleName(), RESTART_SERVICE.toString(),
142 vm_url, context == null ? "Unknown" : context.getTenantName());
143 logger.error(msg, e1);
144 doFailure(rc, HttpStatus.INTERNAL_SERVER_ERROR_500, msg);
146 } catch (RequestFailedException e) {
147 doFailure(rc, e.getStatus(), e.getMessage());
154 protected ModelObject executeProviderOperation(Map<String, String> params, SvcLogicContext context)
155 throws UnknownProviderException {
156 setMDC(Operation.VMSTATUSCHECK_SERVICE.toString(), "App-C IaaS Adapter:VmStatusCheck", ADAPTER_NAME);
157 logOperation(Msg.CHECKING_SERVER, params, context);
158 return vmStatuschecker(params, context);