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());
}
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;
}
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;
}
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);
}
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;
}
Aggregations