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");
}
}
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));
}
}
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");
}
}
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;
}
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);
}
Aggregations