Search in sources :

Example 26 with WormholeRequestException

use of com.vmware.flowgate.exception.WormholeRequestException 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 27 with WormholeRequestException

use of com.vmware.flowgate.exception.WormholeRequestException in project flowgate by vmware.

the class SensorSettingController method updateSensorSetting.

// Update
@ResponseStatus(HttpStatus.OK)
@RequestMapping(value = "/setting", method = RequestMethod.PUT, consumes = MediaType.APPLICATION_JSON_VALUE)
public void updateSensorSetting(@RequestBody SensorSetting sensorSetting) {
    Optional<SensorSetting> oldSensorSettingOptional = repository.findById(sensorSetting.getId());
    if (!oldSensorSettingOptional.isPresent()) {
        throw WormholeRequestException.NotFound("SensorSetting", "id", sensorSetting.getId());
    }
    SensorSetting old = oldSensorSettingOptional.get();
    try {
        BaseDocumentUtil.applyChanges(old, sensorSetting);
    } catch (Exception e) {
        throw new WormholeRequestException("Failed to update the Sensor setting.", e);
    }
    repository.save(old);
}
Also used : WormholeRequestException(com.vmware.flowgate.exception.WormholeRequestException) SensorSetting(com.vmware.flowgate.common.model.SensorSetting) WormholeRequestException(com.vmware.flowgate.exception.WormholeRequestException) ResponseStatus(org.springframework.web.bind.annotation.ResponseStatus) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Aggregations

WormholeRequestException (com.vmware.flowgate.exception.WormholeRequestException)27 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)21 ResponseStatus (org.springframework.web.bind.annotation.ResponseStatus)14 WormholeUserDetails (com.vmware.flowgate.util.WormholeUserDetails)9 IOException (java.io.IOException)9 SDDCSoftwareConfig (com.vmware.flowgate.common.model.SDDCSoftwareConfig)4 EventMessage (com.vmware.flowgate.common.model.redis.message.EventMessage)4 AuthToken (com.vmware.flowgate.common.model.AuthToken)3 FacilityAdapter (com.vmware.flowgate.common.model.FacilityAdapter)3 WormholeUser (com.vmware.flowgate.common.model.WormholeUser)3 WormholeException (com.vmware.flowgate.common.exception.WormholeException)2 AdapterJobCommand (com.vmware.flowgate.common.model.AdapterJobCommand)2 Asset (com.vmware.flowgate.common.model.Asset)2 IntegrationStatus (com.vmware.flowgate.common.model.IntegrationStatus)2 UnsupportedEncodingException (java.io.UnsupportedEncodingException)2 GeneralSecurityException (java.security.GeneralSecurityException)2 Date (java.util.Date)2 NoSuchElementException (java.util.NoSuchElementException)2 Optional (java.util.Optional)2 Cookie (javax.servlet.http.Cookie)2