Search in sources :

Example 1 with BusinessServiceResponseDTO

use of org.opennms.web.rest.v2.bsm.model.BusinessServiceResponseDTO in project opennms by OpenNMS.

the class AbstractBusinessServiceRestServiceIT method canRetrieveBusinessServices.

@Test
public void canRetrieveBusinessServices() throws Exception {
    // Add business services to the DB
    BusinessServiceEntity bs = new BusinessServiceEntityBuilder().name("Application Servers").addReductionKey("MyReductionKey", new IdentityEntity()).reduceFunction(new HighestSeverityEntity()).toEntity();
    Long id = m_businessServiceDao.save(bs);
    m_businessServiceDao.flush();
    // Retrieve the list of business services
    List<ResourceLocation> businessServices = listBusinessServices();
    // Verify
    Assert.assertEquals(1, businessServices.size());
    BusinessServiceResponseDTO expectedResponseDTO = toResponseDto(bs);
    BusinessServiceResponseDTO actualResponseDTO = getAndUnmarshal(buildServiceUrl(id), 200, BusinessServiceResponseDTO.class);
    Assert.assertEquals(expectedResponseDTO, actualResponseDTO);
    verifyReductionKey("MyReductionKey", actualResponseDTO);
}
Also used : BusinessServiceResponseDTO(org.opennms.web.rest.v2.bsm.model.BusinessServiceResponseDTO) ResourceLocation(org.opennms.web.rest.api.ResourceLocation) BusinessServiceEntity(org.opennms.netmgt.bsm.persistence.api.BusinessServiceEntity) HighestSeverityEntity(org.opennms.netmgt.bsm.persistence.api.functions.reduce.HighestSeverityEntity) BusinessServiceEntityBuilder(org.opennms.netmgt.bsm.test.BusinessServiceEntityBuilder) IdentityEntity(org.opennms.netmgt.bsm.persistence.api.functions.map.IdentityEntity) Test(org.junit.Test)

Example 2 with BusinessServiceResponseDTO

use of org.opennms.web.rest.v2.bsm.model.BusinessServiceResponseDTO in project opennms by OpenNMS.

the class AbstractBusinessServiceRestServiceIT method verifyFriendlyName.

@Test
public void verifyFriendlyName() throws Exception {
    BusinessServiceEntity entity = new BusinessServiceEntityBuilder().name("Some Custom Name").addReductionKey("My Reduction Key", new IdentityEntity(), "so friendly").reduceFunction(new HighestSeverityEntity()).toEntity();
    sendData(POST, getMediaType(), "/business-services", marshal(toRequestDto(entity)), 201);
    BusinessServiceResponseDTO responseDTO = verifyResponse(findEntityByName("Some Custom Name"));
    Assert.assertEquals(1, responseDTO.getReductionKeys().size());
    Assert.assertEquals("so friendly", responseDTO.getReductionKeys().get(0).getFriendlyName());
}
Also used : BusinessServiceResponseDTO(org.opennms.web.rest.v2.bsm.model.BusinessServiceResponseDTO) BusinessServiceEntity(org.opennms.netmgt.bsm.persistence.api.BusinessServiceEntity) HighestSeverityEntity(org.opennms.netmgt.bsm.persistence.api.functions.reduce.HighestSeverityEntity) BusinessServiceEntityBuilder(org.opennms.netmgt.bsm.test.BusinessServiceEntityBuilder) IdentityEntity(org.opennms.netmgt.bsm.persistence.api.functions.map.IdentityEntity) Test(org.junit.Test)

Example 3 with BusinessServiceResponseDTO

use of org.opennms.web.rest.v2.bsm.model.BusinessServiceResponseDTO in project opennms by OpenNMS.

the class BusinessServiceResponseDTOMarshalTest method data.

