Search in sources :

Example 6 with AssetIPMapping

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

the class AssetControllerTest method createHostNameAndIPMappingFailureExample2.

@Test
public void createHostNameAndIPMappingFailureExample2() throws Exception {
    SetOperations<String, String> setOperations = Mockito.mock(SetOperations.class);
    when(template.hasKey(anyString())).thenReturn(false);
    when(template.opsForSet()).thenReturn(setOperations);
    when(setOperations.add(anyString(), any())).thenReturn(1l);
    Asset server = createAsset();
    server.setCategory(AssetCategory.Server);
    server.setAssetName("cloud-sha1-esx2");
    assetRepository.save(server);
    AssetIPMapping mapping = createAssetIPMapping();
    mapping.setAssetname("cloud-sha1-esx8");
    mapping.setIp("192.168.0.1");
    mapping.setMacAddress("50:00:56:ge:64:62");
    expectedEx.expect(WormholeRequestException.class);
    expectedEx.expectMessage("Can't find any asset with the name : " + mapping.getAssetname());
    MvcResult result = this.mockMvc.perform(post("/v1/assets/mapping/hostnameip").contentType(MediaType.APPLICATION_JSON).content(objectMapper.writeValueAsString(mapping))).andReturn();
    if (result.getResolvedException() != null) {
        assetRepository.deleteById(server.getId());
        throw result.getResolvedException();
    }
}
Also used : AssetIPMapping(com.vmware.flowgate.common.model.AssetIPMapping) Asset(com.vmware.flowgate.common.model.Asset) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) MvcResult(org.springframework.test.web.servlet.MvcResult) SpringBootTest(org.springframework.boot.test.context.SpringBootTest) Test(org.junit.Test)

Example 7 with AssetIPMapping

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

the class AssetControllerTest method createHostNameIPMappingExample.

@Test
public void createHostNameIPMappingExample() throws Exception {
    SetOperations<String, String> setOperations = Mockito.mock(SetOperations.class);
    when(template.hasKey(anyString())).thenReturn(false);
    when(template.opsForSet()).thenReturn(setOperations);
    when(setOperations.add(anyString(), any())).thenReturn(1l);
    Asset server = createAsset();
    server.setCategory(AssetCategory.Server);
    server.setAssetName("cloud-sha1-esx2");
    server = assetRepository.save(server);
    AssetIPMapping assetipmapping = createAssetIPMapping();
    assetipmapping.setAssetname(server.getAssetName());
    assetipmapping.setIp("192.168.0.1");
    assetipmapping.setMacAddress("50:00:56:ge:64:62");
    this.mockMvc.perform(post("/v1/assets/mapping/hostnameip").contentType(MediaType.APPLICATION_JSON).content(objectMapper.writeValueAsString(assetipmapping))).andExpect(status().isCreated()).andDo(document("assets-createHostNameIPMapping-example", requestFields(fieldWithPath("id").description("ID of the asset, created by flowgate"), fieldWithPath("ip").description("ip of hostname"), fieldWithPath("macAddress").description("macAddress of IP"), fieldWithPath("assetname").description("The name of the asset in the third part DCIM/CMDB systems. Usually it will be a unique identifier of an asset"))));
    assetipmapping = assetIPMappingRepository.findById(assetipmapping.getId()).get();
    assetRepository.deleteById(server.getId());
    assetIPMappingRepository.deleteById(assetipmapping.getId());
    TestCase.assertEquals(server.getAssetName(), assetipmapping.getAssetname());
}
Also used : AssetIPMapping(com.vmware.flowgate.common.model.AssetIPMapping) Asset(com.vmware.flowgate.common.model.Asset) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) SpringBootTest(org.springframework.boot.test.context.SpringBootTest) Test(org.junit.Test)

Example 8 with AssetIPMapping

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

the class AssetControllerTest method updateHostNameIPMappingExample.

