Search in sources :

Example 11 with AssetIPMapping

use of com.vmware.flowgate.common.model.AssetIPMapping in project flowgate by vmware.

the class AssetController method updateHostNameIPMapping.

@ResponseStatus(HttpStatus.OK)
@RequestMapping(value = "/mapping/hostnameip", method = RequestMethod.PUT)
public void updateHostNameIPMapping(@RequestBody AssetIPMapping mapping) {
    Optional<AssetIPMapping> oldMappingOptional = assetIPMappingRepository.findById(mapping.getId());
    if (!oldMappingOptional.isPresent()) {
        throw new WormholeRequestException(HttpStatus.INTERNAL_SERVER_ERROR, "Can't find any mapping with the id: " + mapping.getId(), null);
    }
    AssetIPMapping oldMapping = oldMappingOptional.get();
    String assetName = mapping.getAssetname();
    String macAddress = mapping.getMacAddress();
    if (StringUtils.equals(oldMapping.getAssetname(), assetName)) {
        if (StringUtils.equals(macAddress, oldMapping.getMacAddress())) {
            return;
        }
    }
    if (!assetService.isAssetNameValidate(assetName)) {
        throw new WormholeRequestException(HttpStatus.INTERNAL_SERVER_ERROR, "Can't find any asset with the name : " + mapping.getAssetname(), null);
    }
    oldMapping.setAssetname(mapping.getAssetname());
    oldMapping.setMacAddress(mapping.getMacAddress());
    assetIPMappingRepository.save(oldMapping);
}
Also used : WormholeRequestException(com.vmware.flowgate.exception.WormholeRequestException) AssetIPMapping(com.vmware.flowgate.common.model.AssetIPMapping) ResponseStatus(org.springframework.web.bind.annotation.ResponseStatus) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 12 with AssetIPMapping

use of com.vmware.flowgate.common.model.AssetIPMapping in project flowgate by vmware.

the class InfobloxServiceTest method testExecuteAsyncInvokeRecordHost.

@Test
public void testExecuteAsyncInvokeRecordHost() {
    EventMessage eventMessage = EventMessageUtil.createEventMessage(EventType.InfoBlox, null, "10.161.71.154");
    ResponseEntity<FacilitySoftwareConfig[]> infobloxFacilitySoftware = this.getInfobloxFacilitySoftware();
    Mockito.doReturn(this.getInfoBloxIPInfoResults()).when(infobloxClient).queryHostRecordByIP(Mockito.anyString());
    Mockito.doReturn(new ResponseEntity<>(new Asset(), HttpStatus.OK)).when(wormholeAPIClient).getAssetByName(Mockito.anyString());
    Mockito.doReturn(infobloxFacilitySoftware).when(wormholeAPIClient).getFacilitySoftwareInternalByType(FacilitySoftwareConfig.SoftwareType.InfoBlox);
    Mockito.doReturn(new ResponseEntity<>(new AssetIPMapping[0], HttpStatus.OK)).when(wormholeAPIClient).getHostnameIPMappingByIP(Mockito.anyString());
    infoBloxService.executeAsync(eventMessage);
    TestCase.assertEquals(IntegrationStatus.Status.ACTIVE, Objects.requireNonNull(infobloxFacilitySoftware.getBody())[0].getIntegrationStatus().getStatus());
}
Also used : EventMessage(com.vmware.flowgate.common.model.redis.message.EventMessage) AssetIPMapping(com.vmware.flowgate.common.model.AssetIPMapping) Asset(com.vmware.flowgate.common.model.Asset) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 13 with AssetIPMapping

use of com.vmware.flowgate.common.model.AssetIPMapping in project flowgate by vmware.

the class InfobloxServiceTest method testExecuteAsyncInvokeIPv4.

@Test
public void testExecuteAsyncInvokeIPv4() {
    EventMessage eventMessage = EventMessageUtil.createEventMessage(EventType.InfoBlox, null, "10.161.71.154");
    ResponseEntity<FacilitySoftwareConfig[]> infobloxFacilitySoftware = this.getInfobloxFacilitySoftware();
    Mockito.doReturn(new ArrayList<>()).when(infobloxClient).queryHostRecordByIP(Mockito.anyString());
    Mockito.doReturn(this.getInfoBloxIPInfoResults()).when(infobloxClient).queryIpv4addressByIP(Mockito.anyString());
    Mockito.doReturn(new ResponseEntity<>(new Asset(), HttpStatus.OK)).when(wormholeAPIClient).getAssetByName(Mockito.anyString());
    Mockito.doReturn(infobloxFacilitySoftware).when(wormholeAPIClient).getFacilitySoftwareInternalByType(FacilitySoftwareConfig.SoftwareType.InfoBlox);
    Mockito.doReturn(new ResponseEntity<>(new AssetIPMapping[0], HttpStatus.OK)).when(wormholeAPIClient).getHostnameIPMappingByIP(Mockito.anyString());
    infoBloxService.executeAsync(eventMessage);
    TestCase.assertEquals(IntegrationStatus.Status.WARNING, Objects.requireNonNull(infobloxFacilitySoftware.getBody())[0].getIntegrationStatus().getStatus());
}
Also used : EventMessage(com.vmware.flowgate.common.model.redis.message.EventMessage) AssetIPMapping(com.vmware.flowgate.common.model.AssetIPMapping) Asset(com.vmware.flowgate.common.model.Asset) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 14 with AssetIPMapping

