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);
}
}
}
}
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);
}
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;
}
Aggregations