Search in sources :

Example 11 with FacilityAdapter

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;
}
Also used : HashMap(java.util.HashMap) FacilityAdapter(com.vmware.flowgate.common.model.FacilityAdapter)

Example 12 with FacilityAdapter

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");
}
Also used : FacilitySoftwareConfig(com.vmware.flowgate.common.model.FacilitySoftwareConfig) FacilityAdapter(com.vmware.flowgate.common.model.FacilityAdapter)

Example 13 with FacilityAdapter

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);
}
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 14 with FacilityAdapter

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();
    }
}
Also used : MvcResult(org.springframework.test.web.servlet.MvcResult) FacilityAdapter(com.vmware.flowgate.common.model.FacilityAdapter) SpringBootTest(org.springframework.boot.test.context.SpringBootTest) Test(org.junit.Test)

Example 15 with FacilityAdapter

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());
}
Also used : FacilityAdapter(com.vmware.flowgate.common.model.FacilityAdapter) SpringBootTest(org.springframework.boot.test.context.SpringBootTest) Test(org.junit.Test)

Aggregations

FacilityAdapter (com.vmware.flowgate.common.model.FacilityAdapter)23 Test (org.junit.Test)17 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)17 AdapterJobCommand (com.vmware.flowgate.common.model.AdapterJobCommand)7 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)7 MvcResult (org.springframework.test.web.servlet.MvcResult)7 FacilitySoftwareConfig (com.vmware.flowgate.common.model.FacilitySoftwareConfig)6 ArrayList (java.util.ArrayList)5 WormholeRequestException (com.vmware.flowgate.exception.WormholeRequestException)3 AssetController (com.vmware.flowgate.controller.AssetController)1 HashMap (java.util.HashMap)1 HttpHeaders (org.springframework.http.HttpHeaders)1 FieldDescriptor (org.springframework.restdocs.payload.FieldDescriptor)1 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)1