Search in sources :

Example 1 with TopologyStatus

use of org.apache.metron.rest.model.TopologyStatus in project metron by apache.

the class StormStatusServiceImplTest method activateTopologyShouldReturnActiveTopologyResponse.

@Test
public void activateTopologyShouldReturnActiveTopologyResponse() throws Exception {
    final TopologyStatus topologyStatus = new TopologyStatus();
    topologyStatus.setName("bro");
    topologyStatus.setId("bro_id");
    final TopologySummary topologySummary = new TopologySummary();
    topologySummary.setTopologies(new TopologyStatus[] { topologyStatus });
    when(environment.getProperty(STORM_UI_SPRING_PROPERTY)).thenReturn(HTTP_STORM_UI);
    when(restTemplate.getForObject(HTTP_STORM_UI + TOPOLOGY_SUMMARY_URL, TopologySummary.class)).thenReturn(topologySummary);
    when(restTemplate.postForObject(HTTP_STORM_UI + TOPOLOGY_URL + "/bro_id/activate", null, Map.class)).thenReturn(new HashMap() {

        {
            put("status", "success");
        }
    });
    TopologyResponse expected = new TopologyResponse();
    expected.setSuccessMessage(TopologyStatusCode.ACTIVE.toString());
    assertEquals(expected, stormStatusService.activateTopology("bro"));
}
Also used : HashMap(java.util.HashMap) TopologyResponse(org.apache.metron.rest.model.TopologyResponse) TopologySummary(org.apache.metron.rest.model.TopologySummary) TopologyStatus(org.apache.metron.rest.model.TopologyStatus) Test(org.junit.jupiter.api.Test)

Example 2 with TopologyStatus

use of org.apache.metron.rest.model.TopologyStatus in project metron by apache.

the class StormStatusServiceImplTest method deactivateTopologyShouldReturnErrorTopologyResponse.

@Test
public void deactivateTopologyShouldReturnErrorTopologyResponse() throws Exception {
    final TopologyStatus topologyStatus = new TopologyStatus();
    topologyStatus.setName("bro");
    topologyStatus.setId("bro_id");
    final TopologySummary topologySummary = new TopologySummary();
    topologySummary.setTopologies(new TopologyStatus[] { topologyStatus });
    when(environment.getProperty(STORM_UI_SPRING_PROPERTY)).thenReturn(HTTP_STORM_UI);
    when(restTemplate.getForObject(HTTP_STORM_UI + TOPOLOGY_SUMMARY_URL, TopologySummary.class)).thenReturn(topologySummary);
    when(restTemplate.postForObject(HTTP_STORM_UI + TOPOLOGY_URL + "/bro_id/deactivate", null, Map.class)).thenReturn(new HashMap() {

        {
            put("status", "error message");
        }
    });
    TopologyResponse expected = new TopologyResponse();
    expected.setErrorMessage("error message");
    assertEquals(expected, stormStatusService.deactivateTopology("bro"));
}
Also used : HashMap(java.util.HashMap) TopologyResponse(org.apache.metron.rest.model.TopologyResponse) TopologySummary(org.apache.metron.rest.model.TopologySummary) TopologyStatus(org.apache.metron.rest.model.TopologyStatus) Test(org.junit.jupiter.api.Test)

Example 3 with TopologyStatus

use of org.apache.metron.rest.model.TopologyStatus in project metron by apache.

the class StormStatusServiceImplTest method activateTopologyShouldReturnErrorTopologyResponse.

