Search in sources :

Example 6 with IntegrationStatus

use of com.vmware.flowgate.common.model.IntegrationStatus in project flowgate by vmware.

the class InfoBloxService method updateIntegrationStatusToWarning.

private void updateIntegrationStatusToWarning(FacilitySoftwareConfig infoblox, String ip) {
    IntegrationStatus integrationStatus = infoblox.getIntegrationStatus();
    if (integrationStatus == null) {
        integrationStatus = new IntegrationStatus();
    }
    integrationStatus.setStatus(IntegrationStatus.Status.WARNING);
    integrationStatus.setDetail(String.format("Unauthorized or ip:%s unmanaged", ip));
    infoblox.setIntegrationStatus(integrationStatus);
    updateIntegrationStatus(infoblox);
    logger.error("Update the infoblox status to warning because there is no permission or the ip unmanaged ip:{}", ip);
}
Also used : IntegrationStatus(com.vmware.flowgate.common.model.IntegrationStatus)

Example 7 with IntegrationStatus

use of com.vmware.flowgate.common.model.IntegrationStatus in project flowgate by vmware.

the class VCDataService method syncCustomAttributes.

private void syncCustomAttributes(SDDCSoftwareConfig vc) {
    try (VsphereClient vsphereClient = connectVsphere(vc)) {
        for (String key : VCConstants.hostCustomAttrMapping.values()) {
            vsphereClient.createCustomAttribute(key, VCConstants.HOSTSYSTEM);
        }
        // Add the PDU information;
        vsphereClient.createCustomAttribute(VCConstants.ASSET_PDUs, VCConstants.HOSTSYSTEM);
        // Add host switch information;
        vsphereClient.createCustomAttribute(VCConstants.ASSET_SWITCHs, VCConstants.HOSTSYSTEM);
    } catch (ConnectionException connectionException) {
        checkAndUpdateIntegrationStatus(vc, connectionException.getMessage());
        return;
    } catch (ExecutionException executionException) {
        if (executionException.getCause() instanceof InvalidLogin) {
            logger.error("Failed to push data to " + vc.getServerURL(), executionException);
            IntegrationStatus integrationStatus = vc.getIntegrationStatus();
            if (integrationStatus == null) {
                integrationStatus = new IntegrationStatus();
            }
            integrationStatus.setStatus(IntegrationStatus.Status.ERROR);
            integrationStatus.setDetail("Invalid username or password.");
            integrationStatus.setRetryCounter(FlowgateConstant.DEFAULTNUMBEROFRETRIES);
            updateIntegrationStatus(vc);
            return;
        }
    } catch (Exception exception) {
        logger.error("Failed to sync the host metadata to VC ", exception);
        return;
    }
    try (HostTagClient client = new HostTagClient(vc.getServerURL(), vc.getUserName(), vc.getPassword(), !vc.isVerifyCert())) {
        client.initConnection();
        TagModel tag = client.getTagByName(VCConstants.locationAntiAffinityTagName);
        String categoryID;
        if (tag == null) {
            CategoryModel category = client.getTagCategoryByName(VCConstants.categoryName);
            if (category == null) {
                categoryID = client.createTagCategory(VCConstants.categoryName, VCConstants.categoryDescription, Cardinality.MULTIPLE);
            } else {
                categoryID = category.getId();
            }
            client.createTag(VCConstants.locationAntiAffinityTagName, VCConstants.locationAntiAffinityTagDescription, categoryID);
        }
    } catch (Exception exception) {
        logger.error("Faild to check the predefined tag information", exception);
    }
}
Also used : VsphereClient(com.vmware.flowgate.vcworker.client.VsphereClient) IntegrationStatus(com.vmware.flowgate.common.model.IntegrationStatus) InvalidLogin(com.vmware.vim.binding.vim.fault.InvalidLogin) HostTagClient(com.vmware.flowgate.vcworker.client.HostTagClient) CategoryModel(com.vmware.cis.tagging.CategoryModel) ExecutionException(java.util.concurrent.ExecutionException) TagModel(com.vmware.cis.tagging.TagModel) ConnectionException(com.vmware.vim.vmomi.client.exception.ConnectionException) ConnectionException(com.vmware.vim.vmomi.client.exception.ConnectionException) IOException(java.io.IOException) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException) ExecutionException(java.util.concurrent.ExecutionException) HttpClientErrorException(org.springframework.web.client.HttpClientErrorException)

Example 8 with IntegrationStatus

use of com.vmware.flowgate.common.model.IntegrationStatus in project flowgate by vmware.

the class VCDataService method syncCustomerAttrsData.

