8e114a3c6b7b2b9688f0c0b665e8d04bd46b9e7b
[appc.git] / appc-inbound / appc-interfaces-service / bundle / src / main / java / org / onap / appc / interfaces / service / InterfacesServiceProviderImpl.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.interfaces.service;
26
27 import java.util.concurrent.Future;
28
29 import org.opendaylight.yang.gen.v1.org.onap.appc.interfaces.service.rev170818.ExecuteServiceInput;
30 import org.opendaylight.yang.gen.v1.org.onap.appc.interfaces.service.rev170818.ExecuteServiceOutput;
31 import org.opendaylight.yang.gen.v1.org.onap.appc.interfaces.service.rev170818.ExecuteServiceOutputBuilder;
32 import org.opendaylight.yang.gen.v1.org.onap.appc.interfaces.service.rev170818.InterfacesServiceService;
33 import org.opendaylight.yang.gen.v1.org.onap.appc.interfaces.service.rev170818.response.info.ResponseInfoBuilder;
34 import org.opendaylight.yang.gen.v1.org.onap.appc.interfaces.service.rev170818.status.StatusBuilder;
35 import org.opendaylight.yangtools.yang.common.RpcResult;
36 import org.opendaylight.yangtools.yang.common.RpcResultBuilder;
37 import org.onap.appc.interfaces.service.executor.ServiceExecutor;
38 import org.slf4j.Logger;
39 import org.slf4j.LoggerFactory;
40
41 import com.google.common.util.concurrent.Futures;
42
43 public class InterfacesServiceProviderImpl implements InterfacesServiceService{
44
45     private static final Logger log = LoggerFactory.getLogger(InterfacesServiceProviderImpl.class);
46
47     @Override
48     public Future<RpcResult<ExecuteServiceOutput>> executeService(ExecuteServiceInput input) {
49
50         log.info("Received Request: " + input.getRequest().getRequestId() + " Action : " + 
51                 input.getRequest().getAction() + " with RequestData  :" + input.getRequest().getRequestData() + " and data-Type : " + input.getRequest().getRequestDataType());
52         String request_id = input.getRequest().getRequestId();
53         String action = input.getRequest().getAction();
54         ResponseInfoBuilder responseInfoBuilder = new ResponseInfoBuilder();
55         ExecuteServiceOutputBuilder executeServicebuilder = new ExecuteServiceOutputBuilder();
56         ServiceExecutor serviceExecutor = new ServiceExecutor();
57         StatusBuilder statusBuilder = new StatusBuilder();
58         try{
59             String response = serviceExecutor.execute(action, input.getRequest().getRequestData(), input.getRequest().getRequestDataType());
60             responseInfoBuilder.setBlock(response);
61             responseInfoBuilder.setRequestId(request_id);
62             statusBuilder.setCode("400");
63             statusBuilder.setMessage("success");
64         }
65         catch(Exception e){
66             log.error("Error" + e.getMessage());
67             e.printStackTrace();
68             statusBuilder.setCode("401");
69             statusBuilder.setMessage("failuer");
70         }
71         executeServicebuilder.setResponseInfo(responseInfoBuilder.build());
72         executeServicebuilder.setStatus(statusBuilder.build());
73         RpcResult<ExecuteServiceOutput> result  = RpcResultBuilder.<ExecuteServiceOutput>status(true).withResult(executeServicebuilder.build()).build();
74         return Futures.immediateFuture(result);
75     }
76 }