Updating licenses in all files
[appc.git] / appc-provider / appc-provider-bundle / src / main / java / org / openecomp / appc / provider / AppcProvider.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * APPC
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
11  * 
12  *      http://www.apache.org/licenses/LICENSE-2.0
13  * 
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.
21  */
22
23 package org.openecomp.appc.provider;
24
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;
61
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;
72
73 /* ADDED FOR FUSION SERVICE CODE */
74
75 @SuppressWarnings("JavaDoc")
76 /**
77  * Defines the APPC service provider.
78  * <p>
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.
83  * </p>
84  * <p>
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}.
88  * </p>
89  *
90  * <pre>
91  *   rpc configuration-operation {
92  *      description "An operation to view, change, or audit the configuration of a VM";
93  *      input {
94  *          uses configuration-request-header;
95  *          uses configuration-request;
96  *      }
97  *      output {
98  *          uses common-response-header;
99  *          uses configuration-response;
100  *      }
101  *  }
102  * </pre>
103  *
104  */
105 public class AppcProvider implements AutoCloseable, AppcProviderService {
106
107     private final EELFLogger logger = EELFManager.getInstance().getLogger(AppcProviderClient.class);
108
109     private final ExecutorService executor;
110
111     private ListenerRegistration<DataChangeListener> dclServices;
112
113     /**
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.
116      */
117     protected DataBroker dataBroker;
118
119     /**
120      * ODL Notification Service that provides publish/subscribe capabilities for YANG modeled notifications.
121      */
122     protected NotificationProviderService notificationService;
123
124     /**
125      * Provides a registry for Remote Procedure Call (RPC) service implementations. The RPCs are defined in YANG models.
126      */
127     protected RpcProviderRegistry rpcRegistry;
128
129     /**
130      * Represents our RPC implementation registration
131      */
132     protected BindingAwareBroker.RpcRegistration<AppcProviderService> rpcRegistration;
133
134     /**
135      * The configuration
136      */
137     private Configuration configuration = ConfigurationFactory.getConfiguration();
138
139     /**
140      * @param dataBroker2
141      * @param notificationProviderService
142      * @param rpcProviderRegistry
143      */
144     @SuppressWarnings({
145         "javadoc", "nls"
146     })
147     public AppcProvider(DataBroker dataBroker2, NotificationProviderService notificationProviderService,
148                         RpcProviderRegistry rpcProviderRegistry) {
149
150         String appName = configuration.getProperty(Constants.PROPERTY_APPLICATION_NAME);
151         logger.info(Msg.COMPONENT_INITIALIZING, appName, "provider");
152
153         executor = Executors.newFixedThreadPool(1);
154         dataBroker = dataBroker2;
155         notificationService = notificationProviderService;
156         rpcRegistry = rpcProviderRegistry;
157
158         if (rpcRegistry != null) {
159             rpcRegistration = rpcRegistry.addRpcImplementation(AppcProviderService.class, this);
160         }
161
162         logger.info(Msg.COMPONENT_INITIALIZED, appName, "provider");
163     }
164
165     /**
166      * Implements the close of the service
167      *
168      * @see java.lang.AutoCloseable#close()
169      */
170     @SuppressWarnings("nls")
171     @Override
172     public void close() throws Exception {
173         String appName = configuration.getProperty(Constants.PROPERTY_APPLICATION_NAME);
174         logger.info(Msg.COMPONENT_TERMINATING, appName, "provider");
175         executor.shutdown();
176         if (rpcRegistration != null) {
177             rpcRegistration.close();
178         }
179         logger.info(Msg.COMPONENT_TERMINATED, appName, "provider");
180     }
181
182
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);
189 }
190     /**
191      * Rebuilds a specific VNF
192      *
193      * @see org.opendaylight.yang.gen.v1.org.openecomp.appc.rev160104.AppcProviderService#rebuild(org.opendaylight.yang.gen.v1.org.openecomp.appc.rev160104.RebuildInput)
194      */
195     @Override
196     public Future<RpcResult<RebuildOutput>> rebuild(RebuildInput input) {
197
198         CommonRequestHeader hdr = input.getCommonRequestHeader();
199         VnfResource vnf = input.getVnfResource();
200
201         TopologyService topology = new TopologyService(this);
202         RpcResult<RebuildOutput> result = topology.rebuild(hdr, vnf);
203         return Futures.immediateFuture(result);
204     }
205
206     /**
207      * Restarts a specific VNF
208      *
209      * @see org.opendaylight.yang.gen.v1.org.openecomp.appc.rev160104.AppcProviderService#restart(org.opendaylight.yang.gen.v1.org.openecomp.appc.rev160104.RestartInput)
210      */
211     @Override
212     public Future<RpcResult<RestartOutput>> restart(RestartInput input) {
213         CommonRequestHeader hdr = input.getCommonRequestHeader();
214         VnfResource vnf = input.getVnfResource();
215
216         TopologyService topology = new TopologyService(this);
217         RpcResult<RestartOutput> result = topology.restart(hdr, vnf);
218         return Futures.immediateFuture(result);
219     }
220
221     /**
222      * Migrates a specific VNF
223      *
224      * @see org.opendaylight.yang.gen.v1.org.openecomp.appc.rev160104.AppcProviderService#migrate(org.opendaylight.yang.gen.v1.org.openecomp.appc.rev160104.MigrateInput)
225      */
226     @Override
227     public Future<RpcResult<MigrateOutput>> migrate(MigrateInput input) {
228         CommonRequestHeader hdr = input.getCommonRequestHeader();
229         VnfResource vnf = input.getVnfResource();
230
231         TopologyService topology = new TopologyService(this);
232         RpcResult<MigrateOutput> result = topology.migrate(hdr, vnf);
233         return Futures.immediateFuture(result);
234     }
235
236     /**
237      * Evacuates a specific VNF
238      *
239      * @see org.opendaylight.yang.gen.v1.org.openecomp.appc.rev160104.AppcProviderService#evacuate(org.opendaylight.yang.gen.v1.org.openecomp.appc.rev160104.EvacuateInput)
240      */
241     @Override
242     public Future<RpcResult<EvacuateOutput>> evacuate(EvacuateInput input) {
243         CommonRequestHeader hdr = input.getCommonRequestHeader();
244         VnfResource vnf = input.getVnfResource();
245
246         TopologyService topology = new TopologyService(this);
247         return null;
248     }
249
250     /**
251      * Evacuates a specific VNF
252      *
253      * @see org.opendaylight.yang.gen.v1.org.openecomp.appc.rev160104.AppcProviderService#evacuate(org.opendaylight.yang.gen.v1.org.openecomp.appc.rev160104.EvacuateInput)
254      */
255     @Override
256     public Future<RpcResult<SnapshotOutput>> snapshot(SnapshotInput input) {
257         CommonRequestHeader hdr = input.getCommonRequestHeader();
258         VnfResource vnf = input.getVnfResource();
259
260         TopologyService topology = new TopologyService(this);
261         RpcResult<SnapshotOutput> result = topology.snapshot(hdr, vnf);
262         return Futures.immediateFuture(result);
263     }
264     
265     
266     /**
267      * Checks status of a VM
268     */
269     @Override
270     public Future<RpcResult<VmstatuscheckOutput>> vmstatuscheck(VmstatuscheckInput input) {
271     CommonRequestHeader hdr = input.getCommonRequestHeader();
272     VnfResource vnf = input.getVnfResource();
273
274     TopologyService topology = new TopologyService(this);
275     RpcResult<VmstatuscheckOutput> result = topology.vmstatuscheck(hdr, vnf);
276     return Futures.immediateFuture(result);
277     }   
278
279 }