Search in sources :

Example 31 with EventMessage

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));
}
Also used : HashMap(java.util.HashMap) ServerMapping(com.vmware.flowgate.common.model.ServerMapping) ArrayList(java.util.ArrayList) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) SDDCSoftwareConfig(com.vmware.flowgate.common.model.SDDCSoftwareConfig) EventMessage(com.vmware.flowgate.common.model.redis.message.EventMessage) HostSystem(com.vmware.vim.binding.vim.HostSystem) Asset(com.vmware.flowgate.common.model.Asset) ManagedObjectReference(com.vmware.vim.binding.vmodl.ManagedObjectReference) Test(org.junit.Test)

Example 32 with EventMessage

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;
}
Also used : EventMessage(com.vmware.flowgate.common.model.redis.message.EventMessage) ArrayList(java.util.ArrayList) FacilitySoftwareConfig(com.vmware.flowgate.common.model.FacilitySoftwareConfig)

Example 33 with EventMessage

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;
}
Also used : SDDCSoftwareConfig(com.vmware.flowgate.common.model.SDDCSoftwareConfig) EventMessage(com.vmware.flowgate.common.model.redis.message.EventMessage) ArrayList(java.util.ArrayList)

Aggregations

EventMessage (com.vmware.flowgate.common.model.redis.message.EventMessage)33 IOException (java.io.IOException)24 EventUser (com.vmware.flowgate.common.model.redis.message.EventUser)8 EventMessageImpl (com.vmware.flowgate.common.model.redis.message.impl.EventMessageImpl)8 FacilitySoftwareConfig (com.vmware.flowgate.common.model.FacilitySoftwareConfig)7 Test (org.junit.Test)6 SDDCSoftwareConfig (com.vmware.flowgate.common.model.SDDCSoftwareConfig)5 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)5 Asset (com.vmware.flowgate.common.model.Asset)4 WormholeRequestException (com.vmware.flowgate.exception.WormholeRequestException)4 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)4 ResponseStatus (org.springframework.web.bind.annotation.ResponseStatus)4 ArrayList (java.util.ArrayList)3 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)3 Async (org.springframework.scheduling.annotation.Async)3 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)2 AssetIPMapping (com.vmware.flowgate.common.model.AssetIPMapping)2 Date (java.util.Date)2 AdapterJobCommand (com.vmware.flowgate.common.model.AdapterJobCommand)1 IntegrationStatus (com.vmware.flowgate.common.model.IntegrationStatus)1