Search in sources :

Example 21 with EventMessage

use of com.vmware.flowgate.common.model.redis.message.EventMessage in project flowgate by vmware.

the class InfobloxServiceTest method testExecuteAsyncInvokeRecordHost.

@Test
public void testExecuteAsyncInvokeRecordHost() {
    EventMessage eventMessage = EventMessageUtil.createEventMessage(EventType.InfoBlox, null, "10.161.71.154");
    ResponseEntity<FacilitySoftwareConfig[]> infobloxFacilitySoftware = this.getInfobloxFacilitySoftware();
    Mockito.doReturn(this.getInfoBloxIPInfoResults()).when(infobloxClient).queryHostRecordByIP(Mockito.anyString());
    Mockito.doReturn(new ResponseEntity<>(new Asset(), HttpStatus.OK)).when(wormholeAPIClient).getAssetByName(Mockito.anyString());
    Mockito.doReturn(infobloxFacilitySoftware).when(wormholeAPIClient).getFacilitySoftwareInternalByType(FacilitySoftwareConfig.SoftwareType.InfoBlox);
    Mockito.doReturn(new ResponseEntity<>(new AssetIPMapping[0], HttpStatus.OK)).when(wormholeAPIClient).getHostnameIPMappingByIP(Mockito.anyString());
    infoBloxService.executeAsync(eventMessage);
    TestCase.assertEquals(IntegrationStatus.Status.ACTIVE, Objects.requireNonNull(infobloxFacilitySoftware.getBody())[0].getIntegrationStatus().getStatus());
}
Also used : EventMessage(com.vmware.flowgate.common.model.redis.message.EventMessage) AssetIPMapping(com.vmware.flowgate.common.model.AssetIPMapping) Asset(com.vmware.flowgate.common.model.Asset) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 22 with EventMessage

use of com.vmware.flowgate.common.model.redis.message.EventMessage in project flowgate by vmware.

the class InfobloxServiceTest method testExecuteAsyncInvokeIPv4.

@Test
public void testExecuteAsyncInvokeIPv4() {
    EventMessage eventMessage = EventMessageUtil.createEventMessage(EventType.InfoBlox, null, "10.161.71.154");
    ResponseEntity<FacilitySoftwareConfig[]> infobloxFacilitySoftware = this.getInfobloxFacilitySoftware();
    Mockito.doReturn(new ArrayList<>()).when(infobloxClient).queryHostRecordByIP(Mockito.anyString());
    Mockito.doReturn(this.getInfoBloxIPInfoResults()).when(infobloxClient).queryIpv4addressByIP(Mockito.anyString());
    Mockito.doReturn(new ResponseEntity<>(new Asset(), HttpStatus.OK)).when(wormholeAPIClient).getAssetByName(Mockito.anyString());
    Mockito.doReturn(infobloxFacilitySoftware).when(wormholeAPIClient).getFacilitySoftwareInternalByType(FacilitySoftwareConfig.SoftwareType.InfoBlox);
    Mockito.doReturn(new ResponseEntity<>(new AssetIPMapping[0], HttpStatus.OK)).when(wormholeAPIClient).getHostnameIPMappingByIP(Mockito.anyString());
    infoBloxService.executeAsync(eventMessage);
    TestCase.assertEquals(IntegrationStatus.Status.WARNING, Objects.requireNonNull(infobloxFacilitySoftware.getBody())[0].getIntegrationStatus().getStatus());
}
Also used : EventMessage(com.vmware.flowgate.common.model.redis.message.EventMessage) AssetIPMapping(com.vmware.flowgate.common.model.AssetIPMapping) Asset(com.vmware.flowgate.common.model.Asset) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 23 with EventMessage

use of com.vmware.flowgate.common.model.redis.message.EventMessage in project flowgate by vmware.

the class LabsdbService method executeAsync.

