Search in sources :

Example 31 with SwitchInfoData

use of org.openkilda.messaging.info.event.SwitchInfoData in project open-kilda by telstra.

the class AbstractSerializerTest method eventSwitchInfoTest.

@Test
public void eventSwitchInfoTest() throws IOException, ClassNotFoundException {
    SwitchInfoData data = new SwitchInfoData(SWITCH_ID, SWITCH_EVENT, "127.0.0.1", "localhost", "sw", "controller");
    System.out.println(data);
    InfoMessage info = new InfoMessage(data, System.currentTimeMillis(), CORRELATION_ID, DESTINATION);
    serialize(info);
    Message message = (Message) deserialize();
    assertTrue(message instanceof InfoMessage);
    InfoMessage resultInfo = (InfoMessage) message;
    assertTrue(resultInfo.getData() instanceof SwitchInfoData);
    SwitchInfoData resultData = (SwitchInfoData) resultInfo.getData();
    System.out.println(resultData);
    assertEquals(data, resultData);
    assertEquals(data.hashCode(), resultData.hashCode());
}
Also used : InfoMessage(org.openkilda.messaging.info.InfoMessage) Message(org.openkilda.messaging.Message) CommandMessage(org.openkilda.messaging.command.CommandMessage) ErrorMessage(org.openkilda.messaging.error.ErrorMessage) InfoMessage(org.openkilda.messaging.info.InfoMessage) SwitchInfoData(org.openkilda.messaging.info.event.SwitchInfoData) Test(org.junit.Test)

Example 32 with SwitchInfoData

use of org.openkilda.messaging.info.event.SwitchInfoData in project open-kilda by telstra.

the class NetworkCache method getSwitch.

/**
 * Gets {@link SwitchInfoData} instance.
 *
 * @param switchId {@link SwitchInfoData} instance id
 * @return {@link SwitchInfoData} instance with specified {@link SwitchInfoData} instance id
 * @throws CacheException if {@link SwitchInfoData} instance with specified id does not exist
 */
public SwitchInfoData getSwitch(String switchId) throws CacheException {
    logger.debug("Get {} switch", switchId);
    SwitchInfoData node = switchPool.get(switchId);
    if (node == null) {
        throw new CacheException(ErrorType.NOT_FOUND, "Can not get switch", String.format("Switch %s not found", switchId));
    }
    return node;
}
Also used : CacheException(org.openkilda.messaging.error.CacheException) SwitchInfoData(org.openkilda.messaging.info.event.SwitchInfoData)

Example 33 with SwitchInfoData

use of org.openkilda.messaging.info.event.SwitchInfoData in project open-kilda by telstra.

the class NetworkCache method createSwitch.

/**
 * Creates {@link SwitchInfoData} instance.
 *
 * @param newSwitch {@link SwitchInfoData} instance
 * @return created {@link SwitchInfoData} instance
 * @throws CacheException if {@link SwitchInfoData} instance with specified id already exists
 */
public SwitchInfoData createSwitch(SwitchInfoData newSwitch) throws CacheException {
    String switchId = newSwitch.getSwitchId();
    logger.debug("Create {} switch with {} parameters", switchId, newSwitch);
    SwitchInfoData oldSwitch = switchPool.get(switchId);
    if (oldSwitch != null) {
        throw new CacheException(ErrorType.ALREADY_EXISTS, "Can not create switch", String.format("Switch %s already exists", switchId));
    }
    newSwitch.setCreatedInCacheNow();
    network.addNode(newSwitch);
    switchPool.put(switchId, newSwitch);
    return newSwitch;
}
Also used : CacheException(org.openkilda.messaging.error.CacheException) SwitchInfoData(org.openkilda.messaging.info.event.SwitchInfoData)

Example 34 with SwitchInfoData

use of org.openkilda.messaging.info.event.SwitchInfoData in project open-kilda by telstra.

the class NetworkCache method getIslsByDestination.

/**
 * Gets all {@link IslInfoData} instances which end node is specified {@link SwitchInfoData} instance.
 *
 * @param switchId {@link SwitchInfoData} instance id
 * @return {@link Set} of {@link IslInfoData} instances
 * @throws CacheException if {@link SwitchInfoData} instance with specified id does not exists
 */
public Set<IslInfoData> getIslsByDestination(String switchId) {
    logger.debug("Get all isls by destination switch {}", switchId);
    SwitchInfoData endNode = getSwitch(switchId);
    return network.inEdges(endNode);
}
Also used : SwitchInfoData(org.openkilda.messaging.info.event.SwitchInfoData)

Example 35 with SwitchInfoData

use of org.openkilda.messaging.info.event.SwitchInfoData in project open-kilda by telstra.

the class NetworkCache method deleteSwitch.

/**
 * Deletes {@link SwitchInfoData} instance.
 *
 * @param switchId {@link SwitchInfoData} instance id
 * @return removed {@link SwitchInfoData} instance
 * @throws CacheException if {@link SwitchInfoData} instance with specified id does not exist
 */
public SwitchInfoData deleteSwitch(String switchId) throws CacheException {
    logger.debug("Delete {} switch", switchId);
    SwitchInfoData node = switchPool.remove(switchId);
    if (node == null) {
        throw new CacheException(ErrorType.NOT_FOUND, "Can not delete switch", String.format("Switch %s not found", switchId));
    }
    network.removeNode(node);
    return node;
}
Also used : CacheException(org.openkilda.messaging.error.CacheException) SwitchInfoData(org.openkilda.messaging.info.event.SwitchInfoData)

Aggregations

SwitchInfoData (org.openkilda.messaging.info.event.SwitchInfoData)38 Test (org.junit.Test)11 InfoMessage (org.openkilda.messaging.info.InfoMessage)9 IslInfoData (org.openkilda.messaging.info.event.IslInfoData)9 CacheException (org.openkilda.messaging.error.CacheException)8 CommandMessage (org.openkilda.messaging.command.CommandMessage)7 PathNode (org.openkilda.messaging.info.event.PathNode)6 PortInfoData (org.openkilda.messaging.info.event.PortInfoData)5 Transactional (org.springframework.transaction.annotation.Transactional)5 IOException (java.io.IOException)4 List (java.util.List)4 Collectors (java.util.stream.Collectors)4 InfoData (org.openkilda.messaging.info.InfoData)4 NetworkInfoData (org.openkilda.messaging.info.discovery.NetworkInfoData)4 AbstractStormTest (org.openkilda.wfm.AbstractStormTest)4 Then (cucumber.api.java.en.Then)3 When (cucumber.api.java.en.When)3 Comparator (java.util.Comparator)3 Switch (org.openkilda.topology.domain.Switch)3 PendingException (cucumber.api.PendingException)2