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.RequestContext;
30 import org.openecomp.appc.adapter.iaas.impl.RequestFailedException;
31 import org.openecomp.appc.adapter.iaas.impl.VMURL;
32 import org.openecomp.appc.adapter.iaas.provider.operation.common.enums.Operation;
33 import org.openecomp.appc.adapter.iaas.provider.operation.impl.base.ProviderServerOperation;
34 import org.openecomp.appc.configuration.Configuration;
35 import org.openecomp.appc.configuration.ConfigurationFactory;
36 import org.openecomp.appc.exceptions.APPCException;
37 import org.openecomp.appc.i18n.Msg;
38 import com.att.cdp.exceptions.ZoneException;
39 import com.att.cdp.zones.Context;
40 import com.att.cdp.zones.model.ModelObject;
41 import com.att.cdp.zones.model.Server;
42 import com.att.eelf.configuration.EELFLogger;
43 import com.att.eelf.configuration.EELFManager;
44 import com.att.eelf.i18n.EELFResourceManager;
45 import org.onap.ccsdk.sli.core.sli.SvcLogicContext;
46 import org.glassfish.grizzly.http.util.HttpStatus;
48 import java.io.IOException;
51 import static org.openecomp.appc.adapter.utils.Constants.ADAPTER_NAME;
53 public class LookupServer extends ProviderServerOperation {
55 private static final EELFLogger logger = EELFManager.getInstance().getLogger(EvacuateServer.class);
56 private static final Configuration configuration = ConfigurationFactory.getConfiguration();
59 public Server lookupServer(Map<String, String> params, SvcLogicContext ctx) throws APPCException {
61 RequestContext rc = new RequestContext(ctx);
62 rc.isAlive(); //should we test the return and fail if false?
67 validateParametersExist(params, ProviderAdapter.PROPERTY_INSTANCE_URL,
68 ProviderAdapter.PROPERTY_PROVIDER_NAME);
70 String appName = configuration.getProperty(Constants.PROPERTY_APPLICATION_NAME);
71 vm_url = params.get(ProviderAdapter.PROPERTY_INSTANCE_URL);
72 VMURL vm = VMURL.parseURL(vm_url);
73 if (validateVM(rc, appName, vm_url, vm)) {
77 //use try with resource to ensure context is closed (returned to pool)
78 try (Context context = resolveContext(rc, params, appName, vm_url)) {
79 //resloveContext & getContext call doFailure and log errors before returning null
82 server = lookupServer(rc, context, vm.getServerId());
83 logger.debug(Msg.SERVER_FOUND, vm_url, context.getTenantName(), server.getStatus().toString());
84 ctx.setAttribute("serverFound", "success");
86 EELFResourceManager.format(Msg.SUCCESS_EVENT_MESSAGE, "LookupServer", vm_url);
87 ctx.setAttribute(org.openecomp.appc.Constants.ATTRIBUTE_SUCCESS_MESSAGE, msg);
90 } catch (ZoneException e) {
92 String msg = EELFResourceManager.format(Msg.SERVER_NOT_FOUND, e, vm_url);
94 doFailure(rc, HttpStatus.NOT_FOUND_404, msg);
95 ctx.setAttribute("serverFound", "failure");
96 } catch (IOException e) {
97 //exception closing context
98 String msg = EELFResourceManager.format(Msg.CLOSE_CONTEXT_FAILED, e, vm_url);
100 } catch (Exception e1) {
101 String msg = EELFResourceManager.format(Msg.SERVER_OPERATION_EXCEPTION,
102 e1, e1.getClass().getSimpleName(),
103 Operation.LOOKUP_SERVICE.toString(), vm_url, "Unknown" );
104 logger.error(msg, e1);
105 doFailure(rc, HttpStatus.INTERNAL_SERVER_ERROR_500, msg);
108 } catch (RequestFailedException e) {
109 // parameters not valid, unable to connect to provider
110 String msg = EELFResourceManager.format(Msg.SERVER_NOT_FOUND, e, vm_url);
112 doFailure(rc, HttpStatus.NOT_FOUND_404, msg);
113 ctx.setAttribute("serverFound", "failure");
119 protected ModelObject executeProviderOperation(Map<String, String> params, SvcLogicContext context)
120 throws APPCException {
121 setMDC(Operation.LOOKUP_SERVICE.toString(), "App-C IaaS Adapter:LookupServer", ADAPTER_NAME);
122 logOperation(Msg.LOOKING_SERVER_UP, params, context);
123 return lookupServer(params, context);