Search in sources :

Example 1 with WormholeRequestException

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);
}
Also used : WormholeRequestException(com.vmware.flowgate.exception.WormholeRequestException) Asset(com.vmware.flowgate.common.model.Asset) TypeReference(com.fasterxml.jackson.core.type.TypeReference) Map(java.util.Map) HashMap(java.util.HashMap)

Example 2 with WormholeRequestException

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());
        }
    }
}
Also used : WormholeRequestException(com.vmware.flowgate.exception.WormholeRequestException) FacilityAdapter(com.vmware.flowgate.common.model.FacilityAdapter)

Example 3 with WormholeRequestException

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;
}
Also used : WormholeRequestException(com.vmware.flowgate.exception.WormholeRequestException) AdapterJobCommand(com.vmware.flowgate.common.model.AdapterJobCommand) HttpHeaders(org.springframework.http.HttpHeaders) AssetController(com.vmware.flowgate.controller.AssetController) FacilityAdapter(com.vmware.flowgate.common.model.FacilityAdapter)

Example 4 with WormholeRequestException

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());
    }
}
Also used : WormholeRequestException(com.vmware.flowgate.exception.WormholeRequestException) AuthException(com.vmware.ops.api.client.exceptions.AuthException) VRopsAuth(com.vmware.flowgate.verifycert.VRopsAuth) SSLException(javax.net.ssl.SSLException) URISyntaxException(java.net.URISyntaxException) KeyStoreException(java.security.KeyStoreException) ConnectException(java.net.ConnectException) WormholeRequestException(com.vmware.flowgate.exception.WormholeRequestException) ConnectionException(com.vmware.vim.vmomi.client.exception.ConnectionException) SslException(com.vmware.vim.vmomi.client.exception.SslException) ResourceAccessException(org.springframework.web.client.ResourceAccessException) KeyManagementException(java.security.KeyManagementException) CertificateException(java.security.cert.CertificateException) AuthException(com.vmware.ops.api.client.exceptions.AuthException) UnknownHostException(java.net.UnknownHostException) HttpClientErrorException(org.springframework.web.client.HttpClientErrorException) SSLException(javax.net.ssl.SSLException) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) ConnectException(java.net.ConnectException)

Example 5 with WormholeRequestException

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);
}
Also used : WormholeRequestException(com.vmware.flowgate.exception.WormholeRequestException) AssetIPMapping(com.vmware.flowgate.common.model.AssetIPMapping) 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