use of org.openkilda.model.SwitchInfo in project open-kilda by telstra.
the class SwitchIntegrationService method getSwitchesById.
/**
* Get the switch by id.
*
* @return the switch
*/
public SwitchInfo getSwitchesById(final String switchId) {
try {
HttpResponse response = restClientManager.invoke(applicationProperties.getNbBaseUrl() + IConstants.NorthBoundUrl.GET_SWITCH.replace("{switch_id}", switchId), HttpMethod.GET, "", "", applicationService.getAuthHeader());
if (RestClientManager.isValidResponse(response)) {
SwitchInfo switchInfo = restClientManager.getResponse(response, SwitchInfo.class);
if (switchInfo != null) {
switchInfo.setName(customSwitchName(getSwitchNames(), switchInfo.getSwitchId()));
switchInfo.setControllerSwitch(true);
return switchInfo;
}
}
} catch (InvalidResponseException e) {
LOGGER.error("Error occurred while getting switch by id:" + switchId, e);
throw new InvalidResponseException(e.getCode(), e.getResponse());
}
return null;
}
use of org.openkilda.model.SwitchInfo in project open-kilda by telstra.
the class SwitchService method saveOrUpdateSwitchName.
/**
* Save or update switch name.
*
* @param switchId the switch id
* @param switchName the switch name
* @return the SwitchInfo
*/
public SwitchInfo saveOrUpdateSwitchName(String switchId, String switchName) {
String storageType = applicationSettingService.getApplicationSetting(ApplicationSetting.SWITCH_NAME_STORAGE_TYPE);
if (storageType.equals(IConstants.StorageType.DATABASE_STORAGE.name())) {
SwitchNameEntity switchNameEntity = switchNameRepository.findBySwitchDpid(switchId);
if (switchNameEntity == null) {
switchNameEntity = new SwitchNameEntity();
}
switchNameEntity.setSwitchDpid(switchId);
switchNameEntity.setSwitchName(switchName);
switchNameEntity.setUpdatedDate(new Date());
switchNameRepository.save(switchNameEntity);
SwitchInfo switchInfo = new SwitchInfo();
switchInfo.setSwitchId(switchId);
switchInfo.setName(switchName);
return switchInfo;
} else {
throw new RequestValidationException("Storage-Type in Application Settings is not Database, " + "so switch name can not be updated");
}
}
use of org.openkilda.model.SwitchInfo in project open-kilda by telstra.
the class SwitchControllerTest method testGetSwitchById.
@Test
public void testGetSwitchById() throws Exception {
SwitchInfo switchInfo = new SwitchInfo();
when(serviceSwitch.getSwitch(TestSwitchMock.SWITCH_ID, TestFlowMock.CONTROLLER_FLAG)).thenReturn(switchInfo);
mockMvc.perform(get("/api/switch/{switchId}", TestSwitchMock.SWITCH_ID).contentType(MediaType.APPLICATION_JSON)).andExpect(status().isOk());
assertTrue(true);
}
use of org.openkilda.model.SwitchInfo in project open-kilda by telstra.
the class SwitchControllerTest method testSwitchMaintenance.
@Test
public void testSwitchMaintenance() throws Exception {
SwitchInfo switchInfo = new SwitchInfo();
switchInfo.setSwitchId(TestSwitchMock.SWITCH_ID);
switchInfo.setUnderMaintenance(TestSwitchMock.MAINTENANCE_STATUS);
switchInfo.setEvacuate(TestSwitchMock.EVACUATE_STATUS);
String inputJson = mapToJson(switchInfo);
mockMvc.perform(post("/api/switch/under-maintenance/{switchId}", TestSwitchMock.SWITCH_ID).content(inputJson).contentType(MediaType.APPLICATION_JSON)).andExpect(status().isOk());
}
use of org.openkilda.model.SwitchInfo in project open-kilda by telstra.
the class SwitchControllerTest method testDeleteSwitch.
@Test
public void testDeleteSwitch() {
SwitchInfo switcheInfo = new SwitchInfo();
try {
when(serviceSwitch.deleteSwitch(TestSwitchMock.SWITCH_ID, false)).thenReturn(switcheInfo);
mockMvc.perform(delete("/api/switch/{switchId}", TestSwitchMock.SWITCH_ID, true).contentType(MediaType.APPLICATION_JSON)).andExpect(status().isOk());
assertTrue(true);
} catch (Exception e) {
System.out.println("exception: " + e.getMessage());
assertTrue(false);
}
}
Aggregations