Search in sources :

Example 6 with AdapterJobCommand

use of com.vmware.flowgate.common.model.AdapterJobCommand in project flowgate by vmware.

the class CustomerAdapterJobDispatcher method sendMessage.

private void sendMessage(long execount, FacilitySoftwareConfig integration, FacilityAdapter adapter) {
    String topic = adapter.getTopic();
    String queue = adapter.getQueueName();
    List<AdapterJobCommand> commands = adapter.getCommands();
    for (AdapterJobCommand command : commands) {
        int executeCycle = command.getTriggerCycle() / EVERY_CYCLE;
        if (execount % executeCycle == 0) {
            try {
                template.opsForList().leftPushAll(queue, EventMessageUtil.generateFacilityMessageListByType(null, command.getCommand(), new FacilitySoftwareConfig[] { integration }));
                EventMessage message = EventMessageUtil.createEventMessage(null, null, NODIFY_MESSAGE);
                publisher.publish(topic, EventMessageUtil.convertEventMessageAsString(message));
                logger.info("Send " + command.getCommand() + " of " + integration.getName() + " success");
            } catch (IOException e) {
                logger.error("Failed to send out message", e);
            }
        }
    }
}
Also used : AdapterJobCommand(com.vmware.flowgate.common.model.AdapterJobCommand) EventMessage(com.vmware.flowgate.common.model.redis.message.EventMessage) FacilitySoftwareConfig(com.vmware.flowgate.common.model.FacilitySoftwareConfig) IOException(java.io.IOException)

Example 7 with AdapterJobCommand

use of com.vmware.flowgate.common.model.AdapterJobCommand in project flowgate by vmware.

the class MessageProcessingTest method testExecuteCustomerSendMessageJob1.

@Test
public void testExecuteCustomerSendMessageJob1() throws JobExecutionException {
    ListOperations<String, String> listOp = Mockito.mock(ListOperations.class);
    ValueOperations<String, String> valueOp = Mockito.mock(ValueOperations.class);
    when(template.opsForList()).thenReturn(listOp);
    when(listOp.leftPushAll(anyString(), anyString())).thenReturn(1L);
    when(template.hasKey(anyString())).thenReturn(false);
    when(template.opsForValue()).thenReturn(valueOp);
    when(valueOp.get(anyString())).thenReturn("19");
    FacilitySoftwareConfig fac1 = createFacilitySoftware();
    String unique_value1 = UUID.randomUUID().toString();
    fac1.setSubCategory("OtherDCIM_" + unique_value1);
    when(restClient.getFacilitySoftwareInternalByType(FacilitySoftwareConfig.SoftwareType.OtherDCIM)).thenReturn(getFacilitySoftwareByType(fac1));
    FacilitySoftwareConfig fac2 = createFacilitySoftware();
    fac2.setType(FacilitySoftwareConfig.SoftwareType.OtherCMDB);
    String unique_value2 = UUID.randomUUID().toString();
    fac2.setSubCategory("OtherCMDB_" + unique_value2);
    when(restClient.getFacilitySoftwareInternalByType(FacilitySoftwareConfig.SoftwareType.OtherCMDB)).thenReturn(getFacilitySoftwareByType(fac2));
    FacilityAdapter adapter = new FacilityAdapter();
    adapter.setSubCategory("OtherDCIM_" + unique_value1);
    AdapterJobCommand command1 = new AdapterJobCommand();
    command1.setCommand("syncmetadata");
    command1.setTriggerCycle(20);
    List<AdapterJobCommand> commands = new ArrayList<AdapterJobCommand>();
    commands.add(command1);
    adapter.setCommands(commands);
    adapter.setTopic(unique_value1);
    adapter.setQueueName(unique_value1 + ":joblist");
    FacilityAdapter adapter2 = new FacilityAdapter();
    adapter2.setSubCategory("OtherCMDB_" + unique_value2);
    AdapterJobCommand command2 = new AdapterJobCommand();
    command2.setCommand("syncmetadata");
    command2.setTriggerCycle(20);
    List<AdapterJobCommand> commands2 = new ArrayList<AdapterJobCommand>();
    commands2.add(command2);
    adapter2.setCommands(commands2);
    adapter2.setTopic(unique_value2);
    adapter2.setQueueName(unique_value2 + ":joblist");
    FacilityAdapter[] adapters = new FacilityAdapter[2];
    adapters[0] = adapter;
    adapters[1] = adapter2;
    when(restClient.getAllCustomerFacilityAdapters()).thenReturn(new ResponseEntity<FacilityAdapter[]>(adapters, HttpStatus.OK));
    customerAdapter.execute(null);
}
Also used : AdapterJobCommand(com.vmware.flowgate.common.model.AdapterJobCommand) ArrayList(java.util.ArrayList) FacilitySoftwareConfig(com.vmware.flowgate.common.model.FacilitySoftwareConfig) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) FacilityAdapter(com.vmware.flowgate.common.model.FacilityAdapter) SpringBootTest(org.springframework.boot.test.context.SpringBootTest) Test(org.junit.Test)

Example 8 with AdapterJobCommand

use of com.vmware.flowgate.common.model.AdapterJobCommand in project flowgate by vmware.

the class FacilityAdapterControllerTest method createAdapter.

FacilityAdapter createAdapter() {
    FacilityAdapter adapter = new FacilityAdapter();
    adapter.setId(UUID.randomUUID().toString());
    adapter.setDisplayName("defaultAdapter");
    adapter.setType(SoftwareType.OtherCMDB);
    adapter.setDescription("Default adapter for test");
    List<AdapterJobCommand> commands = new ArrayList<AdapterJobCommand>();
    AdapterJobCommand command = new AdapterJobCommand();
    command.setCommand("syncmetadata");
    command.setTriggerCycle(1440);
    command.setDescription("sync metadata job");
    commands.add(command);
    AdapterJobCommand metricsCommand = new AdapterJobCommand();
    metricsCommand.setCommand("syncmetricsdata");
    metricsCommand.setTriggerCycle(5);
    metricsCommand.setDescription("sync metrics data job");
    commands.add(metricsCommand);
    adapter.setCommands(commands);
    return adapter;
}
Also used : AdapterJobCommand(com.vmware.flowgate.common.model.AdapterJobCommand) ArrayList(java.util.ArrayList) FacilityAdapter(com.vmware.flowgate.common.model.FacilityAdapter)

Aggregations

AdapterJobCommand (com.vmware.flowgate.common.model.AdapterJobCommand)8 FacilityAdapter (com.vmware.flowgate.common.model.FacilityAdapter)7 FacilitySoftwareConfig (com.vmware.flowgate.common.model.FacilitySoftwareConfig)5 ArrayList (java.util.ArrayList)5 Test (org.junit.Test)4 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)4 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)4 WormholeRequestException (com.vmware.flowgate.exception.WormholeRequestException)2 EventMessage (com.vmware.flowgate.common.model.redis.message.EventMessage)1 AssetController (com.vmware.flowgate.controller.AssetController)1 IOException (java.io.IOException)1 HttpHeaders (org.springframework.http.HttpHeaders)1 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)1