blob: 79d664f181a6562b0aebd3e759e3ae73e309867b [file] [log] [blame]
Aharoni, Pavel (pa0916)ca3cb012018-10-22 15:29:57 +03001/*-
2 * ============LICENSE_START=======================================================
3 * OSAM
4 * ================================================================================
5 * Copyright (C) 2018 AT&T
6 * ================================================================================
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
10 *
11 * http://www.apache.org/licenses/LICENSE-2.0
12 *
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 * ============LICENSE_END=========================================================
19 */
20
21
22
23package org.onap.osam.job.command;
24
25import com.google.common.collect.ImmutableMap;
26import org.onap.osam.job.Job;
27import org.onap.osam.job.JobCommand;
28import org.onap.osam.job.NextCommand;
29import org.springframework.beans.factory.config.ConfigurableBeanFactory;
30import org.springframework.context.annotation.Scope;
31import org.springframework.stereotype.Component;
32
33import javax.ws.rs.client.ClientBuilder;
34import javax.ws.rs.client.Entity;
35import javax.ws.rs.core.Response;
36import java.util.Map;
37import java.util.UUID;
38
39
40@Component
41@Scope(ConfigurableBeanFactory.SCOPE_PROTOTYPE)
42public class HttpCallCommand implements JobCommand {
43 private String url;
44 private UUID uuid;
45
46 public HttpCallCommand() {
47 }
48
49 public HttpCallCommand(String url, UUID uuid) {
50 init(url, uuid);
51 }
52
53 @Override
54 public NextCommand call() {
55 final Response response = ClientBuilder.newClient().target(url).request().post(Entity.text(uuid.toString()));
56 return new NextCommand(Job.JobStatus.COMPLETED);
57 }
58
59 @Override
60 public HttpCallCommand init(UUID jobUuid, Map<String, Object> data) {
61 return init((String) data.get("url"), jobUuid);
62 }
63
64 private HttpCallCommand init(String url, UUID jobUuid) {
65 this.url = url;
66 this.uuid = jobUuid;
67 return this;
68 }
69
70 @Override
71 public Map<String, Object> getData() {
72 return ImmutableMap.of("url", url);
73 }
74}