use of com.vmware.flowgate.common.model.SDDCSoftwareConfig in project flowgate by vmware.
the class NlyteDataService method removeInActiveData.
private void removeInActiveData(FacilitySoftwareConfig nlyte) {
NlyteAPIClient nlyteAPIclient = createClient(nlyte);
restClient.setServiceKey(serviceKeyConfig.getServiceKey());
List<Asset> servers = restClient.getAllAssetsBySourceAndType(nlyte.getId(), AssetCategory.Server);
List<Asset> pdus = restClient.getAllAssetsBySourceAndType(nlyte.getId(), AssetCategory.PDU);
List<Asset> networks = restClient.getAllAssetsBySourceAndType(nlyte.getId(), AssetCategory.Networks);
List<Asset> cabinets = restClient.getAllAssetsBySourceAndType(nlyte.getId(), AssetCategory.Cabinet);
long currentTime = System.currentTimeMillis();
// remove inactive pdus information from server and remove inactive pdus
long expiredTimeRange = FlowgateConstant.DEFAULTEXPIREDTIMERANGE;
String expiredTimeValue = template.opsForValue().get(EventMessageUtil.EXPIREDTIMERANGE);
if (expiredTimeValue != null) {
expiredTimeRange = Long.valueOf(expiredTimeValue);
}
for (Asset pdu : pdus) {
if (!pdu.isExpired(currentTime, expiredTimeRange)) {
continue;
}
NlyteAsset asset = nlyteAPIclient.getAssetbyAssetNumber(AssetCategory.PDU, pdu.getAssetNumber());
if (asset == null || !assetIsActived(asset, AssetCategory.PDU)) {
servers = removePduFromServer(servers, pdu.getId());
restClient.saveAssets(servers);
restClient.removeAssetByID(pdu.getId());
} else if (asset != null && assetIsActived(asset, AssetCategory.PDU)) {
pdu.setLastupdate(currentTime);
restClient.saveAssets(pdu);
}
}
// remove inactive network information from servers and remove inactive networks
for (Asset network : networks) {
if (!network.isExpired(currentTime, expiredTimeRange)) {
continue;
}
NlyteAsset asset = nlyteAPIclient.getAssetbyAssetNumber(AssetCategory.Networks, network.getAssetNumber());
if (asset == null || !assetIsActived(asset, AssetCategory.Networks)) {
servers = removeNetworkFromServer(servers, network.getId());
restClient.saveAssets(servers);
restClient.removeAssetByID(network.getId());
} else if (asset != null && assetIsActived(asset, AssetCategory.Networks)) {
network.setLastupdate(currentTime);
restClient.saveAssets(network);
}
}
// remove cabinets
for (Asset cabinet : cabinets) {
if (!cabinet.isExpired(currentTime, expiredTimeRange)) {
continue;
}
NlyteAsset asset = nlyteAPIclient.getAssetbyAssetNumber(AssetCategory.Cabinet, cabinet.getAssetNumber());
if (asset == null || !assetIsActived(asset, AssetCategory.Cabinet)) {
restClient.removeAssetByID(cabinet.getId());
} else if (asset != null && assetIsActived(asset, AssetCategory.Cabinet)) {
cabinet.setLastupdate(currentTime);
restClient.saveAssets(cabinet);
}
}
// get all serverMapping
SDDCSoftwareConfig[] vcs = restClient.getInternalSDDCSoftwareConfigByType(SDDCSoftwareConfig.SoftwareType.VCENTER).getBody();
SDDCSoftwareConfig[] vros = restClient.getInternalSDDCSoftwareConfigByType(SDDCSoftwareConfig.SoftwareType.VRO).getBody();
List<ServerMapping> mappings = new ArrayList<ServerMapping>();
for (SDDCSoftwareConfig vc : vcs) {
mappings.addAll(new ArrayList<>(Arrays.asList(restClient.getServerMappingsByVC(vc.getId()).getBody())));
}
for (SDDCSoftwareConfig vro : vros) {
mappings.addAll(new ArrayList<>(Arrays.asList(restClient.getServerMappingsByVRO(vro.getId()).getBody())));
}
// remove inactive asset from serverMapping and remove inactive servers
for (Asset server : servers) {
if (!server.isExpired(currentTime, expiredTimeRange)) {
continue;
}
NlyteAsset asset = nlyteAPIclient.getAssetbyAssetNumber(AssetCategory.Server, server.getAssetNumber());
if (asset == null || !assetIsActived(asset, AssetCategory.Server)) {
for (ServerMapping mapping : mappings) {
if (mapping.getAsset() == null) {
continue;
}
if (server.getId().equals(mapping.getAsset())) {
mapping.setAsset(null);
restClient.saveServerMapping(mapping);
}
}
restClient.removeAssetByID(server.getId());
} else if (asset != null && assetIsActived(asset, AssetCategory.Server)) {
server.setLastupdate(currentTime);
restClient.saveAssets(server);
}
}
}
use of com.vmware.flowgate.common.model.SDDCSoftwareConfig in project flowgate by vmware.
the class VCDataService method executeAsync.
@Override
@Async("asyncServiceExecutor")
public void executeAsync(EventMessage message) {
// update the value.
if (message.getType() != EventType.VCenter) {
logger.warn("Drop none vcenter message " + message.getType());
return;
}
// TO, this should be comment out since it may contain vc password.
logger.info("message received");
Set<EventUser> users = message.getTarget().getUsers();
for (EventUser command : users) {
logger.info(command.getId());
switch(command.getId()) {
case EventMessageUtil.VCENTER_SyncData:
// it will sync all the data depend on the type in the vcjoblist.
String messageString = null;
while ((messageString = template.opsForList().rightPop(EventMessageUtil.vcJobList)) != null) {
EventMessage payloadMessage = null;
try {
payloadMessage = mapper.readValue(messageString, EventMessageImpl.class);
} catch (IOException ioException) {
logger.error("Cannot process message", ioException);
}
if (payloadMessage == null) {
continue;
}
SDDCSoftwareConfig vcInfo = null;
try {
vcInfo = mapper.readValue(payloadMessage.getContent(), SDDCSoftwareConfig.class);
} catch (IOException ioException) {
logger.error("Cannot process message", ioException);
}
if (null == vcInfo) {
continue;
}
for (EventUser payloadCommand : payloadMessage.getTarget().getUsers()) {
switch(payloadCommand.getId()) {
case EventMessageUtil.VCENTER_SyncCustomerAttrs:
syncCustomAttributes(vcInfo);
logger.info("Finish sync customer attributes for " + vcInfo.getName());
break;
case EventMessageUtil.VCENTER_SyncCustomerAttrsData:
syncCustomerAttrsData(vcInfo);
logger.info("Finish sync data for " + vcInfo.getName());
break;
case EventMessageUtil.VCENTER_QueryHostMetaData:
queryHostMetaData(vcInfo);
logger.info("Finish query host metadata for " + vcInfo.getName());
break;
case EventMessageUtil.VCENTER_QueryHostUsageData:
queryHostMetrics(vcInfo);
logger.info("Finish query host usage for " + vcInfo.getName());
break;
default:
break;
}
}
}
break;
case EventMessageUtil.VCENTER_SyncCustomerAttrs:
logger.warn("VCENTER_SyncCustomerAttrs command is depreacted. use VCENTER_SyncData instead");
break;
case EventMessageUtil.VCENTER_SyncCustomerAttrsData:
logger.warn("VCENTER_SyncCustomerAttrsData command is depreacted. use VCENTER_SyncData instead");
break;
default:
logger.warn("Not supported command");
break;
}
}
}
use of com.vmware.flowgate.common.model.SDDCSoftwareConfig 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());
}
use of com.vmware.flowgate.common.model.SDDCSoftwareConfig in project flowgate by vmware.
the class VCDataServiceTest method testQueryHostMetrics.
@Test
public void testQueryHostMetrics() throws Exception {
SDDCSoftwareConfig vc = Mockito.mock(SDDCSoftwareConfig.class);
HashMap<String, ServerMapping> serverMappingMap = new HashMap<String, ServerMapping>();
ServerMapping mapping1 = new ServerMapping();
mapping1.setVcMobID("vc1");
mapping1.setAsset("asset1");
serverMappingMap.put(mapping1.getVcMobID(), mapping1);
ServerMapping mapping2 = new ServerMapping();
mapping2.setVcMobID("vc2");
mapping2.setAsset("asset2");
serverMappingMap.put(mapping2.getVcMobID(), mapping2);
doReturn(serverMappingMap).when(service).getVaildServerMapping(any());
doReturn(vsphereClient).when(service).connectVsphere(any());
HostSystem host1 = Mockito.mock(HostSystem.class);
HostSystem host2 = Mockito.mock(HostSystem.class);
Collection<HostSystem> hosts = new ArrayList<>();
hosts.add(host1);
hosts.add(host2);
when(vsphereClient.getAllHost()).thenReturn(hosts);
ManagedObjectReference mor1 = Mockito.mock(ManagedObjectReference.class);
ManagedObjectReference mor2 = Mockito.mock(ManagedObjectReference.class);
when(host1._getRef()).thenReturn(mor1);
when(mor1.getValue()).thenReturn("vc1");
when(host2._getRef()).thenReturn(mor2);
when(mor2.getValue()).thenReturn("vc2");
Asset asset = new Asset();
asset.setId("asset1");
Map<String, String> metricsFormulars = new HashMap<>();
Map<String, String> metrics = new HashMap<>();
metricsFormulars.put(FlowgateConstant.HOST_METRICS, mapper.writeValueAsString(metrics));
asset.setMetricsformulars(metricsFormulars);
ResponseEntity<Asset> assets = Mockito.mock(ResponseEntity.class);
when(restClient.getAssetByID(anyString())).thenReturn(assets);
when(assets.getBody()).thenReturn(asset);
doNothing().when(service).feedHostUsageData(any(), any(), any());
service.queryHostMetrics(vc);
}
use of com.vmware.flowgate.common.model.SDDCSoftwareConfig in project flowgate by vmware.
the class VCDataServiceTest method testQueryHostMetaDataForclustersIsNull.
@Test
public void testQueryHostMetaDataForclustersIsNull() throws Exception {
SDDCSoftwareConfig vc = Mockito.mock(SDDCSoftwareConfig.class);
HashMap<String, ServerMapping> serverMappingMap = new HashMap<String, ServerMapping>();
ServerMapping mapping1 = new ServerMapping();
mapping1.setVcMobID("vc1");
mapping1.setAsset("asset1");
serverMappingMap.put(mapping1.getVcMobID(), mapping1);
ServerMapping mapping2 = new ServerMapping();
mapping2.setVcMobID("vc2");
mapping2.setAsset("asset2");
serverMappingMap.put(mapping2.getVcMobID(), mapping2);
doReturn(serverMappingMap).when(service).getVaildServerMapping(any());
doReturn(vsphereClient).when(service).connectVsphere(any());
HostSystem host1 = Mockito.mock(HostSystem.class);
HostSystem host2 = Mockito.mock(HostSystem.class);
Collection<HostSystem> hosts = new ArrayList<>();
hosts.add(host1);
hosts.add(host2);
when(vsphereClient.getAllHost()).thenReturn(hosts);
when(vsphereClient.getAllClusterComputeResource()).thenReturn(null);
ManagedObjectReference mor1 = Mockito.mock(ManagedObjectReference.class);
ManagedObjectReference mor2 = Mockito.mock(ManagedObjectReference.class);
when(host1._getRef()).thenReturn(mor1);
when(mor1.getValue()).thenReturn("vc1");
when(host2._getRef()).thenReturn(mor2);
when(mor2.getValue()).thenReturn("vc2");
Asset asset = new Asset();
asset.setId("asset1");
HashMap<String, String> hostJustification = new HashMap<String, String>();
HostInfo hostInfo = new HostInfo();
String vcHostObjStr = mapper.writeValueAsString(hostInfo);
hostJustification.put(FlowgateConstant.HOST_METADATA, vcHostObjStr);
asset.setJustificationfields(hostJustification);
ResponseEntity<Asset> assets = Mockito.mock(ResponseEntity.class);
when(restClient.getAssetByID(anyString())).thenReturn(assets);
when(assets.getBody()).thenReturn(asset);
doReturn(true).when(service).feedHostMetaData(any(), any());
doReturn(true).when(service).feedClusterMetaData(any(), any(), any(), anyString());
service.queryHostMetaData(vc);
}
Aggregations