@Override
public void executeAsync(EventMessage message) {
    // TODO Auto-generated method stub
    if (message.getType() != EventType.Labsdb) {
        logger.warn("Drop none Labsdb message " + message.getType());
        return;
    }
    logger.info("message received");
    Set<EventUser> users = message.getTarget().getUsers();
    for (EventUser command : users) {
        logger.info(command.getId());
        switch(command.getId()) {
            case EventMessageUtil.Labsdb_SyncData:
                // it will sync all the data depend on the type in the labsdbJobList.
                String messageString = null;
                while ((messageString = template.opsForList().rightPop(EventMessageUtil.labsdbJobList)) != null) {
                    EventMessage payloadMessage = null;
                    try {
                        payloadMessage = mapper.readValue(messageString, EventMessageImpl.class);
                    } catch (IOException e) {
                        logger.error("Cannot process message", e);
                    }
                    if (payloadMessage == null) {
                        continue;
                    }
                    FacilitySoftwareConfig labsdb = null;
                    try {
                        labsdb = mapper.readValue(payloadMessage.getContent(), FacilitySoftwareConfig.class);
                    } catch (IOException e) {
                        logger.error("Cannot process message", e);
                    }
                    if (null == labsdb) {
                        continue;
                    }
                    if (!labsdb.checkIsActive()) {
                        continue;
                    }
                    for (EventUser payloadCommand : payloadMessage.getTarget().getUsers()) {
                        excuteJob(payloadCommand.getId(), labsdb);
                    }
                }
                break;
            default:
                FacilitySoftwareConfig labsdb = null;
                try {
                    labsdb = mapper.readValue(message.getContent(), FacilitySoftwareConfig.class);
                } catch (IOException e1) {
                    // TODO Auto-generated catch block
                    logger.error("Failed to convert message", e1);
                }
                if (labsdb != null) {
                    excuteJob(command.getId(), labsdb);
                }
                break;
        }
    }
}
Also used : EventMessage(com.vmware.flowgate.common.model.redis.message.EventMessage) EventUser(com.vmware.flowgate.common.model.redis.message.EventUser) EventMessageImpl(com.vmware.flowgate.common.model.redis.message.impl.EventMessageImpl) FacilitySoftwareConfig(com.vmware.flowgate.common.model.FacilitySoftwareConfig) IOException(java.io.IOException)

Example 24 with EventMessage

use of com.vmware.flowgate.common.model.redis.message.EventMessage in project flowgate by vmware.

the class RedisMessageReceiver method receiveMessage.

@Override
public void receiveMessage(String message) {
    try {
        EventMessage eventMessage = mapper.readValue(message, EventMessageImpl.class);
        asyncService.executeAsync(eventMessage);
    } catch (IOException e) {
        logger.info(String.format("Failed prase message %s", message));
    }
}
Also used : EventMessage(com.vmware.flowgate.common.model.redis.message.EventMessage) IOException(java.io.IOException)

Example 25 with EventMessage

use of com.vmware.flowgate.common.model.redis.message.EventMessage in project flowgate by vmware.

the class JobsController method startFullMappingAggregation.

@ResponseStatus(HttpStatus.CREATED)
@RequestMapping(value = "/mergeservermapping", method = RequestMethod.POST, consumes = MediaType.APPLICATION_JSON_VALUE)
public void startFullMappingAggregation() {
    try {
        EventMessage eventMessage = EventMessageUtil.createEventMessage(EventType.Aggregator, EventMessageUtil.FullMappingCommand, "");
        String message = EventMessageUtil.convertEventMessageAsString(eventMessage);
        publisher.publish(EventMessageUtil.AggregatorTopic, message);
    } catch (IOException e) {
        log.error("Failed to create event message", e);
        throw new WormholeRequestException("Failed to create event message");
    }
}
Also used : WormholeRequestException(com.vmware.flowgate.exception.WormholeRequestException) EventMessage(com.vmware.flowgate.common.model.redis.message.EventMessage) IOException(java.io.IOException) ResponseStatus(org.springframework.web.bind.annotation.ResponseStatus) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

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