2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017 AT&T Intellectual Property. All rights
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=========================================================
22 package org.openecomp.appc.provider;
24 import com.google.common.util.concurrent.Futures;
25 import org.json.JSONObject;
26 import org.opendaylight.controller.md.sal.binding.api.DataBroker;
27 import org.opendaylight.controller.md.sal.binding.api.DataChangeListener;
28 import org.opendaylight.controller.sal.binding.api.BindingAwareBroker;
29 import org.opendaylight.controller.sal.binding.api.NotificationProviderService;
30 import org.opendaylight.controller.sal.binding.api.RpcProviderRegistry;
31 import org.opendaylight.yang.gen.v1.org.openecomp.appc.rev160104.*;
32 import org.opendaylight.yang.gen.v1.org.openecomp.appc.rev160104.common.request.header.CommonRequestHeader;
33 import org.opendaylight.yang.gen.v1.org.openecomp.appc.rev160104.responseattributes.StatusBuilder;
34 import org.opendaylight.yang.gen.v1.org.openecomp.appc.rev160104.responseheader.ResponseHeaderBuilder;
35 import org.opendaylight.yang.gen.v1.org.openecomp.appc.rev160104.vnf.resource.VnfResource;
36 import org.opendaylight.yang.gen.v1.org.openecomp.appc.rev160104.config.payload.ConfigPayload;
37 import org.opendaylight.yangtools.concepts.ListenerRegistration;
38 import org.opendaylight.yangtools.yang.common.RpcResult;
39 import org.opendaylight.yangtools.yang.common.RpcResultBuilder;
40 import org.openecomp.appc.Constants;
41 import org.openecomp.appc.configuration.Configuration;
42 import org.openecomp.appc.configuration.ConfigurationFactory;
43 import org.openecomp.appc.executor.objects.LCMCommandStatus;
44 import org.openecomp.appc.executor.objects.Params;
45 import org.openecomp.appc.i18n.Msg;
46 import org.openecomp.appc.provider.lcm.util.RequestInputBuilder;
47 import org.openecomp.appc.provider.lcm.util.ValidationService;
48 import org.openecomp.appc.provider.topology.TopologyService;
49 import org.openecomp.appc.requesthandler.RequestHandler;
50 import org.openecomp.appc.requesthandler.objects.RequestHandlerInput;
51 import org.openecomp.appc.requesthandler.objects.RequestHandlerOutput;
52 import com.att.eelf.configuration.EELFLogger;
53 import com.att.eelf.configuration.EELFManager;
54 import com.att.eelf.i18n.EELFResourceManager;
55 import org.osgi.framework.BundleContext;
56 import org.osgi.framework.FrameworkUtil;
57 import org.osgi.framework.ServiceReference;
58 import org.opendaylight.yang.gen.v1.org.openecomp.appc.rev160104.status.Status;
59 import org.opendaylight.yang.gen.v1.org.openecomp.appc.rev160104.Action;
61 import java.text.DateFormat;
62 import java.text.ParseException;
63 import java.text.SimpleDateFormat;
64 import java.util.Date;
65 import java.util.Iterator;
66 import java.util.Properties;
67 import java.util.TimeZone;
68 import java.util.concurrent.ExecutorService;
69 import java.util.concurrent.Executors;
70 import java.util.concurrent.Future;
72 /* ADDED FOR FUSION SERVICE CODE */
74 @SuppressWarnings("JavaDoc")
76 * Defines the APPC service provider.
78 * The rpc definition in the YANG model is shown below. This model is used to generate code to manage the inputs and
79 * outputs of the RPC service. For example, the input is defined by a class named {@link ConfigurationOperationInput},
80 * which is generated from the name of the RPC and the "input" definition of the RPC. This class encapsulates the
81 * various objects that are passed to the RPC and is used to obtain values from the input parameters.
84 * Likewise, the outputs are defined by a class named {@link ConfigurationOperationOutput}. This class encapsulates the
85 * defined outputs. To make construction of the outputs easier, there are also generated builder classes that are named
86 * for the various elements of the output they "build", such as {@link ConfigurationResponseBuilder}.
90 * rpc configuration-operation {
91 * description "An operation to view, change, or audit the configuration of a VM";
93 * uses configuration-request-header;
94 * uses configuration-request;
97 * uses common-response-header;
98 * uses configuration-response;
104 public class AppcProvider implements AutoCloseable, AppcProviderService {
106 private final EELFLogger logger = EELFManager.getInstance().getLogger(AppcProviderClient.class);
108 private final ExecutorService executor;
110 private ListenerRegistration<DataChangeListener> dclServices;
113 * The ODL data store broker. Provides access to a conceptual data tree store and also provides the ability to
114 * subscribe for changes to data under a given branch of the tree.
116 protected DataBroker dataBroker;
119 * ODL Notification Service that provides publish/subscribe capabilities for YANG modeled notifications.
121 protected NotificationProviderService notificationService;
124 * Provides a registry for Remote Procedure Call (RPC) service implementations. The RPCs are defined in YANG models.
126 protected RpcProviderRegistry rpcRegistry;
129 * Represents our RPC implementation registration
131 protected BindingAwareBroker.RpcRegistration<AppcProviderService> rpcRegistration;
136 private Configuration configuration = ConfigurationFactory.getConfiguration();
140 * @param notificationProviderService
141 * @param rpcProviderRegistry
146 public AppcProvider(DataBroker dataBroker2, NotificationProviderService notificationProviderService,
147 RpcProviderRegistry rpcProviderRegistry) {
149 String appName = configuration.getProperty(Constants.PROPERTY_APPLICATION_NAME);
150 logger.info(Msg.COMPONENT_INITIALIZING, appName, "provider");
152 executor = Executors.newFixedThreadPool(1);
153 dataBroker = dataBroker2;
154 notificationService = notificationProviderService;
155 rpcRegistry = rpcProviderRegistry;
157 if (rpcRegistry != null) {
158 logger.info("rpcRegistry was not null");
159 rpcRegistration = rpcRegistry.addRpcImplementation(AppcProviderService.class, this);
161 logger.error("rpcRegistry WAS NULL");
164 logger.info(Msg.COMPONENT_INITIALIZED, appName, "provider");
168 * Implements the close of the service
170 * @see java.lang.AutoCloseable#close()
172 @SuppressWarnings("nls")
174 public void close() throws Exception {
175 String appName = configuration.getProperty(Constants.PROPERTY_APPLICATION_NAME);
176 logger.info(Msg.COMPONENT_TERMINATING, appName, "provider");
178 if (rpcRegistration != null) {
179 rpcRegistration.close();
181 logger.info(Msg.COMPONENT_TERMINATED, appName, "provider");
185 public Future<RpcResult<ModifyConfigOutput>> modifyConfig(ModifyConfigInput input){
186 CommonRequestHeader hdr = input.getCommonRequestHeader();
187 ConfigPayload data = input.getConfigPayload();
188 TopologyService topology = new TopologyService(this);
189 RpcResult<ModifyConfigOutput> result = topology.modifyConfig(hdr, data);
190 return Futures.immediateFuture(result);
193 * Rebuilds a specific VNF
195 * @see org.opendaylight.yang.gen.v1.org.openecomp.appc.rev160104.AppcProviderService#rebuild(org.opendaylight.yang.gen.v1.org.openecomp.appc.rev160104.RebuildInput)
198 public Future<RpcResult<RebuildOutput>> rebuild(RebuildInput input) {
200 CommonRequestHeader hdr = input.getCommonRequestHeader();
201 VnfResource vnf = input.getVnfResource();
203 TopologyService topology = new TopologyService(this);
204 RpcResult<RebuildOutput> result = topology.rebuild(hdr, vnf);
205 return Futures.immediateFuture(result);
209 * Restarts a specific VNF
211 * @see org.opendaylight.yang.gen.v1.org.openecomp.appc.rev160104.AppcProviderService#restart(org.opendaylight.yang.gen.v1.org.openecomp.appc.rev160104.RestartInput)
214 public Future<RpcResult<RestartOutput>> restart(RestartInput input) {
215 CommonRequestHeader hdr = input.getCommonRequestHeader();
216 VnfResource vnf = input.getVnfResource();
218 TopologyService topology = new TopologyService(this);
219 RpcResult<RestartOutput> result = topology.restart(hdr, vnf);
220 return Futures.immediateFuture(result);
224 * Migrates a specific VNF
226 * @see org.opendaylight.yang.gen.v1.org.openecomp.appc.rev160104.AppcProviderService#migrate(org.opendaylight.yang.gen.v1.org.openecomp.appc.rev160104.MigrateInput)
229 public Future<RpcResult<MigrateOutput>> migrate(MigrateInput input) {
230 CommonRequestHeader hdr = input.getCommonRequestHeader();
231 VnfResource vnf = input.getVnfResource();
233 TopologyService topology = new TopologyService(this);
234 RpcResult<MigrateOutput> result = topology.migrate(hdr, vnf);
235 return Futures.immediateFuture(result);
239 * Evacuates a specific VNF
241 * @see org.opendaylight.yang.gen.v1.org.openecomp.appc.rev160104.AppcProviderService#evacuate(org.opendaylight.yang.gen.v1.org.openecomp.appc.rev160104.EvacuateInput)
244 public Future<RpcResult<EvacuateOutput>> evacuate(EvacuateInput input) {
245 CommonRequestHeader hdr = input.getCommonRequestHeader();
246 VnfResource vnf = input.getVnfResource();
248 TopologyService topology = new TopologyService(this);
253 * Evacuates a specific VNF
255 * @see org.opendaylight.yang.gen.v1.org.openecomp.appc.rev160104.AppcProviderService#evacuate(org.opendaylight.yang.gen.v1.org.openecomp.appc.rev160104.EvacuateInput)
258 public Future<RpcResult<SnapshotOutput>> snapshot(SnapshotInput input) {
259 CommonRequestHeader hdr = input.getCommonRequestHeader();
260 VnfResource vnf = input.getVnfResource();
262 TopologyService topology = new TopologyService(this);
263 RpcResult<SnapshotOutput> result = topology.snapshot(hdr, vnf);
264 return Futures.immediateFuture(result);