First part of onap rename
[appc.git] / appc-provider / appc-provider-bundle / src / main / java / org / openecomp / appc / provider / AppcProvider.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * ONAP : APPC
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
12  *
13  *      http://www.apache.org/licenses/LICENSE-2.0
14  *
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.
20  *
21  * ECOMP is a trademark and service mark of AT&T Intellectual Property.
22  * ============LICENSE_END=========================================================
23  */
24
25 package org.onap.appc.provider;
26
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.onap.appc.rev160104.AppcProviderService;
35 import org.opendaylight.yang.gen.v1.org.onap.appc.rev160104.EvacuateInput;
36 import org.opendaylight.yang.gen.v1.org.onap.appc.rev160104.EvacuateOutput;
37 import org.opendaylight.yang.gen.v1.org.onap.appc.rev160104.MigrateInput;
38 import org.opendaylight.yang.gen.v1.org.onap.appc.rev160104.MigrateOutput;
39 import org.opendaylight.yang.gen.v1.org.onap.appc.rev160104.ModifyConfigInput;
40 import org.opendaylight.yang.gen.v1.org.onap.appc.rev160104.ModifyConfigOutput;
41 import org.opendaylight.yang.gen.v1.org.onap.appc.rev160104.RebuildInput;
42 import org.opendaylight.yang.gen.v1.org.onap.appc.rev160104.RebuildOutput;
43 import org.opendaylight.yang.gen.v1.org.onap.appc.rev160104.RestartInput;
44 import org.opendaylight.yang.gen.v1.org.onap.appc.rev160104.RestartOutput;
45 import org.opendaylight.yang.gen.v1.org.onap.appc.rev160104.SnapshotInput;
46 import org.opendaylight.yang.gen.v1.org.onap.appc.rev160104.SnapshotOutput;
47 import org.opendaylight.yang.gen.v1.org.onap.appc.rev160104.VmstatuscheckInput;
48 import org.opendaylight.yang.gen.v1.org.onap.appc.rev160104.VmstatuscheckOutput;
49 import org.opendaylight.yang.gen.v1.org.onap.appc.rev160104.common.request.header.CommonRequestHeader;
50 import org.opendaylight.yang.gen.v1.org.onap.appc.rev160104.config.payload.ConfigPayload;
51 import org.opendaylight.yang.gen.v1.org.onap.appc.rev160104.vnf.resource.VnfResource;
52 import org.opendaylight.yangtools.yang.common.RpcResult;
53 import org.onap.appc.Constants;
54 import org.onap.appc.configuration.Configuration;
55 import org.onap.appc.configuration.ConfigurationFactory;
56 import org.onap.appc.i18n.Msg;
57 import org.onap.appc.provider.topology.TopologyService;
58
59 import java.util.concurrent.ExecutorService;
60 import java.util.concurrent.Executors;
61 import java.util.concurrent.Future;
62
63 /* ADDED FOR FUSION SERVICE CODE */
64
65 @SuppressWarnings("JavaDoc")
66 /**
67  * Defines the APPC service provider.
68  * <p>
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.
73  * </p>
74  * <p>
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}.
78  * </p>
79  *
80  * <pre>
81  *   rpc configuration-operation {
82  *      description "An operation to view, change, or audit the configuration of a VM";
83  *      input {
84  *          uses configuration-request-header;
85  *          uses configuration-request;
86  *      }
87  *      output {
88  *          uses common-response-header;
89  *          uses configuration-response;
90  *      }
91  *  }
92  * </pre>
93  *
94  */
95 public class AppcProvider implements AutoCloseable, AppcProviderService {
96
97     private final EELFLogger logger = EELFManager.getInstance().getLogger(AppcProviderClient.class);
98
99     private final ExecutorService executor;
100
101     /**
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.
104      */
105     protected DataBroker dataBroker;
106
107     /**
108      * ODL Notification Service that provides publish/subscribe capabilities for YANG modeled notifications.
109      */
110     protected NotificationProviderService notificationService;
111
112     /**
113      * Provides a registry for Remote Procedure Call (RPC) service implementations. The RPCs are defined in YANG models.
114      */
115     protected RpcProviderRegistry rpcRegistry;
116
117     /**
118      * Represents our RPC implementation registration
119      */
120     protected BindingAwareBroker.RpcRegistration<AppcProviderService> rpcRegistration;
121
122     /**
123      * The configuration
124      */
125     private Configuration configuration = ConfigurationFactory.getConfiguration();
126
127     /**
128      * @param dataBroker2
129      * @param notificationProviderService
130      * @param rpcProviderRegistry
131      */
132     @SuppressWarnings({
133         "javadoc", "nls"
134     })
135     public AppcProvider(DataBroker dataBroker2, NotificationProviderService notificationProviderService,
136                         RpcProviderRegistry rpcProviderRegistry) {
137
138         String appName = configuration.getProperty(Constants.PROPERTY_APPLICATION_NAME);
139         logger.info(Msg.COMPONENT_INITIALIZING, appName, "provider");
140
141         executor = Executors.newFixedThreadPool(1);
142         dataBroker = dataBroker2;
143         notificationService = notificationProviderService;
144         rpcRegistry = rpcProviderRegistry;
145
146         if (rpcRegistry != null) {
147             rpcRegistration = rpcRegistry.addRpcImplementation(AppcProviderService.class, this);
148         }
149
150         logger.info(Msg.COMPONENT_INITIALIZED, appName, "provider");
151     }
152
153     /**
154      * Implements the close of the service
155      *
156      * @see java.lang.AutoCloseable#close()
157      */
158     @SuppressWarnings("nls")
159     @Override
160     public void close() throws Exception {
161         String appName = configuration.getProperty(Constants.PROPERTY_APPLICATION_NAME);
162         logger.info(Msg.COMPONENT_TERMINATING, appName, "provider");
163         executor.shutdown();
164         if (rpcRegistration != null) {
165             rpcRegistration.close();
166         }
167         logger.info(Msg.COMPONENT_TERMINATED, appName, "provider");
168     }
169
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);
175     }
176
177     /**
178      * Rebuilds a specific VNF
179      *
180      * @see org.opendaylight.yang.gen.v1.org.onap.appc.rev160104.AppcProviderService#rebuild(org.opendaylight.yang.gen.v1.org.onap.appc.rev160104.RebuildInput)
181      */
182     @Override
183     public Future<RpcResult<RebuildOutput>> rebuild(RebuildInput input) {
184
185         CommonRequestHeader hdr = input.getCommonRequestHeader();
186         VnfResource vnf = input.getVnfResource();
187
188         RpcResult<RebuildOutput> result = getTopologyService().rebuild(hdr, vnf);
189         return Futures.immediateFuture(result);
190     }
191
192     /**
193      * Restarts a specific VNF
194      *
195      * @see org.opendaylight.yang.gen.v1.org.onap.appc.rev160104.AppcProviderService#restart(org.opendaylight.yang.gen.v1.org.onap.appc.rev160104.RestartInput)
196      */
197     @Override
198     public Future<RpcResult<RestartOutput>> restart(RestartInput input) {
199         CommonRequestHeader hdr = input.getCommonRequestHeader();
200         VnfResource vnf = input.getVnfResource();
201
202         RpcResult<RestartOutput> result = getTopologyService().restart(hdr, vnf);
203         return Futures.immediateFuture(result);
204     }
205
206     /**
207      * Migrates a specific VNF
208      *
209      * @see org.opendaylight.yang.gen.v1.org.onap.appc.rev160104.AppcProviderService#migrate(org.opendaylight.yang.gen.v1.org.onap.appc.rev160104.MigrateInput)
210      */
211     @Override
212     public Future<RpcResult<MigrateOutput>> migrate(MigrateInput input) {
213         CommonRequestHeader hdr = input.getCommonRequestHeader();
214         VnfResource vnf = input.getVnfResource();
215
216         RpcResult<MigrateOutput> result = getTopologyService().migrate(hdr, vnf);
217         return Futures.immediateFuture(result);
218     }
219
220     /**
221      * Evacuates a specific VNF
222      *
223      * @see org.opendaylight.yang.gen.v1.org.onap.appc.rev160104.AppcProviderService#evacuate(org.opendaylight.yang.gen.v1.org.onap.appc.rev160104.EvacuateInput)
224      */
225     @Override
226     public Future<RpcResult<EvacuateOutput>> evacuate(EvacuateInput input) {
227
228         return null;
229     }
230
231     /**
232      * Evacuates a specific VNF
233      *
234      * @see org.opendaylight.yang.gen.v1.org.onap.appc.rev160104.AppcProviderService#evacuate(org.opendaylight.yang.gen.v1.org.onap.appc.rev160104.EvacuateInput)
235      */
236     @Override
237     public Future<RpcResult<SnapshotOutput>> snapshot(SnapshotInput input) {
238         CommonRequestHeader hdr = input.getCommonRequestHeader();
239         VnfResource vnf = input.getVnfResource();
240
241         RpcResult<SnapshotOutput> result = getTopologyService().snapshot(hdr, vnf);
242         return Futures.immediateFuture(result);
243     }
244
245     /**
246      * Checks status of a VM
247      */
248     @Override
249     public Future<RpcResult<VmstatuscheckOutput>> vmstatuscheck(VmstatuscheckInput input) {
250         CommonRequestHeader hdr = input.getCommonRequestHeader();
251         VnfResource vnf = input.getVnfResource();
252
253         TopologyService topology = getTopologyService();
254         RpcResult<VmstatuscheckOutput> result = getTopologyService().vmstatuscheck(hdr, vnf);
255         return Futures.immediateFuture(result);
256     }
257
258     TopologyService getTopologyService() {
259         return new TopologyService(this);
260     }
261 }