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);
}
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());
}
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());
}
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());
}
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。"))));
}
Aggregations