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.provider;
25 import com.google.common.util.concurrent.Futures;
26 import org.json.JSONObject;
27 import org.opendaylight.controller.md.sal.binding.api.DataBroker;
28 import org.opendaylight.controller.md.sal.binding.api.DataChangeListener;
29 import org.opendaylight.controller.sal.binding.api.BindingAwareBroker;
30 import org.opendaylight.controller.sal.binding.api.NotificationProviderService;
31 import org.opendaylight.controller.sal.binding.api.RpcProviderRegistry;
32 import org.opendaylight.yang.gen.v1.org.openecomp.appc.rev160104.*;
33 import org.opendaylight.yang.gen.v1.org.openecomp.appc.rev160104.common.request.header.CommonRequestHeader;
34 import org.opendaylight.yang.gen.v1.org.openecomp.appc.rev160104.responseattributes.StatusBuilder;
35 import org.opendaylight.yang.gen.v1.org.openecomp.appc.rev160104.responseheader.ResponseHeaderBuilder;
36 import org.opendaylight.yang.gen.v1.org.openecomp.appc.rev160104.vnf.resource.VnfResource;
37 import org.opendaylight.yang.gen.v1.org.openecomp.appc.rev160104.config.payload.ConfigPayload;
38 import org.opendaylight.yangtools.concepts.ListenerRegistration;
39 import org.opendaylight.yangtools.yang.common.RpcResult;
40 import org.opendaylight.yangtools.yang.common.RpcResultBuilder;
41 import org.openecomp.appc.Constants;
42 import org.openecomp.appc.configuration.Configuration;
43 import org.openecomp.appc.configuration.ConfigurationFactory;
44 import org.openecomp.appc.executor.objects.LCMCommandStatus;
45 import org.openecomp.appc.executor.objects.Params;
46 import org.openecomp.appc.i18n.Msg;
47 import org.openecomp.appc.provider.lcm.util.RequestInputBuilder;
48 import org.openecomp.appc.provider.lcm.util.ValidationService;
49 import org.openecomp.appc.provider.topology.TopologyService;
50 import org.openecomp.appc.requesthandler.RequestHandler;
51 import org.openecomp.appc.requesthandler.objects.RequestHandlerInput;
52 import org.openecomp.appc.requesthandler.objects.RequestHandlerOutput;
53 import com.att.eelf.configuration.EELFLogger;
54 import com.att.eelf.configuration.EELFManager;
55 import com.att.eelf.i18n.EELFResourceManager;
56 import org.osgi.framework.BundleContext;
57 import org.osgi.framework.FrameworkUtil;
58 import org.osgi.framework.ServiceReference;
59 import org.opendaylight.yang.gen.v1.org.openecomp.appc.rev160104.status.Status;
60 import org.opendaylight.yang.gen.v1.org.openecomp.appc.rev160104.Action;
62 import java.text.DateFormat;
63 import java.text.ParseException;
64 import java.text.SimpleDateFormat;
65 import java.util.Date;
66 import java.util.Iterator;
67 import java.util.Properties;
68 import java.util.TimeZone;
69 import java.util.concurrent.ExecutorService;
70 import java.util.concurrent.Executors;
71 import java.util.concurrent.Future;
73 /* ADDED FOR FUSION SERVICE CODE */
75 @SuppressWarnings("JavaDoc")
77 * Defines the APPC service provider.
79 * The rpc definition in the YANG model is shown below. This model is used to generate code to manage the inputs and
80 * outputs of the RPC service. For example, the input is defined by a class named {@link ConfigurationOperationInput},
81 * which is generated from the name of the RPC and the "input" definition of the RPC. This class encapsulates the
82 * various objects that are passed to the RPC and is used to obtain values from the input parameters.
85 * Likewise, the outputs are defined by a class named {@link ConfigurationOperationOutput}. This class encapsulates the
86 * defined outputs. To make construction of the outputs easier, there are also generated builder classes that are named
87 * for the various elements of the output they "build", such as {@link ConfigurationResponseBuilder}.
91 * rpc configuration-operation {
92 * description "An operation to view, change, or audit the configuration of a VM";
94 * uses configuration-request-header;
95 * uses configuration-request;
98 * uses common-response-header;
99 * uses configuration-response;
105 public class AppcProvider implements AutoCloseable, AppcProviderService {
107 private final EELFLogger logger = EELFManager.getInstance().getLogger(AppcProviderClient.class);
109 private final ExecutorService executor;
111 private ListenerRegistration<DataChangeListener> dclServices;
114 * The ODL data store broker. Provides access to a conceptual data tree store and also provides the ability to
115 * subscribe for changes to data under a given branch of the tree.
117 protected DataBroker dataBroker;
120 * ODL Notification Service that provides publish/subscribe capabilities for YANG modeled notifications.
122 protected NotificationProviderService notificationService;
125 * Provides a registry for Remote Procedure Call (RPC) service implementations. The RPCs are defined in YANG models.
127 protected RpcProviderRegistry rpcRegistry;
130 * Represents our RPC implementation registration
132 protected BindingAwareBroker.RpcRegistration<AppcProviderService> rpcRegistration;
137 private Configuration configuration = ConfigurationFactory.getConfiguration();
141 * @param notificationProviderService
142 * @param rpcProviderRegistry
147 public AppcProvider(DataBroker dataBroker2, NotificationProviderService notificationProviderService,
148 RpcProviderRegistry rpcProviderRegistry) {
150 String appName = configuration.getProperty(Constants.PROPERTY_APPLICATION_NAME);
151 logger.info(Msg.COMPONENT_INITIALIZING, appName, "provider");
153 executor = Executors.newFixedThreadPool(1);
154 dataBroker = dataBroker2;
155 notificationService = notificationProviderService;
156 rpcRegistry = rpcProviderRegistry;
158 if (rpcRegistry != null) {
159 rpcRegistration = rpcRegistry.addRpcImplementation(AppcProviderService.class, this);
162 logger.info(Msg.COMPONENT_INITIALIZED, appName, "provider");
166 * Implements the close of the service
168 * @see java.lang.AutoCloseable#close()
170 @SuppressWarnings("nls")
172 public void close() throws Exception {
173 String appName = configuration.getProperty(Constants.PROPERTY_APPLICATION_NAME);
174 logger.info(Msg.COMPONENT_TERMINATING, appName, "provider");
176 if (rpcRegistration != null) {
177 rpcRegistration.close();
179 logger.info(Msg.COMPONENT_TERMINATED, appName, "provider");
183 public Future<RpcResult<ModifyConfigOutput>> modifyConfig(ModifyConfigInput input){
184 CommonRequestHeader hdr = input.getCommonRequestHeader();
185 ConfigPayload data = input.getConfigPayload();
186 TopologyService topology = new TopologyService(this);
187 RpcResult<ModifyConfigOutput> result = topology.modifyConfig(hdr, data);
188 return Futures.immediateFuture(result);
191 * Rebuilds a specific VNF
193 * @see org.opendaylight.yang.gen.v1.org.openecomp.appc.rev160104.AppcProviderService#rebuild(org.opendaylight.yang.gen.v1.org.openecomp.appc.rev160104.RebuildInput)
196 public Future<RpcResult<RebuildOutput>> rebuild(RebuildInput input) {
198 CommonRequestHeader hdr = input.getCommonRequestHeader();
199 VnfResource vnf = input.getVnfResource();
201 TopologyService topology = new TopologyService(this);
202 RpcResult<RebuildOutput> result = topology.rebuild(hdr, vnf);
203 return Futures.immediateFuture(result);
207 * Restarts a specific VNF
209 * @see org.opendaylight.yang.gen.v1.org.openecomp.appc.rev160104.AppcProviderService#restart(org.opendaylight.yang.gen.v1.org.openecomp.appc.rev160104.RestartInput)
212 public Future<RpcResult<RestartOutput>> restart(RestartInput input) {
213 CommonRequestHeader hdr = input.getCommonRequestHeader();
214 VnfResource vnf = input.getVnfResource();
216 TopologyService topology = new TopologyService(this);
217 RpcResult<RestartOutput> result = topology.restart(hdr, vnf);
218 return Futures.immediateFuture(result);
222 * Migrates a specific VNF
224 * @see org.opendaylight.yang.gen.v1.org.openecomp.appc.rev160104.AppcProviderService#migrate(org.opendaylight.yang.gen.v1.org.openecomp.appc.rev160104.MigrateInput)
227 public Future<RpcResult<MigrateOutput>> migrate(MigrateInput input) {
228 CommonRequestHeader hdr = input.getCommonRequestHeader();
229 VnfResource vnf = input.getVnfResource();
231 TopologyService topology = new TopologyService(this);
232 RpcResult<MigrateOutput> result = topology.migrate(hdr, vnf);
233 return Futures.immediateFuture(result);
237 * Evacuates a specific VNF
239 * @see org.opendaylight.yang.gen.v1.org.openecomp.appc.rev160104.AppcProviderService#evacuate(org.opendaylight.yang.gen.v1.org.openecomp.appc.rev160104.EvacuateInput)
242 public Future<RpcResult<EvacuateOutput>> evacuate(EvacuateInput input) {
243 CommonRequestHeader hdr = input.getCommonRequestHeader();
244 VnfResource vnf = input.getVnfResource();
246 TopologyService topology = new TopologyService(this);
251 * Evacuates a specific VNF
253 * @see org.opendaylight.yang.gen.v1.org.openecomp.appc.rev160104.AppcProviderService#evacuate(org.opendaylight.yang.gen.v1.org.openecomp.appc.rev160104.EvacuateInput)
256 public Future<RpcResult<SnapshotOutput>> snapshot(SnapshotInput input) {
257 CommonRequestHeader hdr = input.getCommonRequestHeader();
258 VnfResource vnf = input.getVnfResource();
260 TopologyService topology = new TopologyService(this);
261 RpcResult<SnapshotOutput> result = topology.snapshot(hdr, vnf);
262 return Futures.immediateFuture(result);
267 * Checks status of a VM
270 public Future<RpcResult<VmstatuscheckOutput>> vmstatuscheck(VmstatuscheckInput input) {
271 CommonRequestHeader hdr = input.getCommonRequestHeader();
272 VnfResource vnf = input.getVnfResource();
274 TopologyService topology = new TopologyService(this);
275 RpcResult<VmstatuscheckOutput> result = topology.vmstatuscheck(hdr, vnf);
276 return Futures.immediateFuture(result);