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.provider;
27 import com.att.eelf.configuration.EELFLogger;
28 import com.att.eelf.configuration.EELFManager;
29 import com.google.common.util.concurrent.Futures;
30 import org.opendaylight.controller.md.sal.binding.api.DataBroker;
31 import org.opendaylight.controller.sal.binding.api.BindingAwareBroker;
32 import org.opendaylight.controller.sal.binding.api.NotificationProviderService;
33 import org.opendaylight.controller.sal.binding.api.RpcProviderRegistry;
34 import org.opendaylight.yang.gen.v1.org.openecomp.appc.rev160104.AppcProviderService;
35 import org.opendaylight.yang.gen.v1.org.openecomp.appc.rev160104.EvacuateInput;
36 import org.opendaylight.yang.gen.v1.org.openecomp.appc.rev160104.EvacuateOutput;
37 import org.opendaylight.yang.gen.v1.org.openecomp.appc.rev160104.MigrateInput;
38 import org.opendaylight.yang.gen.v1.org.openecomp.appc.rev160104.MigrateOutput;
39 import org.opendaylight.yang.gen.v1.org.openecomp.appc.rev160104.ModifyConfigInput;
40 import org.opendaylight.yang.gen.v1.org.openecomp.appc.rev160104.ModifyConfigOutput;
41 import org.opendaylight.yang.gen.v1.org.openecomp.appc.rev160104.RebuildInput;
42 import org.opendaylight.yang.gen.v1.org.openecomp.appc.rev160104.RebuildOutput;
43 import org.opendaylight.yang.gen.v1.org.openecomp.appc.rev160104.RestartInput;
44 import org.opendaylight.yang.gen.v1.org.openecomp.appc.rev160104.RestartOutput;
45 import org.opendaylight.yang.gen.v1.org.openecomp.appc.rev160104.SnapshotInput;
46 import org.opendaylight.yang.gen.v1.org.openecomp.appc.rev160104.SnapshotOutput;
47 import org.opendaylight.yang.gen.v1.org.openecomp.appc.rev160104.VmstatuscheckInput;
48 import org.opendaylight.yang.gen.v1.org.openecomp.appc.rev160104.VmstatuscheckOutput;
49 import org.opendaylight.yang.gen.v1.org.openecomp.appc.rev160104.common.request.header.CommonRequestHeader;
50 import org.opendaylight.yang.gen.v1.org.openecomp.appc.rev160104.config.payload.ConfigPayload;
51 import org.opendaylight.yang.gen.v1.org.openecomp.appc.rev160104.vnf.resource.VnfResource;
52 import org.opendaylight.yangtools.yang.common.RpcResult;
53 import org.openecomp.appc.Constants;
54 import org.openecomp.appc.configuration.Configuration;
55 import org.openecomp.appc.configuration.ConfigurationFactory;
56 import org.openecomp.appc.i18n.Msg;
57 import org.openecomp.appc.provider.topology.TopologyService;
59 import java.util.concurrent.ExecutorService;
60 import java.util.concurrent.Executors;
61 import java.util.concurrent.Future;
63 /* ADDED FOR FUSION SERVICE CODE */
65 @SuppressWarnings("JavaDoc")
67 * Defines the APPC service provider.
69 * The rpc definition in the YANG model is shown below. This model is used to generate code to manage the inputs and
70 * outputs of the RPC service. For example, the input is defined by a class named {@link ConfigurationOperationInput},
71 * which is generated from the name of the RPC and the "input" definition of the RPC. This class encapsulates the
72 * various objects that are passed to the RPC and is used to obtain values from the input parameters.
75 * Likewise, the outputs are defined by a class named {@link ConfigurationOperationOutput}. This class encapsulates the
76 * defined outputs. To make construction of the outputs easier, there are also generated builder classes that are named
77 * for the various elements of the output they "build", such as {@link ConfigurationResponseBuilder}.
81 * rpc configuration-operation {
82 * description "An operation to view, change, or audit the configuration of a VM";
84 * uses configuration-request-header;
85 * uses configuration-request;
88 * uses common-response-header;
89 * uses configuration-response;
95 public class AppcProvider implements AutoCloseable, AppcProviderService {
97 private final EELFLogger logger = EELFManager.getInstance().getLogger(AppcProviderClient.class);
99 private final ExecutorService executor;
102 * The ODL data store broker. Provides access to a conceptual data tree store and also provides the ability to
103 * subscribe for changes to data under a given branch of the tree.
105 protected DataBroker dataBroker;
108 * ODL Notification Service that provides publish/subscribe capabilities for YANG modeled notifications.
110 protected NotificationProviderService notificationService;
113 * Provides a registry for Remote Procedure Call (RPC) service implementations. The RPCs are defined in YANG models.
115 protected RpcProviderRegistry rpcRegistry;
118 * Represents our RPC implementation registration
120 protected BindingAwareBroker.RpcRegistration<AppcProviderService> rpcRegistration;
125 private Configuration configuration = ConfigurationFactory.getConfiguration();
129 * @param notificationProviderService
130 * @param rpcProviderRegistry
135 public AppcProvider(DataBroker dataBroker2, NotificationProviderService notificationProviderService,
136 RpcProviderRegistry rpcProviderRegistry) {
138 String appName = configuration.getProperty(Constants.PROPERTY_APPLICATION_NAME);
139 logger.info(Msg.COMPONENT_INITIALIZING, appName, "provider");
141 executor = Executors.newFixedThreadPool(1);
142 dataBroker = dataBroker2;
143 notificationService = notificationProviderService;
144 rpcRegistry = rpcProviderRegistry;
146 if (rpcRegistry != null) {
147 rpcRegistration = rpcRegistry.addRpcImplementation(AppcProviderService.class, this);
150 logger.info(Msg.COMPONENT_INITIALIZED, appName, "provider");
154 * Implements the close of the service
156 * @see java.lang.AutoCloseable#close()
158 @SuppressWarnings("nls")
160 public void close() throws Exception {
161 String appName = configuration.getProperty(Constants.PROPERTY_APPLICATION_NAME);
162 logger.info(Msg.COMPONENT_TERMINATING, appName, "provider");
164 if (rpcRegistration != null) {
165 rpcRegistration.close();
167 logger.info(Msg.COMPONENT_TERMINATED, appName, "provider");
170 public Future<RpcResult<ModifyConfigOutput>> modifyConfig(ModifyConfigInput input) {
171 CommonRequestHeader hdr = input.getCommonRequestHeader();
172 ConfigPayload data = input.getConfigPayload();
173 RpcResult<ModifyConfigOutput> result = getTopologyService().modifyConfig(hdr, data);
174 return Futures.immediateFuture(result);
178 * Rebuilds a specific VNF
180 * @see org.opendaylight.yang.gen.v1.org.openecomp.appc.rev160104.AppcProviderService#rebuild(org.opendaylight.yang.gen.v1.org.openecomp.appc.rev160104.RebuildInput)
183 public Future<RpcResult<RebuildOutput>> rebuild(RebuildInput input) {
185 CommonRequestHeader hdr = input.getCommonRequestHeader();
186 VnfResource vnf = input.getVnfResource();
188 RpcResult<RebuildOutput> result = getTopologyService().rebuild(hdr, vnf);
189 return Futures.immediateFuture(result);
193 * Restarts a specific VNF
195 * @see org.opendaylight.yang.gen.v1.org.openecomp.appc.rev160104.AppcProviderService#restart(org.opendaylight.yang.gen.v1.org.openecomp.appc.rev160104.RestartInput)
198 public Future<RpcResult<RestartOutput>> restart(RestartInput input) {
199 CommonRequestHeader hdr = input.getCommonRequestHeader();
200 VnfResource vnf = input.getVnfResource();
202 RpcResult<RestartOutput> result = getTopologyService().restart(hdr, vnf);
203 return Futures.immediateFuture(result);
207 * Migrates a specific VNF
209 * @see org.opendaylight.yang.gen.v1.org.openecomp.appc.rev160104.AppcProviderService#migrate(org.opendaylight.yang.gen.v1.org.openecomp.appc.rev160104.MigrateInput)
212 public Future<RpcResult<MigrateOutput>> migrate(MigrateInput input) {
213 CommonRequestHeader hdr = input.getCommonRequestHeader();
214 VnfResource vnf = input.getVnfResource();
216 RpcResult<MigrateOutput> result = getTopologyService().migrate(hdr, vnf);
217 return Futures.immediateFuture(result);
221 * Evacuates a specific VNF
223 * @see org.opendaylight.yang.gen.v1.org.openecomp.appc.rev160104.AppcProviderService#evacuate(org.opendaylight.yang.gen.v1.org.openecomp.appc.rev160104.EvacuateInput)
226 public Future<RpcResult<EvacuateOutput>> evacuate(EvacuateInput input) {
232 * Evacuates a specific VNF
234 * @see org.opendaylight.yang.gen.v1.org.openecomp.appc.rev160104.AppcProviderService#evacuate(org.opendaylight.yang.gen.v1.org.openecomp.appc.rev160104.EvacuateInput)
237 public Future<RpcResult<SnapshotOutput>> snapshot(SnapshotInput input) {
238 CommonRequestHeader hdr = input.getCommonRequestHeader();
239 VnfResource vnf = input.getVnfResource();
241 RpcResult<SnapshotOutput> result = getTopologyService().snapshot(hdr, vnf);
242 return Futures.immediateFuture(result);
246 * Checks status of a VM
249 public Future<RpcResult<VmstatuscheckOutput>> vmstatuscheck(VmstatuscheckInput input) {
250 CommonRequestHeader hdr = input.getCommonRequestHeader();
251 VnfResource vnf = input.getVnfResource();
253 TopologyService topology = getTopologyService();
254 RpcResult<VmstatuscheckOutput> result = getTopologyService().vmstatuscheck(hdr, vnf);
255 return Futures.immediateFuture(result);
258 TopologyService getTopologyService() {
259 return new TopologyService(this);