Search in sources :

Example 21 with SDDCSoftwareConfig

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

the class MessageProcessingTest method testVC.

@Test
public void testVC() throws Exception {
    ObjectMapper mapper = new ObjectMapper();
    SDDCSoftwareConfig vc = new SDDCSoftwareConfig();
    vc.setDescription("good vc");
    vc.setName("Test VC");
    vc.setServerURL("10.10.10.10");
    vc.setPassword("fake password");
    vc.setType(SoftwareType.VCENTER);
    String payload = mapper.writeValueAsString(vc);
    // EventMessage message =
    // EventMessageUtil.createEventMessage(EventType.VCenter, EventMessageUtil.VCENTER_SyncCustomerAttrs, payload);
    EventMessage message = EventMessageUtil.createEventMessage(EventType.VCenter, EventMessageUtil.VCENTER_SyncData, "");
    System.out.println(mapper.writeValueAsString(message));
}
Also used : SDDCSoftwareConfig(com.vmware.flowgate.common.model.SDDCSoftwareConfig) EventMessage(com.vmware.flowgate.common.model.redis.message.EventMessage) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) SpringBootTest(org.springframework.boot.test.context.SpringBootTest) Test(org.junit.Test)

Example 22 with SDDCSoftwareConfig

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

the class SDDCSoftwareController method updateStatus.

// only modify the status of integration,and not verify information of server.
@ResponseStatus(HttpStatus.OK)
@RequestMapping(value = "/status", method = RequestMethod.PUT, consumes = MediaType.APPLICATION_JSON_VALUE)
public void updateStatus(@RequestBody SDDCSoftwareConfig server) {
    Optional<SDDCSoftwareConfig> oldSddcOptional = sddcRepository.findById(server.getId());
    if (!oldSddcOptional.isPresent()) {
        throw WormholeRequestException.NotFound("SDDCSoftwareConfig", "id", server.getId());
    }
    SDDCSoftwareConfig old = oldSddcOptional.get();
    old.setIntegrationStatus(server.getIntegrationStatus());
    sddcRepository.save(old);
}
Also used : SDDCSoftwareConfig(com.vmware.flowgate.common.model.SDDCSoftwareConfig) ResponseStatus(org.springframework.web.bind.annotation.ResponseStatus) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 23 with SDDCSoftwareConfig

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

the class SDDCSoftwareController method updateSDDCSoftwareConfig.

// Update
@ResponseStatus(HttpStatus.OK)
@RequestMapping(method = RequestMethod.PUT, consumes = MediaType.APPLICATION_JSON_VALUE)
public void updateSDDCSoftwareConfig(@RequestBody SDDCSoftwareConfig server) {
    Optional<SDDCSoftwareConfig> oldSddcOptional = sddcRepository.findById(server.getId());
    if (!oldSddcOptional.isPresent()) {
        throw WormholeRequestException.NotFound("SDDCSoftwareConfig", "id", server.getId());
    }
    SDDCSoftwareConfig old = oldSddcOptional.get();
    server.setServerURL(old.getServerURL());
    server.setType(old.getType());
    server.setUserId(old.getUserId());
    if (StringUtils.isBlank(server.getPassword())) {
        decryptServerPassword(old);
        server.setPassword(old.getPassword());
    }
    switch(server.getType()) {
        case VRO:
            serverValidationService.validateVROServer(server);
            break;
        case VCENTER:
            serverValidationService.validVCServer(server);
            break;
        default:
            throw WormholeRequestException.InvalidFiled("type", server.getType().toString());
    }
    encryptServerPassword(server);
    try {
        BaseDocumentUtil.applyChanges(old, server);
    } catch (Exception e) {
        throw new WormholeRequestException("Faild to update the SDDCSoftware", e);
    }
    sddcRepository.save(old);
}
Also used : SDDCSoftwareConfig(com.vmware.flowgate.common.model.SDDCSoftwareConfig) WormholeRequestException(com.vmware.flowgate.exception.WormholeRequestException) GeneralSecurityException(java.security.GeneralSecurityException) NoSuchElementException(java.util.NoSuchElementException) WormholeRequestException(com.vmware.flowgate.exception.WormholeRequestException) IOException(java.io.IOException) WormholeException(com.vmware.flowgate.common.exception.WormholeException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) ResponseStatus(org.springframework.web.bind.annotation.ResponseStatus) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 24 with SDDCSoftwareConfig

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

the class SDDCSoftwareController method delete.

// Delete
@ResponseStatus(HttpStatus.OK)
@RequestMapping(value = "/{id}", method = RequestMethod.DELETE)
public void delete(@PathVariable String id) {
    Optional<SDDCSoftwareConfig> sddcOptional = sddcRepository.findById(id);
    SDDCSoftwareConfig server = new SDDCSoftwareConfig();
    try {
        server = sddcOptional.get();
    } catch (NoSuchElementException e) {
        throw WormholeRequestException.NotFound("sddc", "id", id);
    }
    SoftwareType type = server.getType();
    switch(type) {
        case VCENTER:
            List<ServerMapping> vcenterMappings = serverMappingRepository.findAllByVCID(id);
            if (vcenterMappings != null && !vcenterMappings.isEmpty()) {
                for (ServerMapping mapping : vcenterMappings) {
                    serverMappingRepository.deleteById(mapping.getId());
                }
            }
            break;
        case VRO:
        case VROPSMP:
            List<ServerMapping> mappings = serverMappingRepository.findAllByVroID(id);
            if (mappings != null && !mappings.isEmpty()) {
                for (ServerMapping mapping : mappings) {
                    serverMappingRepository.deleteById(mapping.getId());
                }
            }
            break;
        default:
            logger.info(String.format("Integration Type: %s No Found.", server.getType()));
            break;
    }
    sddcRepository.deleteById(id);
}
Also used : SDDCSoftwareConfig(com.vmware.flowgate.common.model.SDDCSoftwareConfig) ServerMapping(com.vmware.flowgate.common.model.ServerMapping) NoSuchElementException(java.util.NoSuchElementException) SoftwareType(com.vmware.flowgate.common.model.SDDCSoftwareConfig.SoftwareType) ResponseStatus(org.springframework.web.bind.annotation.ResponseStatus) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 25 with SDDCSoftwareConfig

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

the class SDDCSoftwareController method getVROServerConfigsByUser.

// get servers by user
// Confuse, if we only filter out vrops why not set the type field?
@RequestMapping(value = "/user/vrops", method = RequestMethod.GET)
public List<SDDCSoftwareConfig> getVROServerConfigsByUser(HttpServletRequest request) {
    SDDCSoftwareConfig example = new SDDCSoftwareConfig();
    example.setUserId(getCurrentUserID(request));
    List<SDDCSoftwareConfig> datas = sddcRepository.findAllByUserId(getCurrentUserID(request));
    if (datas.isEmpty()) {
        throw new WormholeRequestException("The result is empty");
    }
    decryptServerListPassword(datas);
    return datas;
}
Also used : SDDCSoftwareConfig(com.vmware.flowgate.common.model.SDDCSoftwareConfig) WormholeRequestException(com.vmware.flowgate.exception.WormholeRequestException) 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