Search in sources :

Example 1 with OpenManageAPIClient

use of com.vmware.flowgate.openmanage.client.OpenManageAPIClient in project flowgate by vmware.

the class OpenManageJobService method syncMetadataJob.

private void syncMetadataJob(FacilitySoftwareConfig integration) {
    wormholeApiClient.setServiceKey(serviceKeyConfig.getServiceKey());
    // check the status of integration
    try (OpenManageAPIClient client = createClient(integration)) {
        checkConnection(client, integration);
        // sync server
        List<Asset> oldServers = wormholeApiClient.getAllAssetsBySourceAndType(integration.getId(), AssetCategory.Server);
        Map<Long, Asset> assetNumberMap = generateAssetNumberMap(oldServers);
        int skip = defaultSkip;
        while (true) {
            CommonResult<Server> serversResult = client.getDevices(skip, defaultPageSize, Server.class);
            int totalCount = serversResult.getCount();
            if (totalCount == defaultSkip) {
                logger.info("Not found server from : {}.", integration.getName());
                break;
            }
            if (!serversResult.getValue().isEmpty()) {
                List<Asset> serverAssetsToSave = handleServerAssets(serversResult, assetNumberMap, integration.getId());
                if (!serverAssetsToSave.isEmpty()) {
                    List<Asset> openmanageServerToUpdate = new ArrayList<Asset>();
                    for (Asset asset : serverAssetsToSave) {
                        ResponseEntity<Void> res = wormholeApiClient.saveAssets(asset);
                        if (res.getStatusCode().is2xxSuccessful()) {
                            String uriPath = res.getHeaders().getLocation().getPath();
                            String id = uriPath.substring(uriPath.lastIndexOf("/") + 1);
                            asset.setId(id);
                            createMetricFormulas(asset);
                            openmanageServerToUpdate.add(asset);
                        }
                    }
                    // update asset about metricsFormula
                    wormholeApiClient.saveAssets(openmanageServerToUpdate);
                }
            }
            skip += defaultPageSize;
            if (skip > totalCount) {
                break;
            }
        }
        // sync chassis
        List<Asset> oldChassis = wormholeApiClient.getAllAssetsBySourceAndType(integration.getId(), AssetCategory.Chassis);
        Map<Long, Asset> chassisAssetNumberMap = generateAssetNumberMap(oldChassis);
        int chassiItemSkip = defaultSkip;
        while (true) {
            CommonResult<Chassis> chassisResult = client.getDevices(chassiItemSkip, defaultPageSize, Chassis.class);
            int totalCount = chassisResult.getCount();
            if (totalCount == defaultSkip) {
                logger.info("Not found chassis from : {}.", integration.getName());
                break;
            }
            if (!chassisResult.getValue().isEmpty()) {
                List<Asset> chassiAssetsToSave = handleChassisAssets(chassisResult, chassisAssetNumberMap, integration.getId());
                if (!chassiAssetsToSave.isEmpty()) {
                    wormholeApiClient.saveAssets(chassiAssetsToSave);
                }
            }
            chassiItemSkip += defaultPageSize;
            if (chassiItemSkip > totalCount) {
                break;
            }
        }
    }
}
Also used : Chassis(com.vmware.flowgate.openmanage.datamodel.Chassis) Server(com.vmware.flowgate.openmanage.datamodel.Server) ArrayList(java.util.ArrayList) OpenManageAPIClient(com.vmware.flowgate.openmanage.client.OpenManageAPIClient) Asset(com.vmware.flowgate.common.model.Asset)

Example 2 with OpenManageAPIClient

use of com.vmware.flowgate.openmanage.client.OpenManageAPIClient in project flowgate by vmware.

the class OpenManageJobService method syncMetricsDataJob.

private void syncMetricsDataJob(FacilitySoftwareConfig integration) {
    wormholeApiClient.setServiceKey(serviceKeyConfig.getServiceKey());
    // check the status of integration
    try (OpenManageAPIClient client = createClient(integration)) {
        checkConnection(client, integration);
        List<RealTimeData> metricData = getMetricDatas(integration, client);
        if (metricData.isEmpty()) {
            logger.info("Not found any metrics data from " + integration.getName());
            return;
        }
        wormholeApiClient.saveRealTimeData(metricData);
    }
}
Also used : RealTimeData(com.vmware.flowgate.common.model.RealTimeData) OpenManageAPIClient(com.vmware.flowgate.openmanage.client.OpenManageAPIClient)

Aggregations

OpenManageAPIClient (com.vmware.flowgate.openmanage.client.OpenManageAPIClient)2 Asset (com.vmware.flowgate.common.model.Asset)1 RealTimeData (com.vmware.flowgate.common.model.RealTimeData)1 Chassis (com.vmware.flowgate.openmanage.datamodel.Chassis)1 Server (com.vmware.flowgate.openmanage.datamodel.Server)1 ArrayList (java.util.ArrayList)1