Search in sources :

Example 36 with SDDCSoftwareConfig

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

the class SDDCSoftwareControllerTest method sDDCSoftwareDeleteOtherExample.

@Test
public void sDDCSoftwareDeleteOtherExample() throws Exception {
    SDDCSoftwareConfig sddc = createSDDCSoftwareConfig(SoftwareType.OTHERS);
    sddcRepository.save(sddc);
    this.mockMvc.perform(delete("/v1/sddc/" + sddc.getId())).andExpect(status().isOk());
    Optional<SDDCSoftwareConfig> sddcOptional = sddcRepository.findById(sddc.getId());
    TestCase.assertEquals(false, sddcOptional.isPresent());
}
Also used : SDDCSoftwareConfig(com.vmware.flowgate.common.model.SDDCSoftwareConfig) SpringBootTest(org.springframework.boot.test.context.SpringBootTest) Test(org.junit.Test)

Example 37 with SDDCSoftwareConfig

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

the class SDDCSoftwareControllerTest method SDDCSoftwareQueryByTypeAndUserId.

@Test
public void SDDCSoftwareQueryByTypeAndUserId() throws Exception {
    SDDCSoftwareConfig sddcCreate = createSDDCSoftwareConfig(SoftwareType.VCENTER);
    sddcCreate.setType(SoftwareType.VCENTER);
    sddcCreate.setName("flowgate");
    sddcCreate.setDescription("flowgate cluster");
    Mockito.doReturn(createuser()).when(tokenService).getCurrentUser(any());
    sddcCreate.setPassword(EncryptionGuard.encode(sddcCreate.getPassword()));
    sddcRepository.save(sddcCreate);
    FieldDescriptor[] fieldpath = new FieldDescriptor[] { fieldWithPath("id").description("ID of FacilitySoftwareConfig, created by flowgate"), fieldWithPath("name").description("The facilitySoftware name."), fieldWithPath("description").description("The facilitySoftware description."), fieldWithPath("userName").description("An username used to obtain authorization"), fieldWithPath("password").description(" A password used to obtain authorization."), fieldWithPath("serverURL").description("The server's address, it can be an IP or FQDN."), fieldWithPath("type").description("A type for facilitySoftware,forExample Nlyte,PowerIQ,Device42,OtherDCIM or OtherCMDB").type(SoftwareType.class).optional(), fieldWithPath("userId").description("userId"), fieldWithPath("subCategory").description("subCategory"), fieldWithPath("verifyCert").description("Whether to verify the certificate when accessing the serverURL.").type(JsonFieldType.BOOLEAN), subsectionWithPath("integrationStatus").description("The status of integration.").optional() };
    MvcResult result = this.mockMvc.perform(get("/v1/sddc/type/{type}", SoftwareType.VCENTER)).andExpect(status().isOk()).andDo(document("SDDCSoftware-queryByType-example", pathParameters(parameterWithName("type").description("The type of SDDCSoftwareConfig, Sample value: VRO/VCENTER")), responseFields(fieldWithPath("[]").description("An array of SDDCSoftwareConfig.")).andWithPrefix("[].", fieldpath))).andReturn();
    ObjectMapper mapper = new ObjectMapper();
    String res = result.getResponse().getContentAsString();
    SDDCSoftwareConfig[] sddcs = mapper.readValue(res, SDDCSoftwareConfig[].class);
    for (SDDCSoftwareConfig sddc : sddcs) {
        if (sddc.getName().equals("flowgate")) {
            TestCase.assertEquals("flowgate cluster", sddc.getDescription());
        }
    }
    sddcRepository.deleteById(sddcCreate.getId());
}
Also used : SDDCSoftwareConfig(com.vmware.flowgate.common.model.SDDCSoftwareConfig) MvcResult(org.springframework.test.web.servlet.MvcResult) SoftwareType(com.vmware.flowgate.common.model.SDDCSoftwareConfig.SoftwareType) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) FieldDescriptor(org.springframework.restdocs.payload.FieldDescriptor) SpringBootTest(org.springframework.boot.test.context.SpringBootTest) Test(org.junit.Test)

Example 38 with SDDCSoftwareConfig

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

the class SystemSummaryTest method testSummaryRepo.