@Parameterized.Parameters
public static Collection<Object[]> data() throws IOException {
    final MapFunctionDTO ignoreDto = createMapFunctionDTO(new Ignore());
    final BusinessServiceResponseDTO bs = new BusinessServiceResponseDTO();
    bs.setId(1L);
    bs.setName("Web Servers");
    bs.addAttribute("dc", "RDU");
    bs.setLocation(new ResourceLocation(ApiVersion.Version2, "business-services", "1"));
    bs.setOperationalStatus(Status.CRITICAL);
    bs.setReduceFunction(createReduceFunctionDTO(new HighestSeverity()));
    bs.getReductionKeys().add(createReductionKeyEdgeResponse(1L, "myReductionKeyA", ignoreDto, Status.CRITICAL, new ResourceLocation(ApiVersion.Version2, "test/1"), "reduction-key-a-friendly-name"));
    bs.getReductionKeys().add(createReductionKeyEdgeResponse(2L, "myReductionKeyB", ignoreDto, Status.NORMAL, new ResourceLocation(ApiVersion.Version2, "test/2"), "reduction-key-b-friendly-name"));
    bs.getChildren().add(createChildEdgeResponse(3L, 2L, ignoreDto, Status.MAJOR, new ResourceLocation(ApiVersion.Version2, "test/3")));
    bs.getChildren().add(createChildEdgeResponse(4L, 3L, ignoreDto, Status.MAJOR, new ResourceLocation(ApiVersion.Version2, "test/4")));
    bs.getIpServices().add(createIpServiceEdgeResponse(5L, createIpServiceResponse(), ignoreDto, Status.MINOR, new ResourceLocation(ApiVersion.Version2, "test/5"), "ip-service-friendly-name"));
    bs.getParentServices().add(11L);
    bs.getParentServices().add(12L);
    return Arrays.asList(new Object[][] { { BusinessServiceResponseDTO.class, bs, "{" + "  \"location\" : \"/api/v2/business-services/1\"," + "  \"name\" : \"Web Servers\"," + "  \"id\" : 1," + "  \"attributes\" : {" + "    \"attribute\" : [ {" + "      \"key\" : \"dc\"," + "      \"value\" : \"RDU\"" + "    } ]" + "  }," + "  \"operational-status\" : \"CRITICAL\"," + "  \"reduce-function\" : {" + "    \"type\" : \"HighestSeverity\"," + "    \"properties\" : { }" + "  }," + "  \"reduction-key-edges\" : [ {" + "    \"id\" : 1," + "    \"operational-status\" : \"CRITICAL\"," + "    \"map-function\" : {" + "      \"type\" : \"Ignore\"," + "      \"properties\" : { }" + "    }," + "    \"weight\" : 9," + "    \"location\" : \"/api/v2/test/1\"," + "    \"reduction-keys\" : [ \"myReductionKeyA\" ]," + "    \"friendly-name\" : \"reduction-key-a-friendly-name\"" + "  }, {" + "    \"id\" : 2," + "    \"operational-status\" : \"NORMAL\"," + "    \"map-function\" : {" + "      \"type\" : \"Ignore\"," + "      \"properties\" : { }" + "    }," + "    \"weight\" : 9," + "    \"location\" : \"/api/v2/test/2\"," + "    \"reduction-keys\" : [ \"myReductionKeyB\" ]," + "    \"friendly-name\" : \"reduction-key-b-friendly-name\"" + "  } ]," + "  \"child-edges\" : [ {" + "    \"id\" : 3," + "    \"operational-status\" : \"MAJOR\"," + "    \"map-function\" : {" + "      \"type\" : \"Ignore\"," + "      \"properties\" : { }" + "    }," + "    \"weight\" : 7," + "    \"location\" : \"/api/v2/test/3\"," + "    \"reduction-keys\" : [ ]," + "    \"child-id\" : 2" + "  }, {" + "    \"id\" : 4," + "    \"operational-status\" : \"MAJOR\"," + "    \"map-function\" : {" + "      \"type\" : \"Ignore\"," + "      \"properties\" : { }" + "    }," + "    \"weight\" : 7," + "    \"location\" : \"/api/v2/test/4\"," + "    \"reduction-keys\" : [ ]," + "    \"child-id\" : 3" + "  } ]," + "  \"ip-service-edges\" : [ {" + "    \"id\" : 5," + "    \"operational-status\" : \"MINOR\"," + "    \"map-function\" : {" + "      \"type\" : \"Ignore\"," + "      \"properties\" : { }" + "    }," + "    \"weight\" : 5," + "    \"location\" : \"/api/v2/test/5\"," + "    \"reduction-keys\" : [ \"key1\", \"key2\" ]," + "    \"ip-service\" : {" + "      \"location\" : \"/api/v2/business-services/ip-services/17\"," + "      \"id\" : 17," + "      \"node-label\" : \"dummy\"," + "      \"service-name\" : \"ICMP\"," + "      \"ip-address\" : \"1.1.1.1\"" + "    }," + "    \"friendly-name\" : \"ip-service-friendly-name\"" + "  } ]," + "  \"parent-services\" : [ 11, 12 ]" + "}", "<business-service>\n" + "   <id>1</id>\n" + "   <name>Web Servers</name>\n" + "   <attributes>\n" + "      <attribute>\n" + "         <key>dc</key>\n" + "         <value>RDU</value>\n" + "      </attribute>\n" + "   </attributes>\n" + "   <ip-service-edges>\n" + "      <ip-service-edge>\n" + "         <id>5</id>\n" + "         <operational-status>MINOR</operational-status>\n" + "         <map-function>\n" + "            <type>Ignore</type>\n" + "         </map-function>\n" + "         <location>/api/v2/test/5</location>\n" + "         <reduction-keys>\n" + "            <reduction-key>key1</reduction-key>\n" + "            <reduction-key>key2</reduction-key>\n" + "         </reduction-keys>\n" + "         <weight>5</weight>\n" + "         <ip-service>\n" + "            <id>17</id>\n" + "            <service-name>ICMP</service-name>\n" + "            <node-label>dummy</node-label>\n" + "            <ip-address>1.1.1.1</ip-address>\n" + "            <location>/api/v2/business-services/ip-services/17</location>\n" + "         </ip-service>\n" + "         <friendly-name>ip-service-friendly-name</friendly-name>\n" + "      </ip-service-edge>\n" + "   </ip-service-edges>\n" + "   <reduction-key-edges>\n" + "      <reduction-key-edge>\n" + "         <id>1</id>\n" + "         <operational-status>CRITICAL</operational-status>\n" + "         <map-function>\n" + "            <type>Ignore</type>\n" + "         </map-function>\n" + "         <location>/api/v2/test/1</location>\n" + "         <reduction-keys>\n" + "            <reduction-key>myReductionKeyA</reduction-key>\n" + "         </reduction-keys>\n" + "         <weight>9</weight>\n" + "         <friendly-name>reduction-key-a-friendly-name</friendly-name>\n" + "      </reduction-key-edge>\n" + "      <reduction-key-edge>\n" + "         <id>2</id>\n" + "         <operational-status>NORMAL</operational-status>\n" + "         <map-function>\n" + "            <type>Ignore</type>\n" + "         </map-function>\n" + "         <location>/api/v2/test/2</location>\n" + "         <reduction-keys>\n" + "            <reduction-key>myReductionKeyB</reduction-key>\n" + "         </reduction-keys>\n" + "         <weight>9</weight>\n" + "         <friendly-name>reduction-key-b-friendly-name</friendly-name>\n" + "      </reduction-key-edge>\n" + "   </reduction-key-edges>\n" + "   <child-edges>\n" + "      <child-edge>\n" + "         <id>3</id>\n" + "         <operational-status>MAJOR</operational-status>\n" + "         <map-function>\n" + "            <type>Ignore</type>\n" + "         </map-function>\n" + "         <location>/api/v2/test/3</location>\n" + "         <reduction-keys/>\n" + "         <weight>7</weight>\n" + "         <child-id>2</child-id>\n" + "      </child-edge>\n" + "      <child-edge>\n" + "         <id>4</id>\n" + "         <operational-status>MAJOR</operational-status>\n" + "         <map-function>\n" + "            <type>Ignore</type>\n" + "         </map-function>\n" + "         <location>/api/v2/test/4</location>\n" + "         <reduction-keys/>\n" + "         <weight>7</weight>\n" + "         <child-id>3</child-id>\n" + "      </child-edge>\n" + "   </child-edges>\n" + "   <parent-services>\n" + "      <parent-service>11</parent-service>\n" + "      <parent-service>12</parent-service>\n" + "   </parent-services>\n" + "   <reduce-function>\n" + "      <type>HighestSeverity</type>\n" + "   </reduce-function>\n" + "   <operational-status>CRITICAL</operational-status>\n" + "   <location>/api/v2/business-services/1</location>\n" + "</business-service>" } });
}
Also used : Ignore(org.opennms.netmgt.bsm.service.model.functions.map.Ignore) TestHelper.createMapFunctionDTO(org.opennms.web.rest.v2.bsm.model.TestHelper.createMapFunctionDTO) HighestSeverity(org.opennms.netmgt.bsm.service.model.functions.reduce.HighestSeverity) ResourceLocation(org.opennms.web.rest.api.ResourceLocation)

