2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017-2018 AT&T Intellectual Property. All rights reserved.
6 * ================================================================================
7 * Copyright (C) 2017 Amdocs
8 * ================================================================================
9 * Modifications Copyright (C) 2019 Ericsson
10 * Modifications Copyright (C) 2019 IBM
11 * =============================================================================
12 * Licensed under the Apache License, Version 2.0 (the "License");
13 * you may not use this file except in compliance with the License.
14 * You may obtain a copy of the License at
16 * http://www.apache.org/licenses/LICENSE-2.0
18 * Unless required by applicable law or agreed to in writing, software
19 * distributed under the License is distributed on an "AS IS" BASIS,
20 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
21 * See the License for the specific language governing permissions and
22 * limitations under the License.
24 * ============LICENSE_END=========================================================
27 package org.onap.appc.interfaces.service;
29 import java.util.concurrent.Future;
31 import org.opendaylight.yang.gen.v1.org.onap.appc.interfaces.service.rev170818.ExecuteServiceInput;
32 import org.opendaylight.yang.gen.v1.org.onap.appc.interfaces.service.rev170818.ExecuteServiceOutput;
33 import org.opendaylight.yang.gen.v1.org.onap.appc.interfaces.service.rev170818.ExecuteServiceOutputBuilder;
34 import org.opendaylight.yang.gen.v1.org.onap.appc.interfaces.service.rev170818.InterfacesServiceService;
35 import org.opendaylight.yang.gen.v1.org.onap.appc.interfaces.service.rev170818.response.info.ResponseInfoBuilder;
36 import org.opendaylight.yang.gen.v1.org.onap.appc.interfaces.service.rev170818.status.StatusBuilder;
37 import org.opendaylight.yangtools.yang.common.RpcResult;
38 import org.opendaylight.yangtools.yang.common.RpcResultBuilder;
39 import org.onap.appc.interfaces.service.executor.ServiceExecutor;
40 import org.slf4j.Logger;
41 import org.slf4j.LoggerFactory;
43 import com.google.common.util.concurrent.Futures;
45 public class InterfacesServiceProviderImpl implements InterfacesServiceService{
47 private static final Logger log = LoggerFactory.getLogger(InterfacesServiceProviderImpl.class);
50 public Future<RpcResult<ExecuteServiceOutput>> executeService(ExecuteServiceInput input) {
52 log.info("Received Request: " + input.getRequest().getRequestId() + " Action : " +
53 input.getRequest().getAction() + " with RequestData :" + input.getRequest().getRequestData() + " and data-Type : " + input.getRequest().getRequestDataType());
54 String request_id = input.getRequest().getRequestId();
55 String action = input.getRequest().getAction();
56 ResponseInfoBuilder responseInfoBuilder = new ResponseInfoBuilder();
57 ExecuteServiceOutputBuilder executeServicebuilder = new ExecuteServiceOutputBuilder();
58 ServiceExecutor serviceExecutor = getServiceExecutor();
59 StatusBuilder statusBuilder = new StatusBuilder();
61 String response = serviceExecutor.execute(action, input.getRequest().getRequestData(), input.getRequest().getRequestDataType());
62 responseInfoBuilder.setBlock(response);
63 responseInfoBuilder.setRequestId(request_id);
64 statusBuilder.setCode("400");
65 statusBuilder.setMessage("success");
68 log.error("Error" + e.getMessage());
69 statusBuilder.setCode("401");
70 statusBuilder.setMessage("failure");
72 executeServicebuilder.setResponseInfo(responseInfoBuilder.build());
73 executeServicebuilder.setStatus(statusBuilder.build());
74 RpcResult<ExecuteServiceOutput> result = RpcResultBuilder.<ExecuteServiceOutput>status(true).withResult(executeServicebuilder.build()).build();
75 return Futures.immediateFuture(result);
78 protected ServiceExecutor getServiceExecutor() {
79 return new ServiceExecutor();