use of com.vmware.flowgate.common.model.FacilitySoftwareConfig in project flowgate by vmware.
the class SystemSummaryTest method testSummaryRepo.
@Test
public void testSummaryRepo() throws IOException {
ValueOperations<String, String> valueOperations = Mockito.mock(ValueOperations.class);
Mockito.doReturn(valueOperations).when(template).opsForValue();
FacilitySoftwareConfig nlyte1 = createFacility();
nlyte1.setType(com.vmware.flowgate.common.model.FacilitySoftwareConfig.SoftwareType.Nlyte);
nlyte1 = facilityrepo.save(nlyte1);
FacilitySoftwareConfig powerIQ1 = createFacility();
powerIQ1.setType(com.vmware.flowgate.common.model.FacilitySoftwareConfig.SoftwareType.PowerIQ);
powerIQ1 = facilityrepo.save(powerIQ1);
Asset nlyteServer1 = createAsset();
nlyteServer1.setCategory(AssetCategory.Server);
nlyteServer1.setAssetSource(nlyte1.getId());
nlyteServer1 = assetrepo.save(nlyteServer1);
Asset nlyteServer2 = createAsset();
nlyteServer2.setCategory(AssetCategory.Server);
nlyteServer2.setAssetSource(nlyte1.getId());
nlyteServer2 = assetrepo.save(nlyteServer2);
Asset nlytePDU1 = createAsset();
nlytePDU1.setCategory(AssetCategory.PDU);
nlytePDU1.setAssetSource(nlyte1.getId());
nlytePDU1 = assetrepo.save(nlytePDU1);
Asset nlytePDU2 = createAsset();
nlytePDU2.setCategory(AssetCategory.PDU);
nlytePDU2.setAssetSource(nlyte1.getId());
nlytePDU2 = assetrepo.save(nlytePDU2);
Asset powerIQSensor1 = createAsset();
powerIQSensor1.setCategory(AssetCategory.Sensors);
powerIQSensor1.setSubCategory(AssetSubCategory.Humidity);
powerIQSensor1.setAssetSource(powerIQ1.getId());
powerIQSensor1 = assetrepo.save(powerIQSensor1);
Asset powerIQSensor2 = createAsset();
powerIQSensor2.setCategory(AssetCategory.Sensors);
powerIQSensor2.setSubCategory(AssetSubCategory.Humidity);
powerIQSensor2.setAssetSource(powerIQ1.getId());
powerIQSensor2 = assetrepo.save(powerIQSensor2);
Asset powerIQSensor3 = createAsset();
powerIQSensor3.setCategory(AssetCategory.Sensors);
powerIQSensor3.setSubCategory(AssetSubCategory.Temperature);
powerIQSensor3.setAssetSource(powerIQ1.getId());
powerIQSensor3 = assetrepo.save(powerIQSensor3);
Asset powerIQSensor4 = createAsset();
powerIQSensor4.setCategory(AssetCategory.Sensors);
powerIQSensor4.setSubCategory(AssetSubCategory.Temperature);
powerIQSensor4.setAssetSource(powerIQ1.getId());
powerIQSensor4 = assetrepo.save(powerIQSensor4);
SDDCSoftwareConfig vro1 = createSDDC();
vro1.setType(SoftwareType.VRO);
vro1 = sddcrepo.save(vro1);
SDDCSoftwareConfig vro2 = createSDDC();
vro2.setType(SoftwareType.VRO);
vro2 = sddcrepo.save(vro2);
SDDCSoftwareConfig vc1 = createSDDC();
vc1.setType(SoftwareType.VCENTER);
vc1 = sddcrepo.save(vc1);
SDDCSoftwareConfig vc2 = createSDDC();
vc2.setType(SoftwareType.VCENTER);
vc2 = sddcrepo.save(vc2);
ServerMapping server1 = createServerMapping();
server1.setVroID(vro1.getId());
server1 = mappingrepo.save(server1);
ServerMapping server2 = createServerMapping();
server2.setVroID(vro1.getId());
server2 = mappingrepo.save(server2);
ServerMapping server3 = createServerMapping();
server3.setVcID(vc1.getId());
server3 = mappingrepo.save(server3);
ServerMapping server4 = createServerMapping();
server4.setVcID(vc2.getId());
server4 = mappingrepo.save(server4);
ServerMapping server5 = createServerMapping();
server5.setVroID(vro2.getId());
server5 = mappingrepo.save(server5);
try {
Thread.sleep(3000);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
try {
SystemSummary data = summaryService.getSystemResult(false);
TestCase.assertEquals(8, data.getAssetsNum());
TestCase.assertEquals(2, data.getFacilitySystemNum());
TestCase.assertEquals(4, data.getSddcIntegrationNum());
TestCase.assertEquals(2, data.getHumiditySensorNum());
TestCase.assertEquals(2, data.getTemperatureSensorNum());
TestCase.assertEquals(4, data.getSensorNum());
TestCase.assertEquals(2, data.getPduNum());
TestCase.assertEquals(2, data.getServerNum());
TestCase.assertEquals(5, data.getSddcServerNum());
TestCase.assertEquals(2, data.getVroNum());
TestCase.assertEquals(2, data.getVcNum());
} finally {
facilityrepo.deleteById(nlyte1.getId());
facilityrepo.deleteById(powerIQ1.getId());
assetrepo.deleteById(nlyteServer1.getId());
assetrepo.deleteById(nlyteServer2.getId());
assetrepo.deleteById(nlytePDU1.getId());
assetrepo.deleteById(nlytePDU2.getId());
assetrepo.deleteById(powerIQSensor1.getId());
assetrepo.deleteById(powerIQSensor2.getId());
assetrepo.deleteById(powerIQSensor3.getId());
assetrepo.deleteById(powerIQSensor4.getId());
sddcrepo.deleteById(vc1.getId());
sddcrepo.deleteById(vc2.getId());
sddcrepo.deleteById(vro1.getId());
sddcrepo.deleteById(vro2.getId());
mappingrepo.deleteById(server1.getId());
mappingrepo.deleteById(server2.getId());
mappingrepo.deleteById(server3.getId());
mappingrepo.deleteById(server4.getId());
mappingrepo.deleteById(server5.getId());
}
}
use of com.vmware.flowgate.common.model.FacilitySoftwareConfig in project flowgate by vmware.
the class SummaryService method getNlyteSummaryList.
public List<NlyteSummary> getNlyteSummaryList() {
List<NlyteSummary> nlyteSummarys = new ArrayList<>();
List<FacilitySoftwareConfig> facility = facilityRepo.findAllByType(com.vmware.flowgate.common.model.FacilitySoftwareConfig.SoftwareType.Nlyte.name());
for (FacilitySoftwareConfig nlyte : facility) {
NlyteSummary nlyteSummary = getNlyteSummary(nlyte);
nlyteSummarys.add(nlyteSummary);
}
return nlyteSummarys;
}
use of com.vmware.flowgate.common.model.FacilitySoftwareConfig in project flowgate by vmware.
the class SummaryService method getPowerIQSummaryList.
public List<PowerIqSummary> getPowerIQSummaryList() {
List<PowerIqSummary> powerIqSummarys = new ArrayList<PowerIqSummary>();
List<FacilitySoftwareConfig> facility = facilityRepo.findAllByType(com.vmware.flowgate.common.model.FacilitySoftwareConfig.SoftwareType.PowerIQ.name());
for (FacilitySoftwareConfig powerIq : facility) {
PowerIqSummary powerIQSummary = getPowerIQSummary(powerIq);
powerIqSummarys.add(powerIQSummary);
}
return powerIqSummarys;
}
use of com.vmware.flowgate.common.model.FacilitySoftwareConfig in project flowgate by vmware.
the class InfoBloxService method executeAsync.
@Override
@Async("asyncServiceExecutor")
public void executeAsync(EventMessage eventMessage) {
// The data format of the message. should be an ip address.
// Do the business here.
String message = eventMessage.getContent();
logger.info(String.format("Try to find hostname for ip: %s", message));
// check message , make sure it is an valid ip address;
wormholeAPIClient.setServiceKey(serviceKeyConfig.getServiceKey());
FacilitySoftwareConfig[] infoBloxes = wormholeAPIClient.getFacilitySoftwareInternalByType(SoftwareType.InfoBlox).getBody();
List<InfoBloxIPInfoResult> infoBloxIPInfoResults = new ArrayList<>();
List<InfoBloxIPInfoResult> hostRecordResults = null;
List<InfoBloxIPInfoResult> ipv4addressResults = null;
for (FacilitySoftwareConfig infoblox : infoBloxes) {
if (!infoblox.checkIsActive()) {
continue;
}
InfobloxClient client = buildInfobloxClient(infoblox);
IntegrationStatus integrationStatus = infoblox.getIntegrationStatus();
IntegrationStatus.Status status = integrationStatus == null ? null : integrationStatus.getStatus();
try {
if (status == null || IntegrationStatus.Status.ACTIVE.equals(status)) {
hostRecordResults = client.queryHostRecordByIP(message);
logger.debug("queryHostRecordByIP: {}", hostRecordResults);
if (hostRecordResults != null && !hostRecordResults.isEmpty()) {
infoBloxIPInfoResults.addAll(hostRecordResults);
}
}
if (hostRecordResults == null || hostRecordResults.isEmpty()) {
ipv4addressResults = client.queryIpv4addressByIP(message);
logger.debug("queryHostNamesByIP: {}", ipv4addressResults);
if (ipv4addressResults != null && !ipv4addressResults.isEmpty()) {
infoBloxIPInfoResults.addAll(ipv4addressResults);
}
if (!IntegrationStatus.Status.WARNING.equals(status) && ipv4addressResults != null) {
updateIntegrationStatusToWarning(infoblox, message);
}
}
} catch (ResourceAccessException e) {
if (e.getCause().getCause() instanceof ConnectException) {
checkAndUpdateIntegrationStatus(infoblox, e.getCause().getCause().getMessage());
continue;
}
} catch (HttpClientErrorException e1) {
logger.error("Failed to query data from Infoblox", e1);
if (integrationStatus == null) {
integrationStatus = new IntegrationStatus();
}
integrationStatus.setStatus(IntegrationStatus.Status.ERROR);
integrationStatus.setDetail(e1.getMessage());
integrationStatus.setRetryCounter(FlowgateConstant.DEFAULTNUMBEROFRETRIES);
infoblox.setIntegrationStatus(integrationStatus);
updateIntegrationStatus(infoblox);
continue;
}
if (integrationStatus != null && integrationStatus.getRetryCounter() > 0) {
integrationStatus.setRetryCounter(FlowgateConstant.DEFAULTNUMBEROFRETRIES);
updateIntegrationStatus(infoblox);
}
if (!infoBloxIPInfoResults.isEmpty()) {
for (InfoBloxIPInfoResult infoBloxIPInfoResult : infoBloxIPInfoResults) {
try {
Asset asset = wormholeAPIClient.getAssetByName(infoBloxIPInfoResult.getHostName()).getBody();
if (asset == null) {
logger.info(String.format("hostname (%s) no found!", infoBloxIPInfoResult.getHostName()));
continue;
}
} catch (HttpClientErrorException e) {
logger.error(String.format("Error when searching %s", infoBloxIPInfoResult.getHostName()), e);
continue;
}
AssetIPMapping tempMapping = new AssetIPMapping();
tempMapping.setAssetname(infoBloxIPInfoResult.getHostName());
tempMapping.setMacAddress(infoBloxIPInfoResult.getMacAddress());
tempMapping.setIp(message);
AssetIPMapping[] mappings = wormholeAPIClient.getHostnameIPMappingByIP(message).getBody();
boolean isNewMapping = true;
if (null != mappings && mappings.length > 0) {
for (AssetIPMapping mapping : mappings) {
if (tempMapping.getAssetname().equals(mapping.getAssetname())) {
if (!StringUtils.equals(mapping.getMacAddress(), tempMapping.getMacAddress())) {
mapping.setMacAddress(tempMapping.getMacAddress());
wormholeAPIClient.updateHostnameIPMapping(mapping);
}
isNewMapping = false;
break;
}
}
}
if (isNewMapping) {
wormholeAPIClient.createHostnameIPMapping(tempMapping);
}
logger.info(String.format("Find hostname %s for ip %s", infoBloxIPInfoResult.getHostName(), message));
return;
}
}
}
logger.info(String.format("Cannot find the hostname for IP: %s", message));
}
use of com.vmware.flowgate.common.model.FacilitySoftwareConfig in project flowgate by vmware.
the class EventMessageUtil method generateFacilityMessageListByType.
public static List<String> generateFacilityMessageListByType(EventType type, String targetCommand, FacilitySoftwareConfig[] facilites) throws JsonProcessingException {
List<String> result = new ArrayList<String>();
for (FacilitySoftwareConfig facility : facilites) {
String payload = mapper.writeValueAsString(facility);
EventMessage message = EventMessageUtil.createEventMessage(type, targetCommand, payload);
result.add(mapper.writeValueAsString(message));
}
return result;
}
Aggregations