Example 4 with BusinessServiceResponseDTO

use of org.opennms.web.rest.v2.bsm.model.BusinessServiceResponseDTO in project opennms by OpenNMS.

the class BusinessServiceRestService method getById.

@GET
@Path("{id}")
public Response getById(@PathParam("id") Long id) {
    BusinessService service = getManager().getBusinessServiceById(id);
    final BusinessServiceResponseDTO response = new BusinessServiceResponseDTO();
    response.setId(service.getId());
    response.setName(service.getName());
    response.setAttributes(service.getAttributes());
    response.setLocation(ResourceLocationFactory.createBusinessServiceLocation(service.getId().toString()));
    response.setParentServices(service.getParentServices().stream().map(BusinessService::getId).collect(Collectors.toSet()));
    response.setOperationalStatus(service.getOperationalStatus());
    response.setReduceFunction(transform(service.getReduceFunction()));
    service.getEdges().forEach(eachEdge -> eachEdge.accept(new EdgeVisitor<Void>() {

        @Override
        public Void visit(IpServiceEdge edge) {
            response.getIpServices().add(transform(edge));
            return null;
        }

        @Override
        public Void visit(ReductionKeyEdge edge) {
            response.getReductionKeys().add(transform(edge));
            return null;
        }

        @Override
        public Void visit(ChildEdge edge) {
            response.getChildren().add(transform(edge));
            return null;
        }
    }));
    return Response.ok(response).build();
}
Also used : BusinessService(org.opennms.netmgt.bsm.service.model.BusinessService) BusinessServiceResponseDTO(org.opennms.web.rest.v2.bsm.model.BusinessServiceResponseDTO) ChildEdge(org.opennms.netmgt.bsm.service.model.edge.ChildEdge) IpServiceEdge(org.opennms.netmgt.bsm.service.model.edge.IpServiceEdge) EdgeVisitor(org.opennms.netmgt.bsm.service.model.edge.EdgeVisitor) ReductionKeyEdge(org.opennms.netmgt.bsm.service.model.edge.ReductionKeyEdge) Path(javax.ws.rs.Path) GET(javax.ws.rs.GET)

