use of com.vmware.flowgate.common.model.redis.message.EventMessage in project flowgate by vmware.
the class VCDataServiceTest method testSyncCustomerAttrsData.
@Test
public void testSyncCustomerAttrsData() throws Exception {
String assetId = "QONVN1098G1NVN01NG01";
String vcMobID = "host-11";
SDDCSoftwareConfig sddcSoftwareConfig = new SDDCSoftwareConfig();
sddcSoftwareConfig.setType(SDDCSoftwareConfig.SoftwareType.VCENTER);
sddcSoftwareConfig.setServerURL("https://1.1.1.1");
sddcSoftwareConfig.setPassword("ASDFGAGAHAHwegqhwrjw");
sddcSoftwareConfig.setVerifyCert(false);
EventMessage eventMessage = EventMessageUtil.createEventMessage(EventType.VCenter, EventMessageUtil.VCENTER_SyncCustomerAttrsData, mapper.writeValueAsString(sddcSoftwareConfig));
ListOperations<String, String> listOperations = Mockito.mock(ListOperations.class);
doReturn(listOperations).when(template).opsForList();
doReturn(mapper.writeValueAsString(eventMessage), null).when(listOperations).rightPop(EventMessageUtil.vcJobList);
doReturn(vsphereClient).when(service).connectVsphere(any());
ServerMapping serverMapping = new ServerMapping();
serverMapping.setVcMobID(vcMobID);
serverMapping.setVcHostName("server-1");
serverMapping.setAsset(assetId);
ServerMapping[] serverMappings = { serverMapping };
doReturn(new ResponseEntity<>(serverMappings, HttpStatus.OK)).when(restClient).getServerMappingsByVC(any());
Collection<HostSystem> hostSystems = new ArrayList<>();
HostSystem hostSystem = mock(HostSystem.class);
ManagedObjectReference managedObjectReference = mock(ManagedObjectReference.class);
hostSystems.add(hostSystem);
doReturn(managedObjectReference).when(hostSystem)._getRef();
doReturn("server-1").when(hostSystem).getName();
doReturn(vcMobID).when(managedObjectReference).getValue();
doReturn(hostSystems).when(vsphereClient).getAllHost();
Asset asset = new Asset();
asset.setId(assetId);
Map<String, String> metricsFormulas = new HashMap<>();
Map<String, String> hostMetricsFormula = new HashMap<>();
hostMetricsFormula.put(MetricName.SERVER_TEMPERATURE, asset.getId());
hostMetricsFormula.put(MetricName.SERVER_PEAK_TEMPERATURE, asset.getId());
hostMetricsFormula.put(MetricName.SERVER_AVERAGE_TEMPERATURE, asset.getId());
hostMetricsFormula.put(MetricName.SERVER_ENERGY_CONSUMPTION, asset.getId());
hostMetricsFormula.put(MetricName.SERVER_POWER, asset.getId());
hostMetricsFormula.put(MetricName.SERVER_AVERAGE_USED_POWER, asset.getId());
hostMetricsFormula.put(MetricName.SERVER_PEAK_USED_POWER, asset.getId());
hostMetricsFormula.put(MetricName.SERVER_MINIMUM_USED_POWER, asset.getId());
metricsFormulas.put(FlowgateConstant.HOST_METRICS, asset.metricsFormulaToString(hostMetricsFormula));
asset.setMetricsformulars(metricsFormulas);
Asset[] assets = { asset };
doReturn(new ResponseEntity<>(assets, HttpStatus.OK)).when(restClient).getAssetsByVCID(any());
doReturn(new ResponseEntity<Void>(HttpStatus.OK)).when(restClient).saveAssets(any(Asset.class));
service.executeAsync(EventMessageUtil.createEventMessage(EventType.VCenter, EventMessageUtil.VCENTER_SyncData, null));
}
use of com.vmware.flowgate.common.model.redis.message.EventMessage 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;
}
use of com.vmware.flowgate.common.model.redis.message.EventMessage in project flowgate by vmware.
the class EventMessageUtil method generateSDDCMessageListByType.
public static List<String> generateSDDCMessageListByType(EventType type, String targetCommand, SDDCSoftwareConfig[] sddcs) throws JsonProcessingException {
List<String> result = new ArrayList<String>();
for (SDDCSoftwareConfig sddc : sddcs) {
String payload = mapper.writeValueAsString(sddc);
EventMessage message = EventMessageUtil.createEventMessage(type, targetCommand, payload);
result.add(mapper.writeValueAsString(message));
}
return result;
}
Aggregations