use of com.vmware.flowgate.common.model.FacilityAdapter in project flowgate by vmware.
the class FacilityAdapterService method create.
public HttpHeaders create(FacilityAdapter adapter) {
String displayName = adapter.getDisplayName();
if (displayName == null || predefineName.contains(displayName)) {
throw WormholeRequestException.InvalidFiled("DisplayName", displayName);
}
FacilityAdapter oldAdapter = facilityAdapterRepo.findByDisplayName(displayName);
if (oldAdapter != null) {
throw new WormholeRequestException("Adapter with dispalyName : " + displayName + " is existed");
}
List<AdapterJobCommand> commands = adapter.getCommands();
if (commands == null || commands.isEmpty()) {
throw new WormholeRequestException("The Commands field is required.");
}
HttpHeaders httpHeaders = new HttpHeaders();
BaseDocumentUtil.generateID(adapter);
String unique_value = adapter.getType().name() + JOIN_FLAG + UUID.randomUUID().toString().replaceAll("-", "");
adapter.setTopic(unique_value);
adapter.setSubCategory(unique_value);
adapter.setQueueName(adapter.getSubCategory() + QUEUE_NAME_SUFFIX);
String randomKey = UUID.randomUUID().toString().replaceAll("-", "");
String serviceKey = DigestUtils.sha256Hex(randomKey);
adapter.setServiceKey(serviceKey);
facilityAdapterRepo.save(adapter);
cacheServiceKey(serviceKey);
httpHeaders.setLocation(linkTo(AssetController.class).slash(adapter.getId()).toUri());
return httpHeaders;
}
use of com.vmware.flowgate.common.model.FacilityAdapter in project flowgate by vmware.
the class FacilityAdapterController method updateAdapterType.
@RequestMapping(method = RequestMethod.PUT, consumes = MediaType.APPLICATION_JSON_VALUE)
public void updateAdapterType(@RequestBody FacilityAdapter adapter) {
FacilityAdapter equalNameAdapter = facilityAdapterRepo.findByDisplayName(adapter.getDisplayName());
if (equalNameAdapter != null && !equalNameAdapter.getId().equals(adapter.getId())) {
throw new WormholeRequestException("Adapter with dispalyName : " + adapter.getDisplayName() + " is existed");
}
List<AdapterJobCommand> commands = adapter.getCommands();
if (commands == null || commands.isEmpty()) {
throw new WormholeRequestException("The Commands field is required.");
}
FacilityAdapter oldAdapterType = facilityAdapterService.findById(adapter.getId());
oldAdapterType.setDescription(adapter.getDescription());
oldAdapterType.setDisplayName(adapter.getDisplayName());
oldAdapterType.setCommands(commands);
facilityAdapterRepo.save(adapter);
}
use of com.vmware.flowgate.common.model.FacilityAdapter in project flowgate by vmware.
the class MessageProcessingTest method testExecuteCustomerSendMessageJob2.
@Test
public void testExecuteCustomerSendMessageJob2() throws JobExecutionException {
FacilitySoftwareConfig fac1 = createFacilitySoftware();
String unique_value1 = UUID.randomUUID().toString();
fac1.setSubCategory("OtherDCIM_" + unique_value1);
when(restClient.getFacilitySoftwareInternalByType(FacilitySoftwareConfig.SoftwareType.OtherDCIM)).thenReturn(getFacilitySoftwareByType(fac1));
when(restClient.getFacilitySoftwareInternalByType(FacilitySoftwareConfig.SoftwareType.OtherCMDB)).thenReturn(new ResponseEntity<FacilitySoftwareConfig[]>(new FacilitySoftwareConfig[0], HttpStatus.OK));
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[] adapters = new FacilityAdapter[1];
adapters[0] = adapter;
when(restClient.getAllCustomerFacilityAdapters()).thenReturn(new ResponseEntity<FacilityAdapter[]>(new FacilityAdapter[0], HttpStatus.OK));
customerAdapter.execute(null);
}
use of com.vmware.flowgate.common.model.FacilityAdapter in project flowgate by vmware.
the class MessageProcessingTest method testExecuteCustomerSendMessageJob3.
@Test
public void testExecuteCustomerSendMessageJob3() 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(true);
when(template.opsForValue()).thenReturn(valueOp);
when(valueOp.increment(anyString())).thenReturn(4l);
FacilitySoftwareConfig fac1 = createFacilitySoftware();
String unique_value1 = UUID.randomUUID().toString();
fac1.setSubCategory("OtherDCIM_" + unique_value1);
when(restClient.getFacilitySoftwareInternalByType(FacilitySoftwareConfig.SoftwareType.OtherDCIM)).thenReturn(new ResponseEntity<FacilitySoftwareConfig[]>(new FacilitySoftwareConfig[0], HttpStatus.OK));
when(restClient.getFacilitySoftwareInternalByType(FacilitySoftwareConfig.SoftwareType.OtherCMDB)).thenReturn(new ResponseEntity<FacilitySoftwareConfig[]>(new FacilitySoftwareConfig[0], HttpStatus.OK));
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[] adapters = new FacilityAdapter[1];
adapters[0] = adapter;
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 MessageProcessingTest method testExecuteCustomerSendMessageJob.
@Test
public void testExecuteCustomerSendMessageJob() 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(true);
when(template.opsForValue()).thenReturn(valueOp);
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);
}
Aggregations