Search in sources :

Example 41 with SDDCSoftwareConfig

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

the class SDDCSoftwareController method createServer.

@ResponseStatus(HttpStatus.CREATED)
@RequestMapping(method = RequestMethod.POST)
public void createServer(@RequestBody SDDCSoftwareConfig server, HttpServletRequest request) {
    String ip = server.getServerURL();
    SDDCSoftwareConfig example = sddcRepository.findOneByServerURL(ip);
    if (example != null) {
        String message = String.format("The server %s is already exsit.", ip);
        throw new WormholeRequestException(message);
    }
    switch(server.getType()) {
        case VRO:
            serverValidationService.validateVROServer(server);
            break;
        case VCENTER:
            serverValidationService.validVCServer(server);
            break;
        case VROPSMP:
            break;
        default:
            throw WormholeRequestException.InvalidFiled("type", server.getType().toString());
    }
    WormholeUserDetails user = accessTokenService.getCurrentUser(request);
    server.setUserId(user.getUserId());
    IntegrationStatus integrationStatus = new IntegrationStatus();
    integrationStatus.setRetryCounter(FlowgateConstant.DEFAULTNUMBEROFRETRIES);
    integrationStatus.setStatus(IntegrationStatus.Status.ACTIVE);
    server.setIntegrationStatus(integrationStatus);
    // encrypt the password
    encryptServerPassword(server);
    BaseDocumentUtil.generateID(server);
    sddcRepository.save(server);
    // notify worker for the start jobs
    decryptServerPassword(server);
    notifySDDCWorker(server);
}
Also used : SDDCSoftwareConfig(com.vmware.flowgate.common.model.SDDCSoftwareConfig) WormholeRequestException(com.vmware.flowgate.exception.WormholeRequestException) WormholeUserDetails(com.vmware.flowgate.util.WormholeUserDetails) IntegrationStatus(com.vmware.flowgate.common.model.IntegrationStatus) ResponseStatus(org.springframework.web.bind.annotation.ResponseStatus) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 42 with SDDCSoftwareConfig

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

the class EventMessageUtil method generateSDDCMessageListByType.

public static List<String> generateSDDCMessageListByType(EventType type, String targetCommand, SDDCSoftwareConfig[] sddcs) throws JsonProcessingException {
    List<String> result = new ArrayList<String>();
    for (SDDCSoftwareConfig sddc : sddcs) {
        String payload = mapper.writeValueAsString(sddc);
        EventMessage message = EventMessageUtil.createEventMessage(type, targetCommand, payload);
        result.add(mapper.writeValueAsString(message));
    }
    return result;
}
Also used : SDDCSoftwareConfig(com.vmware.flowgate.common.model.SDDCSoftwareConfig) EventMessage(com.vmware.flowgate.common.model.redis.message.EventMessage) ArrayList(java.util.ArrayList)

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