Example 5 with BusinessServiceResponseDTO

use of org.opennms.web.rest.v2.bsm.model.BusinessServiceResponseDTO in project opennms by OpenNMS.

the class AbstractBusinessServiceRestServiceIT method canCreateBusinessService.

@Test
public void canCreateBusinessService() throws Exception {
    final BusinessServiceEntity bs = new BusinessServiceEntityBuilder().name("some-service").addAttribute("some-key", "some-value").reduceFunction(new HighestSeverityEntity()).addReductionKey("reductionKey-1", new IdentityEntity()).addReductionKey("reductionKey-2", new IdentityEntity()).addReductionKey("reductionKey-3", new IdentityEntity()).toEntity();
    sendData(POST, getMediaType(), "/business-services", marshal(toRequestDto(bs)), 201);
    Assert.assertEquals(1, m_businessServiceDao.countAll());
    for (BusinessServiceEntity eachEntity : m_businessServiceDao.findAll()) {
        BusinessServiceResponseDTO responseDTO = verifyResponse(eachEntity);
        Assert.assertEquals(3, responseDTO.getReductionKeys().size());
    }
}
Also used : BusinessServiceResponseDTO(org.opennms.web.rest.v2.bsm.model.BusinessServiceResponseDTO) BusinessServiceEntity(org.opennms.netmgt.bsm.persistence.api.BusinessServiceEntity) HighestSeverityEntity(org.opennms.netmgt.bsm.persistence.api.functions.reduce.HighestSeverityEntity) BusinessServiceEntityBuilder(org.opennms.netmgt.bsm.test.BusinessServiceEntityBuilder) IdentityEntity(org.opennms.netmgt.bsm.persistence.api.functions.map.IdentityEntity) Test(org.junit.Test)

Aggregations

BusinessServiceResponseDTO (org.opennms.web.rest.v2.bsm.model.BusinessServiceResponseDTO)7 Test (org.junit.Test)4 BusinessServiceEntity (org.opennms.netmgt.bsm.persistence.api.BusinessServiceEntity)4 IdentityEntity (org.opennms.netmgt.bsm.persistence.api.functions.map.IdentityEntity)4 HighestSeverityEntity (org.opennms.netmgt.bsm.persistence.api.functions.reduce.HighestSeverityEntity)4 BusinessServiceEntityBuilder (org.opennms.netmgt.bsm.test.BusinessServiceEntityBuilder)4 Ignore (org.opennms.netmgt.bsm.service.model.functions.map.Ignore)2 ResourceLocation (org.opennms.web.rest.api.ResourceLocation)2 GET (javax.ws.rs.GET)1 Path (javax.ws.rs.Path)1 BusinessService (org.opennms.netmgt.bsm.service.model.BusinessService)1 ChildEdge (org.opennms.netmgt.bsm.service.model.edge.ChildEdge)1 EdgeVisitor (org.opennms.netmgt.bsm.service.model.edge.EdgeVisitor)1 IpServiceEdge (org.opennms.netmgt.bsm.service.model.edge.IpServiceEdge)1 ReductionKeyEdge (org.opennms.netmgt.bsm.service.model.edge.ReductionKeyEdge)1 HighestSeverity (org.opennms.netmgt.bsm.service.model.functions.reduce.HighestSeverity)1 BusinessServiceRequestDTO (org.opennms.web.rest.v2.bsm.model.BusinessServiceRequestDTO)1 TestHelper.createMapFunctionDTO (org.opennms.web.rest.v2.bsm.model.TestHelper.createMapFunctionDTO)1 FunctionsManager (org.opennms.web.rest.v2.bsm.model.meta.FunctionsManager)1