2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017-2018 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 * ============LICENSE_END=========================================================
24 package org.onap.appc.provider;
26 import com.att.eelf.configuration.EELFLogger;
27 import com.att.eelf.configuration.EELFManager;
28 import com.google.common.util.concurrent.Futures;
29 import org.opendaylight.controller.md.sal.binding.api.DataBroker;
30 import org.opendaylight.controller.md.sal.binding.api.NotificationPublishService;
31 import org.opendaylight.controller.sal.binding.api.BindingAwareBroker;
32 import org.opendaylight.controller.sal.binding.api.RpcProviderRegistry;
33 import org.opendaylight.yang.gen.v1.org.onap.appc.provider.rev160104.AppcProviderService;
34 import org.opendaylight.yang.gen.v1.org.onap.appc.provider.rev160104.EvacuateInput;
35 import org.opendaylight.yang.gen.v1.org.onap.appc.provider.rev160104.EvacuateOutput;
36 import org.opendaylight.yang.gen.v1.org.onap.appc.provider.rev160104.MigrateInput;
37 import org.opendaylight.yang.gen.v1.org.onap.appc.provider.rev160104.MigrateOutput;
38 import org.opendaylight.yang.gen.v1.org.onap.appc.provider.rev160104.ModifyConfigInput;
39 import org.opendaylight.yang.gen.v1.org.onap.appc.provider.rev160104.ModifyConfigOutput;
40 import org.opendaylight.yang.gen.v1.org.onap.appc.provider.rev160104.RebuildInput;
41 import org.opendaylight.yang.gen.v1.org.onap.appc.provider.rev160104.RebuildOutput;
42 import org.opendaylight.yang.gen.v1.org.onap.appc.provider.rev160104.RestartInput;
43 import org.opendaylight.yang.gen.v1.org.onap.appc.provider.rev160104.RestartOutput;
44 import org.opendaylight.yang.gen.v1.org.onap.appc.provider.rev160104.SnapshotInput;
45 import org.opendaylight.yang.gen.v1.org.onap.appc.provider.rev160104.SnapshotOutput;
46 import org.opendaylight.yang.gen.v1.org.onap.appc.provider.rev160104.VmstatuscheckInput;
47 import org.opendaylight.yang.gen.v1.org.onap.appc.provider.rev160104.VmstatuscheckOutput;
48 import org.opendaylight.yang.gen.v1.org.onap.appc.provider.rev160104.common.request.header.CommonRequestHeader;
49 import org.opendaylight.yang.gen.v1.org.onap.appc.provider.rev160104.config.payload.ConfigPayload;
50 import org.opendaylight.yang.gen.v1.org.onap.appc.provider.rev160104.vnf.resource.VnfResource;
51 import org.opendaylight.yangtools.yang.common.RpcResult;
52 import org.onap.appc.Constants;
53 import org.onap.appc.configuration.Configuration;
54 import org.onap.appc.configuration.ConfigurationFactory;
55 import org.onap.appc.i18n.Msg;
56 import org.onap.appc.provider.topology.TopologyService;
58 import java.util.concurrent.ExecutorService;
59 import java.util.concurrent.Executors;
60 import java.util.concurrent.Future;
62 /* ADDED FOR FUSION SERVICE CODE */
64 @SuppressWarnings("JavaDoc")
66 * Defines the APPC service provider.
68 * The rpc definition in the YANG model is shown below. This model is used to generate code to manage the inputs and
69 * outputs of the RPC service. For example, the input is defined by a class named {@link ConfigurationOperationInput},
70 * which is generated from the name of the RPC and the "input" definition of the RPC. This class encapsulates the
71 * various objects that are passed to the RPC and is used to obtain values from the input parameters.
74 * Likewise, the outputs are defined by a class named {@link ConfigurationOperationOutput}. This class encapsulates the
75 * defined outputs. To make construction of the outputs easier, there are also generated builder classes that are named
76 * for the various elements of the output they "build", such as {@link ConfigurationResponseBuilder}.
80 * rpc configuration-operation {
81 * description "An operation to view, change, or audit the configuration of a VM";
83 * uses configuration-request-header;
84 * uses configuration-request;
87 * uses common-response-header;
88 * uses configuration-response;
94 public class AppcProvider implements AutoCloseable, AppcProviderService {
96 private final EELFLogger logger = EELFManager.getInstance().getLogger(AppcProviderClient.class);
98 private final ExecutorService executor;
101 * The ODL data store broker. Provides access to a conceptual data tree store and also provides the ability to
102 * subscribe for changes to data under a given branch of the tree.
104 protected DataBroker dataBroker;
107 * ODL Notification Service that provides publish/subscribe capabilities for YANG modeled notifications.
109 protected NotificationPublishService notificationService;
112 * Provides a registry for Remote Procedure Call (RPC) service implementations. The RPCs are defined in YANG models.
114 protected RpcProviderRegistry rpcRegistry;
117 * Represents our RPC implementation registration
119 protected BindingAwareBroker.RpcRegistration<AppcProviderService> rpcRegistration;
124 private Configuration configuration = ConfigurationFactory.getConfiguration();
126 private AppcProviderClient appcProviderClient;
130 * @param notificationProviderService
131 * @param rpcProviderRegistry
136 public AppcProvider(DataBroker dataBroker2, NotificationPublishService notificationProviderService,
137 RpcProviderRegistry rpcProviderRegistry, AppcProviderClient appcProviderClient) {
139 String appName = configuration.getProperty(Constants.PROPERTY_APPLICATION_NAME);
140 logger.info(Msg.COMPONENT_INITIALIZING, appName, "provider");
142 executor = Executors.newFixedThreadPool(1);
143 dataBroker = dataBroker2;
144 notificationService = notificationProviderService;
145 rpcRegistry = rpcProviderRegistry;
146 this.appcProviderClient = appcProviderClient;
148 logger.info(Msg.COMPONENT_INITIALIZED, appName, "provider");
152 * Implements the close of the service
154 * @see java.lang.AutoCloseable#close()
156 @SuppressWarnings("nls")
158 public void close() throws Exception {
159 String appName = configuration.getProperty(Constants.PROPERTY_APPLICATION_NAME);
160 logger.info(Msg.COMPONENT_TERMINATING, appName, "provider");
162 if (rpcRegistration != null) {
163 rpcRegistration.close();
165 logger.info(Msg.COMPONENT_TERMINATED, appName, "provider");
168 public Future<RpcResult<ModifyConfigOutput>> modifyConfig(ModifyConfigInput input) {
169 CommonRequestHeader hdr = input.getCommonRequestHeader();
170 ConfigPayload data = input.getConfigPayload();
171 RpcResult<ModifyConfigOutput> result = getTopologyService().modifyConfig(hdr, data);
172 return Futures.immediateFuture(result);
176 * Rebuilds a specific VNF
178 * @see org.opendaylight.yang.gen.v1.org.onap.appc.provider.rev160104.AppcProviderService#rebuild(org.opendaylight.yang.gen.v1.org.onap.appc.provider.rev160104.RebuildInput)
181 public Future<RpcResult<RebuildOutput>> rebuild(RebuildInput input) {
183 CommonRequestHeader hdr = input.getCommonRequestHeader();
184 VnfResource vnf = input.getVnfResource();
186 RpcResult<RebuildOutput> result = getTopologyService().rebuild(hdr, vnf);
187 return Futures.immediateFuture(result);
191 * Restarts a specific VNF
193 * @see org.opendaylight.yang.gen.v1.org.onap.appc.provider.rev160104.AppcProviderService#restart(org.opendaylight.yang.gen.v1.org.onap.appc.provider.rev160104.RestartInput)
196 public Future<RpcResult<RestartOutput>> restart(RestartInput input) {
197 CommonRequestHeader hdr = input.getCommonRequestHeader();
198 VnfResource vnf = input.getVnfResource();
200 RpcResult<RestartOutput> result = getTopologyService().restart(hdr, vnf);
201 return Futures.immediateFuture(result);
205 * Migrates a specific VNF
207 * @see org.opendaylight.yang.gen.v1.org.onap.appc.provider.rev160104.AppcProviderService#migrate(org.opendaylight.yang.gen.v1.org.onap.appc.provider.rev160104.MigrateInput)
210 public Future<RpcResult<MigrateOutput>> migrate(MigrateInput input) {
211 CommonRequestHeader hdr = input.getCommonRequestHeader();
212 VnfResource vnf = input.getVnfResource();
214 RpcResult<MigrateOutput> result = getTopologyService().migrate(hdr, vnf);
215 return Futures.immediateFuture(result);
219 * Evacuates a specific VNF
221 * @see org.opendaylight.yang.gen.v1.org.onap.appc.provider.rev160104.AppcProviderService#evacuate(org.opendaylight.yang.gen.v1.org.onap.appc.provider.rev160104.EvacuateInput)
224 public Future<RpcResult<EvacuateOutput>> evacuate(EvacuateInput input) {
230 * Evacuates a specific VNF
232 * @see org.opendaylight.yang.gen.v1.org.onap.appc.provider.rev160104.AppcProviderService#evacuate(org.opendaylight.yang.gen.v1.org.onap.appc.provider.rev160104.EvacuateInput)
235 public Future<RpcResult<SnapshotOutput>> snapshot(SnapshotInput input) {
236 CommonRequestHeader hdr = input.getCommonRequestHeader();
237 VnfResource vnf = input.getVnfResource();
239 RpcResult<SnapshotOutput> result = getTopologyService().snapshot(hdr, vnf);
240 return Futures.immediateFuture(result);
244 * Checks status of a VM
247 public Future<RpcResult<VmstatuscheckOutput>> vmstatuscheck(VmstatuscheckInput input) {
248 CommonRequestHeader hdr = input.getCommonRequestHeader();
249 VnfResource vnf = input.getVnfResource();
251 TopologyService topology = getTopologyService();
252 RpcResult<VmstatuscheckOutput> result = getTopologyService().vmstatuscheck(hdr, vnf);
253 return Futures.immediateFuture(result);
256 TopologyService getTopologyService() {
257 return new TopologyService(this);
260 public AppcProviderClient getClient() {
261 return appcProviderClient;