private void syncCustomerAttrsData(SDDCSoftwareConfig vcInfo) {
    restClient.setServiceKey(serviceKeyConfig.getServiceKey());
    try (VsphereClient vsphereClient = connectVsphere(vcInfo)) {
        ServerMapping[] mappings = null;
        try {
            mappings = restClient.getServerMappingsByVC(vcInfo.getId()).getBody();
        } catch (HttpClientErrorException clientError) {
            if (clientError.getRawStatusCode() != HttpStatus.NOT_FOUND.value()) {
                throw clientError;
            }
            mappings = new ServerMapping[0];
        }
        HashMap<String, ServerMapping> mobIdDictionary = new HashMap<String, ServerMapping>();
        for (ServerMapping mapping : mappings) {
            mobIdDictionary.put(mapping.getVcMobID(), mapping);
        }
        List<ServerMapping> validMapping = new ArrayList<ServerMapping>();
        Collection<HostSystem> hosts = vsphereClient.getAllHost();
        Map<String, HostSystem> hostDictionary = new HashMap<String, HostSystem>();
        for (HostSystem host : hosts) {
            String mobId = host._getRef().getValue();
            String hostName = host.getName();
            if (mobIdDictionary.containsKey(mobId)) {
                ServerMapping serverMapping = mobIdDictionary.get(mobId);
                if (!serverMapping.getVcHostName().equals(hostName)) {
                    // need to update the hostname.
                    serverMapping.setVcHostName(hostName);
                    restClient.saveServerMapping(serverMapping);
                }
                if (serverMapping.getAsset() != null) {
                    validMapping.add(serverMapping);
                } else {
                    // check the hostNameIP mapping
                    String ipaddress = IPAddressUtil.getIPAddress(hostName);
                    if (null != ipaddress) {
                        AssetIPMapping[] ipMappings = restClient.getHostnameIPMappingByIP(ipaddress).getBody();
                        if (null != ipMappings && ipMappings.length > 0) {
                            // update the mapping
                            String assetName = ipMappings[0].getAssetname();
                            Asset asset = restClient.getAssetByName(assetName).getBody();
                            if (asset != null) {
                                serverMapping.setAsset(asset.getId());
                                restClient.saveServerMapping(serverMapping);
                                validMapping.add(serverMapping);
                                feedAssetMetricsFormulars(asset);
                            }
                        } else {
                            // seems we don't have the ip hostname mapping. Notify infoblox to check the ip
                            logger.info("Notify infoblox to check ip: " + ipaddress);
                            publisher.publish(null, ipaddress);
                        }
                    }
                }
                hostDictionary.put(mobId, host);
            } else {
                ServerMapping newMapping = new ServerMapping();
                newMapping.setVcHostName(hostName);
                newMapping.setVcID(vcInfo.getId());
                newMapping.setVcMobID(mobId);
                newMapping.setVcInstanceUUID(vsphereClient.getVCUUID());
                String ipaddress = IPAddressUtil.getIPAddress(hostName);
                logger.info(String.format("hostName %s, ipaddress: %s", hostName, ipaddress));
                // publish message to queue.
                if (null != ipaddress) {
                    logger.info("Notify infoblox");
                    publisher.publish(null, hostName);
                    AssetIPMapping[] ipMappings = restClient.getHostnameIPMappingByIP(ipaddress).getBody();
                    if (null != ipMappings && ipMappings.length > 0) {
                        // update the mapping
                        String assetName = ipMappings[0].getAssetname();
                        Asset asset = restClient.getAssetByName(assetName).getBody();
                        if (asset != null) {
                            newMapping.setAsset(asset.getId());
                            feedAssetMetricsFormulars(asset);
                        }
                    }
                }
                restClient.saveServerMapping(newMapping);
            }
        }
        // feed meta data to VC.
        Asset[] assets = restClient.getAssetsByVCID(vcInfo.getId()).getBody();
        Map<String, Asset> assetDictionary = new HashMap<String, Asset>();
        for (Asset asset : assets) {
            assetDictionary.put(asset.getId(), asset);
        }
        feedData(assetDictionary, validMapping, hostDictionary);
        validClusterHostsLocationAntiaffinity(vcInfo, assetDictionary, validMapping);
    } catch (ConnectionException connectionException) {
        checkAndUpdateIntegrationStatus(vcInfo, connectionException.getMessage());
        return;
    } catch (ExecutionException executionException) {
        if (executionException.getCause() instanceof InvalidLogin) {
            logger.error("Failed to push data to " + vcInfo.getServerURL(), executionException);
            IntegrationStatus integrationStatus = vcInfo.getIntegrationStatus();
            if (integrationStatus == null) {
                integrationStatus = new IntegrationStatus();
            }
            integrationStatus.setStatus(IntegrationStatus.Status.ERROR);
            integrationStatus.setDetail("Invalid username or password.");
            integrationStatus.setRetryCounter(FlowgateConstant.DEFAULTNUMBEROFRETRIES);
            updateIntegrationStatus(vcInfo);
            return;
        }
    } catch (Exception exception) {
        logger.error("Failed to push data to " + vcInfo.getServerURL(), exception);
    }
}
Also used : HttpClientErrorException(org.springframework.web.client.HttpClientErrorException) HashMap(java.util.HashMap) VsphereClient(com.vmware.flowgate.vcworker.client.VsphereClient) ServerMapping(com.vmware.flowgate.common.model.ServerMapping) IntegrationStatus(com.vmware.flowgate.common.model.IntegrationStatus) ArrayList(java.util.ArrayList) ConnectionException(com.vmware.vim.vmomi.client.exception.ConnectionException) IOException(java.io.IOException) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException) ExecutionException(java.util.concurrent.ExecutionException) HttpClientErrorException(org.springframework.web.client.HttpClientErrorException) AssetIPMapping(com.vmware.flowgate.common.model.AssetIPMapping) HostSystem(com.vmware.vim.binding.vim.HostSystem) InvalidLogin(com.vmware.vim.binding.vim.fault.InvalidLogin) Asset(com.vmware.flowgate.common.model.Asset) ExecutionException(java.util.concurrent.ExecutionException) ConnectionException(com.vmware.vim.vmomi.client.exception.ConnectionException)

