use of com.vmware.flowgate.exception.WormholeRequestException in project flowgate by vmware.
the class AssetService method mappingFacilityForServerAsset.
public void mappingFacilityForServerAsset(Asset asset) {
Optional<Asset> oldAssetOptional = assetRepository.findById(asset.getId());
if (!oldAssetOptional.isPresent()) {
throw new WormholeRequestException(HttpStatus.INTERNAL_SERVER_ERROR, "Asset not found", null);
}
Asset oldAsset = oldAssetOptional.get();
List<String> pdus = asset.getPdus();
if (pdus != null) {
oldAsset.setPdus(pdus);
}
List<String> switchs = asset.getSwitches();
if (switchs != null) {
oldAsset.setSwitches(switchs);
}
Map<String, String> newMetricsformulas = asset.getMetricsformulars();
if (newMetricsformulas != null && newMetricsformulas.containsKey(FlowgateConstant.SENSOR)) {
Map<String, String> oldMetricsformulas = oldAsset.getMetricsformulars();
Map<String, Map<String, String>> oldSensorformulasMap = null;
String oldSensorFormulasInfo = null;
if (oldMetricsformulas.containsKey(FlowgateConstant.SENSOR)) {
oldSensorFormulasInfo = oldMetricsformulas.get(FlowgateConstant.SENSOR);
oldSensorformulasMap = asset.metricsFormulaToMap(oldSensorFormulasInfo, new TypeReference<Map<String, Map<String, String>>>() {
});
} else {
oldSensorformulasMap = new HashMap<String, Map<String, String>>();
}
String newSensorFormulaInfo = newMetricsformulas.get(FlowgateConstant.SENSOR);
Map<String, Map<String, String>> newSensorformulasMap = asset.metricsFormulaToMap(newSensorFormulaInfo, new TypeReference<Map<String, Map<String, String>>>() {
});
generateSensorFormula(oldSensorformulasMap, newSensorformulasMap);
oldSensorFormulasInfo = asset.metricsFormulaToString(oldSensorformulasMap);
oldMetricsformulas.put(FlowgateConstant.SENSOR, oldSensorFormulasInfo);
oldAsset.setMetricsformulars(oldMetricsformulas);
}
oldAsset.setLastupdate(System.currentTimeMillis());
assetRepository.save(oldAsset);
}
use of com.vmware.flowgate.exception.WormholeRequestException in project flowgate by vmware.
the class FacilityAdapterService method deleteAdapter.
public void deleteAdapter(String id) {
FacilityAdapter adapter = findById(id);
int count = facilitySoftwareRepo.countFacilityBySubcategory(adapter.getSubCategory());
if (count > 0) {
throw new WormholeRequestException("Adapter deletion failed, there are some integration instances are using it");
} else {
facilityAdapterRepo.deleteById(id);
if (redis.opsForSet().isMember(FlowgateConstant.SERVICE_KEY_SET, adapter.getServiceKey())) {
redis.opsForSet().remove(FlowgateConstant.SERVICE_KEY_SET, adapter.getServiceKey());
}
}
}
use of com.vmware.flowgate.exception.WormholeRequestException in project flowgate by vmware.
the class FacilityAdapterService method create.
public HttpHeaders create(FacilityAdapter adapter) {
String displayName = adapter.getDisplayName();
if (displayName == null || predefineName.contains(displayName)) {
throw WormholeRequestException.InvalidFiled("DisplayName", displayName);
}
FacilityAdapter oldAdapter = facilityAdapterRepo.findByDisplayName(displayName);
if (oldAdapter != null) {
throw new WormholeRequestException("Adapter with dispalyName : " + displayName + " is existed");
}
List<AdapterJobCommand> commands = adapter.getCommands();
if (commands == null || commands.isEmpty()) {
throw new WormholeRequestException("The Commands field is required.");
}
HttpHeaders httpHeaders = new HttpHeaders();
BaseDocumentUtil.generateID(adapter);
String unique_value = adapter.getType().name() + JOIN_FLAG + UUID.randomUUID().toString().replaceAll("-", "");
adapter.setTopic(unique_value);
adapter.setSubCategory(unique_value);
adapter.setQueueName(adapter.getSubCategory() + QUEUE_NAME_SUFFIX);
String randomKey = UUID.randomUUID().toString().replaceAll("-", "");
String serviceKey = DigestUtils.sha256Hex(randomKey);
adapter.setServiceKey(serviceKey);
facilityAdapterRepo.save(adapter);
cacheServiceKey(serviceKey);
httpHeaders.setLocation(linkTo(AssetController.class).slash(adapter.getId()).toUri());
return httpHeaders;
}
use of com.vmware.flowgate.exception.WormholeRequestException in project flowgate by vmware.
the class ServerValidationService method validateVROServer.
public void validateVROServer(SDDCSoftwareConfig server) {
try {
VRopsAuth ss = createVRopsAuth(server);
ss.getClient().apiVersionsClient().getCurrentVersion();
} catch (AuthException authException) {
throw new WormholeRequestException(HttpStatus.BAD_REQUEST, "Invalid user name or password.", authException.getCause());
} catch (Exception exception) {
if (exception.getCause() instanceof ConnectException) {
throw new WormholeRequestException(HttpStatus.BAD_REQUEST, "Failed to connect to server: " + server.getServerURL(), exception.getCause());
} else if (exception.getCause() instanceof SSLException) {
throw new WormholeRequestException(HttpStatus.BAD_REQUEST, "Certificate verification error", exception.getCause());
}
throw new WormholeRequestException("Internal error", exception.getCause());
}
}
use of com.vmware.flowgate.exception.WormholeRequestException in project flowgate by vmware.
the class AssetController method updateHostNameIPMapping.
@ResponseStatus(HttpStatus.OK)
@RequestMapping(value = "/mapping/hostnameip", method = RequestMethod.PUT)
public void updateHostNameIPMapping(@RequestBody AssetIPMapping mapping) {
Optional<AssetIPMapping> oldMappingOptional = assetIPMappingRepository.findById(mapping.getId());
if (!oldMappingOptional.isPresent()) {
throw new WormholeRequestException(HttpStatus.INTERNAL_SERVER_ERROR, "Can't find any mapping with the id: " + mapping.getId(), null);
}
AssetIPMapping oldMapping = oldMappingOptional.get();
String assetName = mapping.getAssetname();
String macAddress = mapping.getMacAddress();
if (StringUtils.equals(oldMapping.getAssetname(), assetName)) {
if (StringUtils.equals(macAddress, oldMapping.getMacAddress())) {
return;
}
}
if (!assetService.isAssetNameValidate(assetName)) {
throw new WormholeRequestException(HttpStatus.INTERNAL_SERVER_ERROR, "Can't find any asset with the name : " + mapping.getAssetname(), null);
}
oldMapping.setAssetname(mapping.getAssetname());
oldMapping.setMacAddress(mapping.getMacAddress());
assetIPMappingRepository.save(oldMapping);
}
Aggregations