use of com.vmware.flowgate.common.model.FacilityAdapter in project flowgate by vmware.
the class CustomerAdapterJobDispatcher method initFacilityAdapterMap.
private Map<String, FacilityAdapter> initFacilityAdapterMap() {
Map<String, FacilityAdapter> facilityAdapterMap = new HashMap<String, FacilityAdapter>();
FacilityAdapter[] customerAdapters = restClient.getAllCustomerFacilityAdapters().getBody();
for (FacilityAdapter adapter : customerAdapters) {
facilityAdapterMap.put(adapter.getSubCategory(), adapter);
}
return facilityAdapterMap;
}
use of com.vmware.flowgate.common.model.FacilityAdapter in project flowgate by vmware.
the class CustomerAdapterJobDispatcher method execute.
@Override
public void execute(JobExecutionContext context) throws JobExecutionException {
restClient.setServiceKey(serviceKeyConfig.getServiceKey());
Map<String, FacilityAdapter> facilityAdapterMap = initFacilityAdapterMap();
if (facilityAdapterMap.isEmpty()) {
return;
}
List<FacilitySoftwareConfig> facilityIntegrations = getIntegrations();
if (facilityIntegrations.isEmpty()) {
return;
}
String execountString = template.opsForValue().get(EventMessageUtil.CUSTOMER_ADAPTER_EXECOUNT);
if (execountString == null || "".equals(execountString)) {
execountString = "0";
}
long execount = Long.valueOf(execountString);
execount++;
template.opsForValue().set(EventMessageUtil.CUSTOMER_ADAPTER_EXECOUNT, String.valueOf(execount));
for (FacilitySoftwareConfig integration : facilityIntegrations) {
String subcategory = integration.getSubCategory();
FacilityAdapter adapter = facilityAdapterMap.get(subcategory);
sendMessage(execount, integration, adapter);
}
logger.info("Send customer adapter job finished");
}
use of com.vmware.flowgate.common.model.FacilityAdapter 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.FacilityAdapter in project flowgate by vmware.
the class FacilityAdapterControllerTest method updateFacilityAdapterValidDisplayNameExample.
@Test
public void updateFacilityAdapterValidDisplayNameExample() throws JsonProcessingException, Exception {
FacilityAdapter adapter = createAdapter();
adapter.setDisplayName("displayNameForTestUpdate");
facilityAdapterRepo.save(adapter);
FacilityAdapter adapter1 = createAdapter();
adapter1.setDisplayName("displayNameForTestUpdate");
expectedEx.expect(WormholeRequestException.class);
expectedEx.expectMessage("Adapter with dispalyName : displayNameForTestUpdate is existed");
MvcResult result = this.mockMvc.perform(put("/v1/facilityadapter").contentType(MediaType.APPLICATION_JSON).content(objectMapper.writeValueAsString(adapter1))).andExpect(status().is4xxClientError()).andReturn();
facilityAdapterRepo.deleteById(adapter.getId());
if (result.getResolvedException() != null) {
throw result.getResolvedException();
} else {
TestCase.fail();
}
}
use of com.vmware.flowgate.common.model.FacilityAdapter in project flowgate by vmware.
the class FacilityAdapterControllerTest method findFacilityAdapterByIdExample.
@Test
public void findFacilityAdapterByIdExample() throws JsonProcessingException, Exception {
FacilityAdapter adapter = createAdapter();
adapter.setDisplayName("displayNameForTestfindById");
facilityAdapterRepo.save(adapter);
this.mockMvc.perform(get("/v1/facilityadapter/{Id}", adapter.getId())).andExpect(status().isOk()).andExpect(jsonPath("$..displayName").value("displayNameForTestfindById")).andDo(document("facilityadapter-findOneById-example", pathParameters(parameterWithName("Id").description("The id of FacilityAdapter, generated by flowgate.")))).andReturn();
facilityAdapterRepo.deleteById(adapter.getId());
}
Aggregations