Example 9 with IntegrationStatus

use of com.vmware.flowgate.common.model.IntegrationStatus in project flowgate by vmware.

the class VCDataServiceTest method testCheckAndUpdateIntegrationStatus.

@Test
public void testCheckAndUpdateIntegrationStatus() {
    SDDCSoftwareConfig vc = Mockito.spy(new SDDCSoftwareConfig());
    IntegrationStatus integrationStatus = Mockito.spy(new IntegrationStatus());
    String message = "message";
    vc.setIntegrationStatus(null);
    Mockito.doNothing().when(service).updateIntegrationStatus(any(SDDCSoftwareConfig.class));
    service.checkAndUpdateIntegrationStatus(vc, message);
    TestCase.assertEquals(1, vc.getIntegrationStatus().getRetryCounter());
    Mockito.when(vc.getIntegrationStatus()).thenReturn(integrationStatus);
    Mockito.when(integrationStatus.getRetryCounter()).thenReturn(FlowgateConstant.MAXNUMBEROFRETRIES);
    service.checkAndUpdateIntegrationStatus(vc, message);
    TestCase.assertEquals(IntegrationStatus.Status.ERROR, integrationStatus.getStatus());
    TestCase.assertEquals(message, integrationStatus.getDetail());
}
Also used : SDDCSoftwareConfig(com.vmware.flowgate.common.model.SDDCSoftwareConfig) IntegrationStatus(com.vmware.flowgate.common.model.IntegrationStatus) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) Test(org.junit.Test)

Example 10 with IntegrationStatus

use of com.vmware.flowgate.common.model.IntegrationStatus in project flowgate by vmware.

the class VROAsyncJob method checkAndUpdateIntegrationStatus.

public void checkAndUpdateIntegrationStatus(SDDCSoftwareConfig vro, String message) {
    IntegrationStatus integrationStatus = vro.getIntegrationStatus();
    if (integrationStatus == null) {
        integrationStatus = new IntegrationStatus();
    }
    int timesOftry = integrationStatus.getRetryCounter();
    timesOftry++;
    if (timesOftry < FlowgateConstant.MAXNUMBEROFRETRIES) {
        integrationStatus.setRetryCounter(timesOftry);
    } else {
        integrationStatus.setStatus(IntegrationStatus.Status.ERROR);
        integrationStatus.setDetail(message);
        integrationStatus.setRetryCounter(FlowgateConstant.DEFAULTNUMBEROFRETRIES);
        logger.error("Failed to sync data from VRO,error message is +" + message);
    }
    vro.setIntegrationStatus(integrationStatus);
    updateIntegrationStatus(vro);
}
Also used : IntegrationStatus(com.vmware.flowgate.common.model.IntegrationStatus)

Aggregations

IntegrationStatus (com.vmware.flowgate.common.model.IntegrationStatus)31 HttpClientErrorException (org.springframework.web.client.HttpClientErrorException)12 Asset (com.vmware.flowgate.common.model.Asset)10 ConnectException (java.net.ConnectException)10 IOException (java.io.IOException)8 FacilitySoftwareConfig (com.vmware.flowgate.common.model.FacilitySoftwareConfig)7 HashMap (java.util.HashMap)7 ResourceAccessException (org.springframework.web.client.ResourceAccessException)7 ArrayList (java.util.ArrayList)5 AssetIPMapping (com.vmware.flowgate.common.model.AssetIPMapping)3 RealTimeData (com.vmware.flowgate.common.model.RealTimeData)3 SDDCSoftwareConfig (com.vmware.flowgate.common.model.SDDCSoftwareConfig)3 NlyteAsset (com.vmware.flowgate.nlyteworker.model.NlyteAsset)3 PowerIQAPIClient (com.vmware.flowgate.poweriqworker.client.PowerIQAPIClient)3 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)2 AdvanceSettingType (com.vmware.flowgate.common.model.FacilitySoftwareConfig.AdvanceSettingType)2 ServerMapping (com.vmware.flowgate.common.model.ServerMapping)2 WormholeRequestException (com.vmware.flowgate.exception.WormholeRequestException)2 LocationGroup (com.vmware.flowgate.nlyteworker.model.LocationGroup)2 Manufacturer (com.vmware.flowgate.nlyteworker.model.Manufacturer)2