@Test
public void updateHostNameIPMappingExample() throws Exception {
    SetOperations<String, String> setOperations = Mockito.mock(SetOperations.class);
    when(template.hasKey(anyString())).thenReturn(false);
    when(template.opsForSet()).thenReturn(setOperations);
    when(setOperations.add(anyString(), any())).thenReturn(1l);
    Asset server = createAsset();
    server.setCategory(AssetCategory.Server);
    server.setAssetName("cloud-sha1-esx2");
    server = assetRepository.save(server);
    Asset server1 = createAsset();
    server1.setCategory(AssetCategory.Server);
    server1.setAssetName("cloud-sha1-esx8");
    server1 = assetRepository.save(server1);
    AssetIPMapping assetipmapping = createAssetIPMapping();
    assetipmapping.setAssetname(server.getAssetName());
    assetipmapping = assetIPMappingRepository.save(assetipmapping);
    AssetIPMapping newAssetIPMapping = createAssetIPMapping();
    newAssetIPMapping.setAssetname(server1.getAssetName());
    newAssetIPMapping.setId(assetipmapping.getId());
    newAssetIPMapping.setMacAddress("00:50:56:be:60:62");
    newAssetIPMapping.setIp("192.168.0.1");
    this.mockMvc.perform(put("/v1/assets/mapping/hostnameip").contentType(MediaType.APPLICATION_JSON).content(objectMapper.writeValueAsString(newAssetIPMapping))).andExpect(status().isOk()).andDo(document("assets-updateHostNameIPMapping-example", requestFields(fieldWithPath("id").description("ID of the asset, created by flowgate"), fieldWithPath("ip").description("ip of hostname"), fieldWithPath("macAddress").description("macAddress of IP"), fieldWithPath("assetname").description("The name of the asset in the third part DCIM/CMDB systems. Usually it will be a unique identifier of an asset"))));
    assetipmapping = assetIPMappingRepository.findById(assetipmapping.getId()).get();
    assetRepository.deleteById(server.getId());
    assetRepository.deleteById(server1.getId());
    assetIPMappingRepository.deleteById(assetipmapping.getId());
    TestCase.assertEquals(server1.getAssetName(), assetipmapping.getAssetname());
    TestCase.assertEquals("00:50:56:be:60:62", assetipmapping.getMacAddress());
}
Also used : AssetIPMapping(com.vmware.flowgate.common.model.AssetIPMapping) Asset(com.vmware.flowgate.common.model.Asset) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) SpringBootTest(org.springframework.boot.test.context.SpringBootTest) Test(org.junit.Test)

Example 9 with AssetIPMapping

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

the class AssetService method batchCreateMappingFromFile.

public List<AssetIPMapping> batchCreateMappingFromFile(MultipartFile multipartFile) throws IOException {
    List<AssetIPMapping> failureMappings = new ArrayList<AssetIPMapping>();
    InputStream inputStream = multipartFile.getInputStream();
    try (InputStreamReader inputStreamReader = new InputStreamReader(inputStream, "UTF-8");
        BufferedReader br = new BufferedReader(inputStreamReader)) {
        String assetIPMappingString = null;
        while ((assetIPMappingString = br.readLine()) != null) {
            AssetIPMapping mapping = parseAssetIPMapingByString(assetIPMappingString);
            if (isAssetNameValidate(mapping.getAssetname()) && IPAddressUtil.isValidIp(mapping.getIp())) {
                BaseDocumentUtil.generateID(mapping);
                assetIPMappingRepository.save(mapping);
            } else {
                failureMappings.add(mapping);
            }
        }
    }
    return failureMappings;
}
Also used : InputStreamReader(java.io.InputStreamReader) AssetIPMapping(com.vmware.flowgate.common.model.AssetIPMapping) InputStream(java.io.InputStream) ArrayList(java.util.ArrayList) BufferedReader(java.io.BufferedReader)

Example 10 with AssetIPMapping

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

the class AssetService method parseAssetIPMapingByString.

public static AssetIPMapping parseAssetIPMapingByString(String contentString) {
    String[] contentsArray = contentString.trim().split("\\s+");
    AssetIPMapping mapping = new AssetIPMapping();
    for (String content : contentsArray) {
        if (!content.isEmpty() && mapping.getIp() == null) {
            mapping.setIp(content);
            continue;
        }
        if (!content.isEmpty() && mapping.getAssetname() == null) {
            mapping.setAssetname(content);
            break;
        }
    }
    return mapping;
}
Also used : AssetIPMapping(com.vmware.flowgate.common.model.AssetIPMapping)

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