@Test
public void activateTopologyShouldReturnErrorTopologyResponse() throws Exception {
    final TopologyStatus topologyStatus = new TopologyStatus();
    topologyStatus.setName("bro");
    topologyStatus.setId("bro_id");
    final TopologySummary topologySummary = new TopologySummary();
    topologySummary.setTopologies(new TopologyStatus[] { topologyStatus });
    when(environment.getProperty(STORM_UI_SPRING_PROPERTY)).thenReturn(HTTP_STORM_UI);
    when(restTemplate.getForObject(HTTP_STORM_UI + TOPOLOGY_SUMMARY_URL, TopologySummary.class)).thenReturn(topologySummary);
    when(restTemplate.postForObject(HTTP_STORM_UI + TOPOLOGY_URL + "/bro_id/activate", null, Map.class)).thenReturn(new HashMap() {

        {
            put("status", "error message");
        }
    });
    TopologyResponse expected = new TopologyResponse();
    expected.setErrorMessage("error message");
    assertEquals(expected, stormStatusService.activateTopology("bro"));
}
Also used : HashMap(java.util.HashMap) TopologyResponse(org.apache.metron.rest.model.TopologyResponse) TopologySummary(org.apache.metron.rest.model.TopologySummary) TopologyStatus(org.apache.metron.rest.model.TopologyStatus) Test(org.junit.jupiter.api.Test)

Example 4 with TopologyStatus

use of org.apache.metron.rest.model.TopologyStatus in project metron by apache.

the class StormStatusServiceImplTest method deactivateTopologyShouldReturnActiveTopologyResponse.

@Test
public void deactivateTopologyShouldReturnActiveTopologyResponse() throws Exception {
    final TopologyStatus topologyStatus = new TopologyStatus();
    topologyStatus.setName("bro");
    topologyStatus.setId("bro_id");
    final TopologySummary topologySummary = new TopologySummary();
    topologySummary.setTopologies(new TopologyStatus[] { topologyStatus });
    when(environment.getProperty(STORM_UI_SPRING_PROPERTY)).thenReturn(HTTP_STORM_UI);
    when(restTemplate.getForObject(HTTP_STORM_UI + TOPOLOGY_SUMMARY_URL, TopologySummary.class)).thenReturn(topologySummary);
    when(restTemplate.postForObject(HTTP_STORM_UI + TOPOLOGY_URL + "/bro_id/deactivate", null, Map.class)).thenReturn(new HashMap() {

        {
            put("status", "success");
        }
    });
    TopologyResponse expected = new TopologyResponse();
    expected.setSuccessMessage(TopologyStatusCode.INACTIVE.toString());
    assertEquals(expected, stormStatusService.deactivateTopology("bro"));
}
Also used : HashMap(java.util.HashMap) TopologyResponse(org.apache.metron.rest.model.TopologyResponse) TopologySummary(org.apache.metron.rest.model.TopologySummary) TopologyStatus(org.apache.metron.rest.model.TopologyStatus) Test(org.junit.jupiter.api.Test)

Example 5 with TopologyStatus

use of org.apache.metron.rest.model.TopologyStatus in project metron by apache.

the class StormAdminServiceImpl method stopParserTopology.

/**
 * Stops a parser topology.  The name should either be a sensor name or group name in the case of aggregate parser topologies.
 * @param name SensorParserConfig or SensorParserGroup name
 * @param stopNow Stop the topology immediately
 * @return ToplogyResponse
 * @throws RestException Stopping the topology resulted in an error.
 */
@Override
public TopologyResponse stopParserTopology(String name, boolean stopNow) throws RestException {
    // Supplied name could be a group so get the actual job name from Storm
    TopologyStatus topologyStatus = stormStatusService.getTopologyStatus(name);
    String jobName = topologyStatus != null ? topologyStatus.getName() : name;
    return createResponse(stormCLIClientWrapper.stopParserTopology(jobName, stopNow), TopologyStatusCode.STOPPED, TopologyStatusCode.STOP_ERROR);
}
Also used : TopologyStatus(org.apache.metron.rest.model.TopologyStatus)

Aggregations

TopologyStatus (org.apache.metron.rest.model.TopologyStatus)12 Test (org.junit.jupiter.api.Test)9 TopologySummary (org.apache.metron.rest.model.TopologySummary)8 TopologyResponse (org.apache.metron.rest.model.TopologyResponse)5 HashMap (java.util.HashMap)4 SensorParserGroup (org.apache.metron.common.configuration.SensorParserGroup)2 ArrayList (java.util.ArrayList)1 HashSet (java.util.HashSet)1