Search in sources :

Example 11 with WormholeRequestException

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

the class JobsController method generateTempHumidityMapping.

@ResponseStatus(HttpStatus.CREATED)
@RequestMapping(value = "/temphumiditymapping/fullsync/{fullsync}", method = RequestMethod.POST, consumes = MediaType.APPLICATION_JSON_VALUE)
public void generateTempHumidityMapping(@PathVariable boolean fullsync) {
    try {
        String command = fullsync ? EventMessageUtil.FullSyncTemperatureAndHumiditySensors : EventMessageUtil.SyncTemperatureAndHumiditySensors;
        EventMessage eventMessage = EventMessageUtil.createEventMessage(EventType.Aggregator, command, "");
        String message = EventMessageUtil.convertEventMessageAsString(eventMessage);
        publisher.publish(EventMessageUtil.AggregatorTopic, message);
    } catch (IOException e) {
        log.error("Failed to create event message", e);
        throw new WormholeRequestException("Failed to create event message");
    }
}
Also used : WormholeRequestException(com.vmware.flowgate.exception.WormholeRequestException) EventMessage(com.vmware.flowgate.common.model.redis.message.EventMessage) IOException(java.io.IOException) ResponseStatus(org.springframework.web.bind.annotation.ResponseStatus) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 12 with WormholeRequestException

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

the class JobsController method syncHostnameByIp.

@ResponseStatus(HttpStatus.CREATED)
@RequestMapping(value = "/synchostnamebyip/{ip:.+}", method = RequestMethod.POST, consumes = MediaType.APPLICATION_JSON_VALUE)
public void syncHostnameByIp(@PathVariable("ip") String ip) {
    if (IPAddressUtil.isValidIp(ip)) {
        EventMessage eventMessage = EventMessageUtil.createEventMessage(EventType.InfoBlox, null, ip);
        try {
            String message = EventMessageUtil.convertEventMessageAsString(eventMessage);
            publisher.publish(EventMessageUtil.InfobloxTopic, message);
        } catch (IOException e) {
            log.error("Failed to create event message", e);
            throw new WormholeRequestException("Failed to create event message for query hostname.");
        }
    } else {
        throw new WormholeRequestException(String.format("Invalid Ip: %s", ip));
    }
}
Also used : WormholeRequestException(com.vmware.flowgate.exception.WormholeRequestException) EventMessage(com.vmware.flowgate.common.model.redis.message.EventMessage) IOException(java.io.IOException) ResponseStatus(org.springframework.web.bind.annotation.ResponseStatus) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 13 with WormholeRequestException

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

the class JobsController method generateServerPDUMapping.

@ResponseStatus(HttpStatus.CREATED)
@RequestMapping(value = "/pduservermapping", method = RequestMethod.POST, consumes = MediaType.APPLICATION_JSON_VALUE)
public void generateServerPDUMapping() {
    try {
        EventMessage eventMessage = EventMessageUtil.createEventMessage(EventType.Aggregator, EventMessageUtil.PDUServerMappingCommand, "");
        String message = EventMessageUtil.convertEventMessageAsString(eventMessage);
        publisher.publish(EventMessageUtil.AggregatorTopic, message);
    } catch (IOException e) {
        log.error("Failed to create event message", e);
        throw new WormholeRequestException("Failed to create event message");
    }
}
Also used : WormholeRequestException(com.vmware.flowgate.exception.WormholeRequestException) EventMessage(com.vmware.flowgate.common.model.redis.message.EventMessage) IOException(java.io.IOException) ResponseStatus(org.springframework.web.bind.annotation.ResponseStatus) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 14 with WormholeRequestException

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

the class AccessTokenService method createToken.

public AuthToken createToken(WormholeUser user) {
    // Perform the security
    AuthToken access_token = null;
    try {
        String username = user.getUserName();
        final Authentication authentication = authenticationManager.authenticate(new UsernamePasswordAuthenticationToken(username, user.getPassword()));
        SecurityContextHolder.getContext().setAuthentication(authentication);
        // Reload password post-security so we can generate token
        WormholeUserDetails userDetails = userDetailsService.loadUserByUsername(user.getUserName());
        access_token = jwtTokenUtil.generate(userDetails);
    } catch (BadCredentialsException e) {
        throw new WormholeRequestException(HttpStatus.UNAUTHORIZED, "Invalid username or password", e.getCause());
    }
    return access_token;
}
Also used : WormholeRequestException(com.vmware.flowgate.exception.WormholeRequestException) WormholeUserDetails(com.vmware.flowgate.util.WormholeUserDetails) Authentication(org.springframework.security.core.Authentication) AuthToken(com.vmware.flowgate.common.model.AuthToken) UsernamePasswordAuthenticationToken(org.springframework.security.authentication.UsernamePasswordAuthenticationToken) BadCredentialsException(org.springframework.security.authentication.BadCredentialsException)

Example 15 with WormholeRequestException

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

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