@Test
public void testSummaryRepo() throws IOException {
    ValueOperations<String, String> valueOperations = Mockito.mock(ValueOperations.class);
    Mockito.doReturn(valueOperations).when(template).opsForValue();
    FacilitySoftwareConfig nlyte1 = createFacility();
    nlyte1.setType(com.vmware.flowgate.common.model.FacilitySoftwareConfig.SoftwareType.Nlyte);
    nlyte1 = facilityrepo.save(nlyte1);
    FacilitySoftwareConfig powerIQ1 = createFacility();
    powerIQ1.setType(com.vmware.flowgate.common.model.FacilitySoftwareConfig.SoftwareType.PowerIQ);
    powerIQ1 = facilityrepo.save(powerIQ1);
    Asset nlyteServer1 = createAsset();
    nlyteServer1.setCategory(AssetCategory.Server);
    nlyteServer1.setAssetSource(nlyte1.getId());
    nlyteServer1 = assetrepo.save(nlyteServer1);
    Asset nlyteServer2 = createAsset();
    nlyteServer2.setCategory(AssetCategory.Server);
    nlyteServer2.setAssetSource(nlyte1.getId());
    nlyteServer2 = assetrepo.save(nlyteServer2);
    Asset nlytePDU1 = createAsset();
    nlytePDU1.setCategory(AssetCategory.PDU);
    nlytePDU1.setAssetSource(nlyte1.getId());
    nlytePDU1 = assetrepo.save(nlytePDU1);
    Asset nlytePDU2 = createAsset();
    nlytePDU2.setCategory(AssetCategory.PDU);
    nlytePDU2.setAssetSource(nlyte1.getId());
    nlytePDU2 = assetrepo.save(nlytePDU2);
    Asset powerIQSensor1 = createAsset();
    powerIQSensor1.setCategory(AssetCategory.Sensors);
    powerIQSensor1.setSubCategory(AssetSubCategory.Humidity);
    powerIQSensor1.setAssetSource(powerIQ1.getId());
    powerIQSensor1 = assetrepo.save(powerIQSensor1);
    Asset powerIQSensor2 = createAsset();
    powerIQSensor2.setCategory(AssetCategory.Sensors);
    powerIQSensor2.setSubCategory(AssetSubCategory.Humidity);
    powerIQSensor2.setAssetSource(powerIQ1.getId());
    powerIQSensor2 = assetrepo.save(powerIQSensor2);
    Asset powerIQSensor3 = createAsset();
    powerIQSensor3.setCategory(AssetCategory.Sensors);
    powerIQSensor3.setSubCategory(AssetSubCategory.Temperature);
    powerIQSensor3.setAssetSource(powerIQ1.getId());
    powerIQSensor3 = assetrepo.save(powerIQSensor3);
    Asset powerIQSensor4 = createAsset();
    powerIQSensor4.setCategory(AssetCategory.Sensors);
    powerIQSensor4.setSubCategory(AssetSubCategory.Temperature);
    powerIQSensor4.setAssetSource(powerIQ1.getId());
    powerIQSensor4 = assetrepo.save(powerIQSensor4);
    SDDCSoftwareConfig vro1 = createSDDC();
    vro1.setType(SoftwareType.VRO);
    vro1 = sddcrepo.save(vro1);
    SDDCSoftwareConfig vro2 = createSDDC();
    vro2.setType(SoftwareType.VRO);
    vro2 = sddcrepo.save(vro2);
    SDDCSoftwareConfig vc1 = createSDDC();
    vc1.setType(SoftwareType.VCENTER);
    vc1 = sddcrepo.save(vc1);
    SDDCSoftwareConfig vc2 = createSDDC();
    vc2.setType(SoftwareType.VCENTER);
    vc2 = sddcrepo.save(vc2);
    ServerMapping server1 = createServerMapping();
    server1.setVroID(vro1.getId());
    server1 = mappingrepo.save(server1);
    ServerMapping server2 = createServerMapping();
    server2.setVroID(vro1.getId());
    server2 = mappingrepo.save(server2);
    ServerMapping server3 = createServerMapping();
    server3.setVcID(vc1.getId());
    server3 = mappingrepo.save(server3);
    ServerMapping server4 = createServerMapping();
    server4.setVcID(vc2.getId());
    server4 = mappingrepo.save(server4);
    ServerMapping server5 = createServerMapping();
    server5.setVroID(vro2.getId());
    server5 = mappingrepo.save(server5);
    try {
        Thread.sleep(3000);
    } catch (InterruptedException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
    try {
        SystemSummary data = summaryService.getSystemResult(false);
        TestCase.assertEquals(8, data.getAssetsNum());
        TestCase.assertEquals(2, data.getFacilitySystemNum());
        TestCase.assertEquals(4, data.getSddcIntegrationNum());
        TestCase.assertEquals(2, data.getHumiditySensorNum());
        TestCase.assertEquals(2, data.getTemperatureSensorNum());
        TestCase.assertEquals(4, data.getSensorNum());
        TestCase.assertEquals(2, data.getPduNum());
        TestCase.assertEquals(2, data.getServerNum());
        TestCase.assertEquals(5, data.getSddcServerNum());
        TestCase.assertEquals(2, data.getVroNum());
        TestCase.assertEquals(2, data.getVcNum());
    } finally {
        facilityrepo.deleteById(nlyte1.getId());
        facilityrepo.deleteById(powerIQ1.getId());
        assetrepo.deleteById(nlyteServer1.getId());
        assetrepo.deleteById(nlyteServer2.getId());
        assetrepo.deleteById(nlytePDU1.getId());
        assetrepo.deleteById(nlytePDU2.getId());
        assetrepo.deleteById(powerIQSensor1.getId());
        assetrepo.deleteById(powerIQSensor2.getId());
        assetrepo.deleteById(powerIQSensor3.getId());
        assetrepo.deleteById(powerIQSensor4.getId());
        sddcrepo.deleteById(vc1.getId());
        sddcrepo.deleteById(vc2.getId());
        sddcrepo.deleteById(vro1.getId());
        sddcrepo.deleteById(vro2.getId());
        mappingrepo.deleteById(server1.getId());
        mappingrepo.deleteById(server2.getId());
        mappingrepo.deleteById(server3.getId());
        mappingrepo.deleteById(server4.getId());
        mappingrepo.deleteById(server5.getId());
    }
}
Also used : SDDCSoftwareConfig(com.vmware.flowgate.common.model.SDDCSoftwareConfig) SystemSummary(com.vmware.flowgate.common.model.SystemSummary) ServerMapping(com.vmware.flowgate.common.model.ServerMapping) FacilitySoftwareConfig(com.vmware.flowgate.common.model.FacilitySoftwareConfig) Asset(com.vmware.flowgate.common.model.Asset) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 39 with SDDCSoftwareConfig

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

the class SummaryService method getVcSummaryList.

public List<VcSummary> getVcSummaryList() {
    List<VcSummary> vcSummary = new ArrayList<>();
    List<SDDCSoftwareConfig> sddcSoftwareConfigs = sddcrpeo.findAllByType(SoftwareType.VCENTER.name());
    for (SDDCSoftwareConfig s : sddcSoftwareConfigs) {
        VcSummary vc = new VcSummary();
        vc.setName(s.getName());
        vc.setUrl(s.getServerURL());
        vc.setHostsNum(summaryRepository.countServerMappingByVC(s.getId()));
        vcSummary.add(vc);
    }
    return vcSummary;
}
Also used : SDDCSoftwareConfig(com.vmware.flowgate.common.model.SDDCSoftwareConfig) ArrayList(java.util.ArrayList) VcSummary(com.vmware.flowgate.common.model.VcSummary)

Example 40 with SDDCSoftwareConfig

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

the class SDDCSoftwareController method getServerConfig.

// get a server
@RequestMapping(value = "/{id}", method = RequestMethod.GET)
public SDDCSoftwareConfig getServerConfig(@PathVariable String id) {
    Optional<SDDCSoftwareConfig> sddcOptional = sddcRepository.findById(id);
    SDDCSoftwareConfig server = null;
    if (sddcOptional.isPresent()) {
        server = sddcOptional.get();
        server.setPassword(null);
    }
    return server;
}
Also used : SDDCSoftwareConfig(com.vmware.flowgate.common.model.SDDCSoftwareConfig) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Aggregations

SDDCSoftwareConfig (com.vmware.flowgate.common.model.SDDCSoftwareConfig)42 Test (org.junit.Test)22 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)16 ServerMapping (com.vmware.flowgate.common.model.ServerMapping)11 ArrayList (java.util.ArrayList)9 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)9 WormholeRequestException (com.vmware.flowgate.exception.WormholeRequestException)8 MvcResult (org.springframework.test.web.servlet.MvcResult)8 SoftwareType (com.vmware.flowgate.common.model.SDDCSoftwareConfig.SoftwareType)7 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)7 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)6 Asset (com.vmware.flowgate.common.model.Asset)6 IOException (java.io.IOException)6 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)5 AuthVcUser (com.vmware.flowgate.auth.AuthVcUser)5 EventMessage (com.vmware.flowgate.common.model.redis.message.EventMessage)5 HashMap (java.util.HashMap)5 ResponseStatus (org.springframework.web.bind.annotation.ResponseStatus)5 HostSystem (com.vmware.vim.binding.vim.HostSystem)4 ManagedObjectReference (com.vmware.vim.binding.vmodl.ManagedObjectReference)4