1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
|
/*-
* ============LICENSE_START=======================================================
* Copyright (C) 2019-2020 AT&T Intellectual Property. All rights reserved.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* ============LICENSE_END=========================================================
*/
package org.onap.policy.drools.server.restful;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import java.util.Properties;
import javax.ws.rs.Consumes;
import javax.ws.rs.GET;
import javax.ws.rs.PUT;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
import org.onap.policy.common.endpoints.event.comm.TopicSink;
import org.onap.policy.common.endpoints.event.comm.TopicSource;
import org.onap.policy.common.endpoints.http.server.YamlMessageBodyHandler;
import org.onap.policy.drools.lifecycle.LifecycleFeature;
import org.onap.policy.drools.lifecycle.PolicyTypeController;
import org.onap.policy.models.pdp.concepts.PdpStateChange;
import org.onap.policy.models.pdp.enums.PdpState;
import org.onap.policy.models.tosca.authorative.concepts.ToscaPolicy;
import org.onap.policy.models.tosca.authorative.concepts.ToscaPolicyTypeIdentifier;
/**
* REST Lifecycle Manager.
*/
@Path("/policy/pdp/engine/lifecycle")
@Produces({MediaType.APPLICATION_JSON, YamlMessageBodyHandler.APPLICATION_YAML})
@Consumes({MediaType.APPLICATION_JSON, YamlMessageBodyHandler.APPLICATION_YAML})
@Api
public class RestLifecycleManager {
/**
* GET group.
*/
@GET
@Path("group")
@ApiOperation(value = "Retrieves the Lifecycle group",
notes = "Lifecycle Group", response = String.class)
public Response group() {
return Response.status(Response.Status.OK).entity(LifecycleFeature.fsm.getGroup()).build();
}
/**
* PUT group.
*/
@PUT
@Path("group/{group}")
@ApiOperation(value = "Updates the Lifecycle group",
notes = "Lifecycle Group", response = String.class)
public Response updateGroup(
@ApiParam(value = "Group", required = true) @PathParam("group") String group) {
LifecycleFeature.fsm.setGroup(group);
return Response.status(Response.Status.OK).entity(LifecycleFeature.fsm.getGroup()).build();
}
/**
* GET subgroup.
*/
@GET
@Path("subgroup")
@ApiOperation(value = "Retrieves the Lifecycle subgroup",
notes = "Lifecycle Subgroup", response = String.class)
public Response subgroup() {
return Response.status(Response.Status.OK).entity(LifecycleFeature.fsm.getSubgroup()).build();
}
/**
* PUT subgroup.
*/
@PUT
@Path("subgroup/{subgroup}")
@ApiOperation(value = "Retrieves the Lifecycle subgroup",
notes = "Lifecycle Subgroup", response = String.class)
public Response subgroup(
@ApiParam(value = "Subgroup", required = true) @PathParam("subgroup") String subgroup) {
LifecycleFeature.fsm.setSubgroup(subgroup);
return Response.status(Response.Status.OK).entity(LifecycleFeature.fsm.getSubgroup()).build();
}
/**
* GET properties.
*/
@GET
@Path("properties")
@ApiOperation(value = "Retrieves the Lifecycle properties",
notes = "Lifecycle Properties", response = Properties.class)
public Response properties() {
return Response.status(Response.Status.OK).entity(LifecycleFeature.fsm.getProperties()).build();
}
/**
* GET state.
*/
@GET
@Path("state")
@ApiOperation(value = "Retrieves the Lifecycle state", notes = "Lifecycle State", response = PdpState.class)
public Response state() {
return Response.status(Response.Status.OK).entity(LifecycleFeature.fsm.state()).build();
}
/**
* PUT state.
*/
@PUT
@Path("state/{state}")
@ApiOperation(value = "updates the Lifecycle state", notes = "Lifecycle State", response = Boolean.class)
public Response updateState(
@ApiParam(value = "state", required = true) @PathParam("state") String state) {
PdpStateChange change = new PdpStateChange();
change.setPdpGroup(LifecycleFeature.fsm.getGroup());
change.setPdpSubgroup(LifecycleFeature.fsm.getSubgroup());
change.setState(PdpState.valueOf(state));
change.setName(LifecycleFeature.fsm.getName());
return Response.status(Response.Status.OK).entity(LifecycleFeature.fsm.stateChange(change)).build();
}
/**
* GET topic source.
*/
@GET
@Path("topic/source")
@ApiOperation(value = "Retrieves the Lifecycle topic source",
notes = "Lifecycle Topic Source", response = TopicSource.class)
public Response source() {
return Response.status(Response.Status.OK).entity(LifecycleFeature.fsm.getSource()).build();
}
/**
* GET topic sink.
*/
@GET
@Path("topic/sink")
@ApiOperation(value = "Retrieves the Lifecycle topic sink",
notes = "Lifecycle Topic Sink", response = TopicSink.class)
public Response sink() {
return Response.status(Response.Status.OK).entity(LifecycleFeature.fsm.getClient()).build();
}
/**
* GET status interval.
*/
@GET
@Path("status/interval")
@ApiOperation(value = "Retrieves the Lifecycle Status Timer Interval in seconds",
notes = "Lifecycle Status Timer Interval in seconds", response = Long.class)
public Response updateStatusTimer() {
return Response.status(Response.Status.OK).entity(LifecycleFeature.fsm.getStatusTimerSeconds()).build();
}
/**
* PUT timeout.
*/
@PUT
@Path("status/interval/{timeout}")
@ApiOperation(value = "Updates the Lifecycle Status Timer Interval in seconds",
notes = "Lifecycle Status Timer Interval in seconds", response = Long.class)
public Response statusTimer(
@ApiParam(value = "timeout", required = true) @PathParam("timeout") Long timeout) {
LifecycleFeature.fsm.setStatusTimerSeconds(timeout);
return Response.status(Response.Status.OK).entity(LifecycleFeature.fsm.getStatusTimerSeconds()).build();
}
/**
* GET policy types.
*/
@GET
@Path("policyTypes")
@ApiOperation(value = "List of supported policy types",
notes = "Lifecycle Policy Types", responseContainer = "List")
public Response policyTypes() {
return Response.status(Response.Status.OK)
.entity(LifecycleFeature.fsm.getPolicyTypesMap().keySet())
.build();
}
/**
* GET controllers.
*/
@GET
@Path("policyTypes/{policyType}/{policyVersion}")
@ApiOperation(value = "Entities associated with a policy type",
notes = "Lifecycle policy Types", response = PolicyTypeController.class)
public Response policyType(
@ApiParam(value = "Policy Type", required = true) @PathParam("policyType") String policyType,
@ApiParam(value = "Policy Type Version", required = true) @PathParam("policyVersion") String policyVersion) {
return Response.status(Response.Status.OK)
.entity(LifecycleFeature.fsm
.getPolicyTypesMap()
.get(new ToscaPolicyTypeIdentifier(policyType, policyVersion)))
.build();
}
/**
* GET policies.
*/
@GET
@Path("policies")
@ApiOperation(value = "List of tracked policies",
notes = "Lifecycle Policies", responseContainer = "List")
public Response policies() {
return Response.status(Response.Status.OK)
.entity(LifecycleFeature.fsm.getPoliciesMap().keySet())
.build();
}
/**
* GET a policy.
*/
@GET
@Path("policies/{policy}/{policyVersion}")
@ApiOperation(value = "Lifecycle tracked policy",
notes = "Lifecycle Tracked Policy", response = ToscaPolicy.class)
public Response policy(
@ApiParam(value = "Policy", required = true) @PathParam("policyName") String policyName,
@ApiParam(value = "Policy Version", required = true) @PathParam("policyVersion") String policyVersion) {
ToscaPolicy policy = LifecycleFeature.fsm
.getPoliciesMap()
.get(new ToscaPolicyTypeIdentifier(policyName, policyVersion));
if (policy != null) {
return
Response.status(Response.Status.OK)
.entity(LifecycleFeature.fsm.getPolicyTypesMap()
.get(new ToscaPolicyTypeIdentifier(policyName, policyVersion)))
.build();
}
return Response.status(Response.Status.NOT_FOUND).build();
}
}
|