Search in sources :

Example 6 with SwitchInfo

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;
}
Also used : HttpResponse(org.apache.http.HttpResponse) SwitchInfo(org.openkilda.model.SwitchInfo) InvalidResponseException(org.openkilda.integration.exception.InvalidResponseException)

Example 7 with SwitchInfo

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");
    }
}
Also used : SwitchNameEntity(org.openkilda.dao.entity.SwitchNameEntity) SwitchInfo(org.openkilda.model.SwitchInfo) RequestValidationException(org.usermanagement.exception.RequestValidationException) Date(java.util.Date)

Example 8 with SwitchInfo

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);
}
Also used : SwitchInfo(org.openkilda.model.SwitchInfo) Test(org.junit.Test)

Example 9 with SwitchInfo

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());
}
Also used : SwitchInfo(org.openkilda.model.SwitchInfo) Test(org.junit.Test)

Example 10 with SwitchInfo

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);
    }
}
Also used : SwitchInfo(org.openkilda.model.SwitchInfo) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException) Test(org.junit.Test)

Aggregations

SwitchInfo (org.openkilda.model.SwitchInfo)10 Test (org.junit.Test)3 InvalidResponseException (org.openkilda.integration.exception.InvalidResponseException)3 InventorySwitch (org.openkilda.integration.source.store.dto.InventorySwitch)3 SwitchDiscrepancy (org.openkilda.model.SwitchDiscrepancy)3 SwitchStatus (org.openkilda.model.SwitchStatus)3 RequestValidationException (org.usermanagement.exception.RequestValidationException)3 AccessDeniedException (java.nio.file.AccessDeniedException)2 ArrayList (java.util.ArrayList)2 IntegrationException (org.openkilda.integration.exception.IntegrationException)2 StoreIntegrationException (org.openkilda.integration.exception.StoreIntegrationException)2 UserInfo (org.usermanagement.model.UserInfo)2 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)1 Date (java.util.Date)1 HttpResponse (org.apache.http.HttpResponse)1 SwitchNameEntity (org.openkilda.dao.entity.SwitchNameEntity)1