--- /dev/null
+/*-
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2019 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 static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+
+import javax.ws.rs.core.Response;
+import javax.ws.rs.core.Response.Status;
+import org.junit.After;
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Test;
+import org.onap.policy.common.endpoints.event.comm.bus.internal.BusTopicParams;
+import org.onap.policy.common.endpoints.http.client.HttpClient;
+import org.onap.policy.common.endpoints.http.server.HttpServletServer;
+import org.onap.policy.common.utils.network.NetworkUtil;
+import org.onap.policy.drools.persistence.SystemPersistence;
+import org.onap.policy.models.pdp.enums.PdpState;
+
+/**
+ * REST Lifecycle Manager Test.
+ */
+public class RestLifecycleManagerTest {
+
+ /**
+ * Set up.
+ */
+ @Before
+ public void setUp() throws Exception {
+ HttpServletServer.factory.destroy();
+ HttpClient.factory.destroy();
+
+ SystemPersistence.manager.setConfigurationDir("target/test-classes");
+
+ HttpClient.factory.build(
+ BusTopicParams.builder()
+ .clientName("lifecycle")
+ .hostname("localhost")
+ .port(8765)
+ .basePath("policy/pdp/engine/lifecycle")
+ .managed(true)
+ .build());
+
+ HttpServletServer server =
+ HttpServletServer.factory.build("lifecycle", "localhost", 8765, "/", true, true);
+ server.addServletClass("/*", RestLifecycleManager.class.getName());
+ server.setSerializationProvider("org.onap.policy.common.gson.JacksonHandler");
+ server.waitedStart(5000L);
+
+ Assert.assertTrue(NetworkUtil.isTcpPortOpen("localhost", 8765, 5, 10000L));
+
+ }
+
+ /**
+ * Tear down.
+ */
+ @After
+ public void tearDown() {
+ HttpServletServer.factory.destroy();
+ HttpClient.factory.destroy();
+ }
+
+ @Test
+ public void fsm() {
+ Response response = HttpClient.factory.get("lifecycle").get("fsm");
+ assertNotNull(HttpClient.getBody(response, String.class));
+ assertEquals(Status.OK.getStatusCode(), response.getStatus());
+
+ response = HttpClient.factory.get("lifecycle").get("fsm/state");
+ assertEquals(PdpState.TERMINATED, HttpClient.getBody(response, PdpState.class));
+ assertEquals(Status.OK.getStatusCode(), response.getStatus());
+ }
+}
\ No newline at end of file
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
import javax.ws.rs.core.Response.Status;
+import org.onap.policy.common.endpoints.event.comm.Topic.CommInfrastructure;
import org.onap.policy.common.endpoints.event.comm.TopicEndpoint;
import org.onap.policy.common.endpoints.event.comm.TopicSink;
import org.onap.policy.common.endpoints.event.comm.TopicSource;
public Response engineUpdate(
@ApiParam(value = "Configuration to apply", required = true) PdpdConfiguration configuration) {
final PolicyController controller = null;
- boolean success = true;
+ boolean success;
try {
success = PolicyEngine.manager.configure(configuration);
} catch (final Exception e) {
.entity(new Error(controllerName + " can't be started")).build();
}
} catch (final IllegalStateException e) {
- logger.info("{}: cannot start {} because of {}", this, controller, e.getMessage(), e);;
+ logger.info("{}: cannot start {} because of {}", this, controller, e.getMessage(), e);
return Response.status(Response.Status.PARTIAL_CONTENT).entity(controller).build();
}
}
/**
- * GET.
- *
- * @return response object
+ * GET a source.
*/
@GET
- @Path("engine/topics/sources/ueb/{topic}")
- @ApiOperation(value = "Retrieves an UEB managed topic source",
- notes = "This is an UEB Network Communicaton Endpoint source of messages for the Engine",
- response = UebTopicSource.class)
- public Response uebSourceTopic(@ApiParam(value = "Topic Name", required = true) @PathParam("topic") String topic) {
- return Response.status(Response.Status.OK).entity(TopicEndpoint.manager.getUebTopicSource(topic)).build();
+ @Path("engine/topics/sources/{comm: ueb|dmaap|noop}/{topic}")
+ @ApiOperation(value = "Retrieves a managed topic source",
+ notes = "This is an Network Communication Endpoint source of messages for the Engine",
+ response = TopicSource.class)
+ public Response sourceTopic(
+ @ApiParam(value = "Communication Mechanism", required = true) @PathParam("comm") String comm,
+ @ApiParam(value = "Topic Name", required = true) @PathParam("topic") String topic) {
+ return Response
+ .status(Response.Status.OK)
+ .entity(TopicEndpoint.manager
+ .getTopicSource(CommInfrastructure.valueOf(comm.toUpperCase()), topic))
+ .build();
}
/**
- * GET.
- *
- * @return response object
+ * GET a sink.
*/
@GET
- @Path("engine/topics/sinks/ueb/{topic}")
- @ApiOperation(value = "Retrieves an UEB managed topic sink",
- notes = "This is an UEB Network Communicaton Endpoint destination of messages from the Engine",
- response = UebTopicSink.class)
- public Response uebSinkTopic(@ApiParam(value = "Topic Name", required = true) @PathParam("topic") String topic) {
- return Response.status(Response.Status.OK).entity(TopicEndpoint.manager.getUebTopicSink(topic)).build();
+ @Path("engine/topics/sinks/{comm: ueb|dmaap|noop}/{topic}")
+ @ApiOperation(value = "Retrieves a managed topic sink",
+ notes = "This is a Network Communicaton Endpoint destination of messages from the Engine",
+ response = TopicSink.class)
+ public Response sinkTopic(
+ @ApiParam(value = "Communication Mechanism", required = true) @PathParam("comm") String comm,
+ @ApiParam(value = "Topic Name", required = true) @PathParam("topic") String topic) {
+ return Response
+ .status(Response.Status.OK)
+ .entity(TopicEndpoint.manager
+ .getTopicSink(CommInfrastructure.valueOf(comm.toUpperCase()), topic))
+ .build();
}
/**
- * GET.
- *
- * @return response object
+ * GET a source events.
*/
@GET
- @Path("engine/topics/sources/dmaap/{topic}")
- @ApiOperation(value = "Retrieves a DMaaP managed topic source",
- notes = "This is a DMaaP Network Communicaton Endpoint source of messages for the Engine",
- response = DmaapTopicSource.class)
- public Response dmaapSourceTopic(
- @ApiParam(value = "Topic Name", required = true) @PathParam("topic") String topic) {
- return Response.status(Response.Status.OK).entity(TopicEndpoint.manager.getDmaapTopicSource(topic)).build();
- }
-
- /**
- * GET.
- *
- * @return response object
- */
- @GET
- @Path("engine/topics/sinks/dmaap/{topic}")
- @ApiOperation(value = "Retrieves a DMaaP managed topic sink",
- notes = "This is a DMaaP Network Communicaton Endpoint destination of messages from the Engine",
- response = DmaapTopicSink.class)
- public Response dmaapSinkTopic(@ApiParam(value = "Topic Name", required = true) @PathParam("topic") String topic) {
- return Response.status(Response.Status.OK).entity(TopicEndpoint.manager.getDmaapTopicSink(topic)).build();
- }
-
- /**
- * GET.
- *
- * @return response object
- */
- @GET
- @Path("engine/topics/sources/ueb/{topic}/events")
+ @Path("engine/topics/sources/{comm: ueb|dmaap|noop}/{topic}/events")
@ApiOperation(value = "Retrieves the latest events received by an UEB topic",
- notes = "This is a UEB Network Communicaton Endpoint source of messages for the Engine",
- responseContainer = "List")
- public Response uebSourceEvents(@ApiParam(value = "Topic Name", required = true) @PathParam("topic") String topic) {
- return Response.status(Status.OK)
- .entity(Arrays.asList(TopicEndpoint.manager.getUebTopicSource(topic).getRecentEvents())).build();
- }
-
- /**
- * GET.
- *
- * @return response object
- */
- @GET
- @Path("engine/topics/sinks/ueb/{topic}/events")
- @ApiOperation(value = "Retrieves the latest events sent from a topic",
- notes = "This is a UEB Network Communicaton Endpoint sink of messages from the Engine",
+ notes = "This is a Network Communicaton Endpoint source of messages for the Engine",
responseContainer = "List")
- public Response uebSinkEvents(@ApiParam(value = "Topic Name", required = true) @PathParam("topic") String topic) {
+ public Response sourceEvents(
+ @ApiParam(value = "Communication Mechanism", required = true) @PathParam("comm") String comm,
+ @ApiParam(value = "Topic Name", required = true) @PathParam("topic") String topic) {
return Response.status(Status.OK)
- .entity(Arrays.asList(TopicEndpoint.manager.getUebTopicSink(topic).getRecentEvents())).build();
+ .entity(Arrays
+ .asList(TopicEndpoint.manager.getTopicSource(CommInfrastructure.valueOf(comm.toUpperCase()), topic)
+ .getRecentEvents()))
+ .build();
}
/**
- * GET.
- *
- * @return response object
+ * GET a sink events.
*/
@GET
- @Path("engine/topics/sources/dmaap/{topic}/events")
- @ApiOperation(value = "Retrieves the latest events received by a DMaaP topic",
- notes = "This is a DMaaP Network Communicaton Endpoint source of messages for the Engine",
- responseContainer = "List")
- public Response dmaapSourceEvents(
- @ApiParam(value = "Topic Name", required = true) @PathParam("topic") String topic) {
- return Response.status(Status.OK)
- .entity(Arrays.asList(TopicEndpoint.manager.getDmaapTopicSource(topic).getRecentEvents())).build();
- }
-
- /**
- * GET.
- *
- * @return response object
- */
- @GET
- @Path("engine/topics/sinks/dmaap/{topic}/events")
- @ApiOperation(value = "Retrieves the latest events send through a DMaaP topic",
- notes = "This is a DMaaP Network Communicaton Endpoint destination of messages from the Engine",
- responseContainer = "List")
- public Response dmaapSinkEvents(@PathParam("topic") String topic) {
+ @Path("engine/topics/sinks/{comm: ueb|dmaap|noop}/{topic}/events")
+ @ApiOperation(value = "Retrieves the latest events received by an UEB topic",
+ notes = "This is a Network Communicaton Endpoint source of messages for the Engine",
+ responseContainer = "List")
+ public Response sinkEvents(
+ @ApiParam(value = "Communication Mechanism", required = true) @PathParam("comm") String comm,
+ @ApiParam(value = "Topic Name", required = true) @PathParam("topic") String topic) {
return Response.status(Status.OK)
- .entity(Arrays.asList(TopicEndpoint.manager.getDmaapTopicSink(topic).getRecentEvents())).build();
+ .entity(Arrays
+ .asList(TopicEndpoint.manager.getTopicSink(CommInfrastructure.valueOf(comm.toUpperCase()), topic)
+ .getRecentEvents()))
+ .build();
}
/**
- * GET.
- *
- * @return response object
+ * GET noop sinks.
*/
@GET
@Path("engine/topics/sinks/noop")
return Response.status(Response.Status.OK).entity(TopicEndpoint.manager.getNoopTopicSinks()).build();
}
- /**
- * GET.
- *
- * @return response object
- */
- @GET
- @Path("engine/topics/sinks/noop/{topic}")
- @ApiOperation(value = "Retrieves a NOOP managed topic sink",
- notes = "NOOP is an dev/null Network Communicaton Sink", response = NoopTopicSink.class)
- public Response noopSinkTopic(@ApiParam(value = "Topic Name", required = true) @PathParam("topic") String topic) {
- return Response.status(Response.Status.OK).entity(TopicEndpoint.manager.getNoopTopicSink(topic)).build();
- }
-
- /**
- * GET.
- *
- * @return response object
- */
- @GET
- @Path("engine/topics/sinks/noop/{topic}/events")
- @ApiOperation(value = "Retrieves the latest events send through a NOOP topic",
- notes = "NOOP is an dev/null Network Communicaton Sink", responseContainer = "List")
- public Response noopSinkEvents(@PathParam("topic") String topic) {
- return Response.status(Status.OK)
- .entity(Arrays.asList(TopicEndpoint.manager.getNoopTopicSink(topic).getRecentEvents())).build();
- }
-
/**
* GET.
*
}
/**
- * PUT.
+ * Offers and event to a topic in a communication infrastructure.
*
* @return response object
*/
@PUT
- @Path("engine/topics/sources/ueb/{topic}/events")
+ @Path("engine/topics/sources/{comm: ueb|dmaap|noop}/{topic}/events")
@Consumes(MediaType.TEXT_PLAIN)
- @ApiOperation(value = "Offers an event to an UEB topic for internal processing by the engine",
+ @ApiOperation(value = "Offers an event to a topic for internal processing by the engine",
notes = "The offered event is treated as it was incoming from the network", responseContainer = "List")
@ApiResponses(value = {@ApiResponse(code = 404, message = "The topic information cannot be found"),
@ApiResponse(code = 406,
message = "The system is an administrative state that prevents " + "this request to be fulfilled"),
@ApiResponse(code = 500, message = "A server error has occurred processing this request")})
- public Response uebOffer(@ApiParam(value = "Topic Name", required = true) @PathParam("topic") String topic,
+ public Response commEventOffer(
+ @ApiParam(value = "Communication Mechanism", required = true) @PathParam("comm") String comm,
+ @ApiParam(value = "Topic Name", required = true) @PathParam("topic") String topic,
@ApiParam(value = "Network Message", required = true) String json) {
- try {
- final UebTopicSource uebReader = TopicEndpoint.manager.getUebTopicSource(topic);
- final boolean success = uebReader.offer(json);
- if (success) {
- return Response.status(Status.OK)
- .entity(Arrays.asList(TopicEndpoint.manager.getUebTopicSource(topic).getRecentEvents()))
- .build();
- } else {
- return Response.status(Status.NOT_ACCEPTABLE).entity(new Error("Failure to inject event over " + topic))
- .build();
- }
- } catch (final IllegalArgumentException e) {
- logNoUebEncoder(topic, e);
- return Response.status(Response.Status.NOT_FOUND).entity(new Error(topic + " not found")).build();
- } catch (final IllegalStateException e) {
- logNoUebEncoder(topic, e);
- return Response.status(Response.Status.NOT_ACCEPTABLE)
- .entity(new Error(topic + " not acceptable due to current state")).build();
- } catch (final Exception e) {
- logNoUebEncoder(topic, e);
- return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(new Error(e.getMessage())).build();
- }
- }
-
- private void logNoUebEncoder(String topic, Exception ex) {
- logger.debug("{}: cannot offer for encoder ueb topic for {} because of {}", this, topic, ex.getMessage(), ex);
- }
- /**
- * PUT.
- *
- * @return response object
- */
- @PUT
- @Path("engine/topics/sources/dmaap/{topic}/events")
- @Consumes(MediaType.TEXT_PLAIN)
- @ApiOperation(value = "Offers an event to a DMaaP topic for internal processing by the engine",
- notes = "The offered event is treated as it was incoming from the network", responseContainer = "List")
- @ApiResponses(value = {@ApiResponse(code = 404, message = "The topic information cannot be found"),
- @ApiResponse(code = 406,
- message = "The system is an administrative state that prevents " + "this request to be fulfilled"),
- @ApiResponse(code = 500, message = "A server error has occurred processing this request")})
- public Response dmaapOffer(@ApiParam(value = "Topic Name", required = true) @PathParam("topic") String topic,
- @ApiParam(value = "Network Message", required = true) String json) {
try {
- final DmaapTopicSource dmaapReader = TopicEndpoint.manager.getDmaapTopicSource(topic);
- final boolean success = dmaapReader.offer(json);
- if (success) {
+ TopicSource source =
+ TopicEndpoint.manager.getTopicSource(CommInfrastructure.valueOf(comm.toUpperCase()), topic);
+ if (source.offer(json)) {
return Response.status(Status.OK)
- .entity(Arrays.asList(TopicEndpoint.manager.getDmaapTopicSource(topic).getRecentEvents()))
- .build();
+ .entity(Arrays.asList(source.getRecentEvents()))
+ .build();
} else {
- return Response.status(Status.NOT_ACCEPTABLE).entity(new Error("Failure to inject event over " + topic))
- .build();
+ return Response.status(Status.NOT_ACCEPTABLE)
+ .entity(new Error("Failure to inject event over " + topic))
+ .build();
}
- } catch (final IllegalArgumentException e) {
- logNoDmaapEncoder(topic, e);
- return Response.status(Response.Status.NOT_FOUND).entity(new Error(topic + " not found")).build();
- } catch (final IllegalStateException e) {
- logNoDmaapEncoder(topic, e);
+ } catch (IllegalArgumentException e) {
+ return Response.status(Response.Status.NOT_FOUND)
+ .entity(new Error(topic + " not found")).build();
+ } catch (IllegalStateException e) {
return Response.status(Response.Status.NOT_ACCEPTABLE)
- .entity(new Error(topic + " not acceptable due to current state")).build();
- } catch (final Exception e) {
- logNoDmaapEncoder(topic, e);
- return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(new Error(e.getMessage())).build();
+ .entity(new Error(topic + " not acceptable due to current state"))
+ .build();
+ } catch (Exception e) {
+ return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(new Error(e.getMessage()))
+ .build();
}
}
- private void logNoDmaapEncoder(String topic, Exception ex) {
- logger.debug("{}: cannot offer for encoder dmaap topic for {} because of {}", this, topic, ex.getMessage(), ex);
- }
-
/**
* GET.
*
try {
newLevel = LoggerUtil.setLevel(loggerName, loggerLevel);
} catch (final IllegalArgumentException e) {
- logger.warn("{}: no logger {}", this, loggerName, loggerLevel, e);
+ logger.warn("{}: invalid operation for logger {} and level {}", this, loggerName, loggerLevel, e);
return Response.status(Status.NOT_FOUND).build();
} catch (final IllegalStateException e) {
logger.warn("{}: logging framework unavailable for {} / {}", this, loggerName, loggerLevel, e);
@Override
public String toString() {
- final StringBuilder builder = new StringBuilder();
- builder.append("rest-telemetry-api []");
- return builder.toString();
+ return "rest-telemetry-api []";
}
/**
* ============LICENSE_START=======================================================
* policy-management
* ================================================================================
- * Copyright (C) 2017-2018 AT&T Intellectual Property. All rights reserved.
+ * Copyright (C) 2017-2019 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.
private static final String DMAAP_SINK_PASSWD_KEY = PolicyEndPointProperties.PROPERTY_DMAAP_SINK_TOPICS + "."
+ DMAAP_TOPIC + PolicyEndPointProperties.PROPERTY_TOPIC_AAF_PASSWORD_SUFFIX;
-
private static final String FOO_CONTROLLER_FILE = FOO_CONTROLLER + "-controller.properties";
private static final String FOO_CONTROLLER_FILE_BAK = FOO_CONTROLLER_FILE + ".bak";
engineProps.put(DMAAP_SOURCE_PASSWD_KEY, DMAAP_PASSWD);
engineProps.put(DMAAP_SINK_MECHID_KEY, DMAAP_MECHID);
engineProps.put(DMAAP_SINK_PASSWD_KEY, DMAAP_PASSWD);
- engineProps.put(PolicyEndPointProperties.PROPERTY_NOOP_SINK_TOPICS, NOOP_TOPIC);
PolicyEngine.manager.configure(engineProps);
PolicyEngine.manager.start();
if (!NetworkUtil.isTcpPortOpen("localhost", DEFAULT_TELEMETRY_PORT, 5, 10000L)) {
throw new IllegalStateException("cannot connect to port " + DEFAULT_TELEMETRY_PORT);
}
+
+ Properties noopProperties = new Properties();
+ noopProperties.put(PolicyEndPointProperties.PROPERTY_NOOP_SOURCE_TOPICS, NOOP_TOPIC);
+ noopProperties.put(PolicyEndPointProperties.PROPERTY_NOOP_SINK_TOPICS, NOOP_TOPIC);
+ TopicEndpoint.manager.addTopics(noopProperties);
}
/**
httpDelete.releaseConnection();
/*
- * PUT: /engine/topics/sources/ueb/topic/events /engine/topics/sources/dmaap/topic/events
- * /engine/topics/switches/lock DELETE: /engine/topics/switches/lock
+ * PUT: /engine/topics/sources/ueb/topic/events
+ * /engine/topics/sources/dmaap/topic/events
+ * /engine/topics/switches/lock
+ *
+ * DELETE: /engine/topics/switches/lock
*/
httpPut = new HttpPut(HOST_URL + "/engine/topics/sources/ueb/" + UEB_TOPIC + "/events");
httpPut.addHeader("Content-Type", "text/plain");
httpPut.addHeader("Accept", "application/json");
- httpPut.setEntity(new StringEntity("FOOOO"));
+ httpPut.setEntity(new StringEntity("{x:y}"));
+ response = client.execute(httpPut);
+ logger.info(httpPut.getRequestLine() + " response code: {}", response.getStatusLine().getStatusCode());
+ assertEquals(200, response.getStatusLine().getStatusCode());
+ httpPut.releaseConnection();
+
+ httpPut = new HttpPut(HOST_URL + "/engine/topics/sources/noop/" + NOOP_TOPIC + "/events");
+ httpPut.addHeader("Content-Type", "text/plain");
+ httpPut.addHeader("Accept", "application/json");
+ httpPut.setEntity(new StringEntity("{x:y}"));
response = client.execute(httpPut);
logger.info(httpPut.getRequestLine() + " response code: {}", response.getStatusLine().getStatusCode());
assertEquals(200, response.getStatusLine().getStatusCode());