use of com.vmware.flowgate.common.model.AssetIPMapping in project flowgate by vmware.

the class AssetControllerTest method getHostNameIPMappingByPage.

@Test
public void getHostNameIPMappingByPage() throws Exception {
    AssetIPMapping assetipmapping = createAssetIPMapping();
    assetipmapping.setAssetname("cloud-sha2-esx2");
    assetipmapping = assetIPMappingRepository.save(assetipmapping);
    this.mockMvc.perform(get("/v1/assets/mapping/hostnameip").param("pagesize", "10").param("pagenumber", "1")).andExpect(status().isOk()).andExpect(jsonPath("$..totalPages").value(1)).andExpect(jsonPath("$..content[0].ip").value(assetipmapping.getIp())).andExpect(jsonPath("$..content[0].macAddress").value(assetipmapping.getMacAddress())).andExpect(jsonPath("$..content[0].assetname").value(assetipmapping.getAssetname())).andDo(document("assets-getHostNameIPMappingByPage-example", requestParameters(parameterWithName("pagesize").description("The number of AssetIPMapping you want to get by every request.Default value:20").optional(), parameterWithName("pagenumber").description("The number of page you want to get").optional()), responseFields(subsectionWithPath("content").description("AssetIPMapping's array."), fieldWithPath("totalPages").description("content's total pages."), fieldWithPath("totalElements").description("content's total elements."), fieldWithPath("last").description("Is the last."), fieldWithPath("number").description("The page number."), fieldWithPath("size").description("The page size."), fieldWithPath("sort").description("The sort."), fieldWithPath("numberOfElements").description("The number of Elements."), fieldWithPath("first").description("Is the first."), subsectionWithPath("pageable").description("pageable.").ignored(), subsectionWithPath("sort").description("sorted.").ignored(), fieldWithPath("empty").description("Is empty.").ignored())));
    assetIPMappingRepository.deleteById(assetipmapping.getId());
}
Also used : AssetIPMapping(com.vmware.flowgate.common.model.AssetIPMapping) SpringBootTest(org.springframework.boot.test.context.SpringBootTest) Test(org.junit.Test)

Example 15 with AssetIPMapping

use of com.vmware.flowgate.common.model.AssetIPMapping in project flowgate by vmware.

the class AssetControllerTest method deleteAssetIPAndNameMappingExample.

@Test
public void deleteAssetIPAndNameMappingExample() throws Exception {
    AssetIPMapping assetipmapping = createAssetIPMapping();
    assetipmapping.setAssetname("cloud-server");
    assetipmapping.setMacAddress("00:50:56:be:60:62");
    assetipmapping = assetIPMappingRepository.save(assetipmapping);
    this.mockMvc.perform(delete("/v1/assets/mapping/hostnameip/{Id}", assetipmapping.getId())).andExpect(status().isOk()).andDo(document("assets-deleteAssetIPAndNameMapping-example", pathParameters(parameterWithName("Id").description("The id of AssetIPMapping, generated by flowgate。"))));
}
Also used : AssetIPMapping(com.vmware.flowgate.common.model.AssetIPMapping) SpringBootTest(org.springframework.boot.test.context.SpringBootTest) Test(org.junit.Test)

Aggregations

AssetIPMapping (com.vmware.flowgate.common.model.AssetIPMapping)19 Test (org.junit.Test)12 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)12 Asset (com.vmware.flowgate.common.model.Asset)10 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)6 ArrayList (java.util.ArrayList)4 IntegrationStatus (com.vmware.flowgate.common.model.IntegrationStatus)3 MvcResult (org.springframework.test.web.servlet.MvcResult)3 HttpClientErrorException (org.springframework.web.client.HttpClientErrorException)3 ServerMapping (com.vmware.flowgate.common.model.ServerMapping)2 EventMessage (com.vmware.flowgate.common.model.redis.message.EventMessage)2 IOException (java.io.IOException)2 ConnectException (java.net.ConnectException)2 HashMap (java.util.HashMap)2 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)1 FacilitySoftwareConfig (com.vmware.flowgate.common.model.FacilitySoftwareConfig)1 MetricData (com.vmware.flowgate.common.model.MetricData)1 WormholeRequestException (com.vmware.flowgate.exception.WormholeRequestException)1 InfoBloxIPInfoResult (com.vmware.flowgate.infobloxworker.model.InfoBloxIPInfoResult)1 InfobloxClient (com.vmware.flowgate.infobloxworker.service.InfobloxClient)1