use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.netconf.callhome.server.rev201015.netconf.callhome.server.allowed.devices.Device in project openflowplugin by opendaylight.
the class StatisticsGatheringUtils method markDeviceStateSnapshotEnd.
/**
* Writes snapshot gathering end timestamp + outcome.
*
* @param deviceInfo device info
* @param txFacade tx manager
* @param succeeded outcome of currently finished gathering
*/
static void markDeviceStateSnapshotEnd(final DeviceInfo deviceInfo, final TxFacade txFacade, final boolean succeeded) {
final InstanceIdentifier<SnapshotGatheringStatusEnd> statusEndPath = deviceInfo.getNodeInstanceIdentifier().augmentation(FlowCapableStatisticsGatheringStatus.class).child(SnapshotGatheringStatusEnd.class);
final SimpleDateFormat simpleDateFormat = new SimpleDateFormat(DATE_AND_TIME_FORMAT);
final SnapshotGatheringStatusEnd gatheringStatus = new SnapshotGatheringStatusEndBuilder().setEnd(new DateAndTime(simpleDateFormat.format(new Date()))).setSucceeded(succeeded).build();
try {
txFacade.writeToTransaction(LogicalDatastoreType.OPERATIONAL, statusEndPath, gatheringStatus);
} catch (TransactionChainClosedException e) {
LOG.warn("Can't write to transaction, transaction chain probably closed.");
LOG.trace("Write to transaction exception: ", e);
}
txFacade.submitTransaction();
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.netconf.callhome.server.rev201015.netconf.callhome.server.allowed.devices.Device in project openflowplugin by opendaylight.
the class RoleService method submitRoleChange.
public ListenableFuture<RpcResult<SetRoleOutput>> submitRoleChange(final OfpRole ofpRole, final Uint8 version, final Uint64 generationId) {
LOG.info("submitRoleChange called for device:{}, role:{}", getDeviceInfo().getNodeId(), ofpRole);
final RoleRequestInputBuilder roleRequestInputBuilder = new RoleRequestInputBuilder();
roleRequestInputBuilder.setRole(toOFJavaRole(ofpRole));
roleRequestInputBuilder.setVersion(version);
roleRequestInputBuilder.setGenerationId(generationId);
final ListenableFuture<RpcResult<RoleRequestOutput>> roleListenableFuture = handleServiceCall(roleRequestInputBuilder);
final SettableFuture<RpcResult<SetRoleOutput>> finalFuture = SettableFuture.create();
Futures.addCallback(roleListenableFuture, new FutureCallback<RpcResult<RoleRequestOutput>>() {
@Override
public void onSuccess(final RpcResult<RoleRequestOutput> roleRequestOutputRpcResult) {
LOG.info("submitRoleChange onSuccess for device:{}, role:{}", getDeviceInfo().getNodeId(), ofpRole);
final RoleRequestOutput roleRequestOutput = roleRequestOutputRpcResult.getResult();
final Collection<RpcError> rpcErrors = roleRequestOutputRpcResult.getErrors();
if (roleRequestOutput != null) {
final SetRoleOutputBuilder setRoleOutputBuilder = new SetRoleOutputBuilder();
setRoleOutputBuilder.setTransactionId(new TransactionId(Uint64.valueOf(roleRequestOutput.getXid())));
finalFuture.set(RpcResultBuilder.<SetRoleOutput>success().withResult(setRoleOutputBuilder.build()).build());
} else if (rpcErrors != null) {
LOG.trace("roleRequestOutput is null , rpcErrors={}", rpcErrors);
for (RpcError rpcError : rpcErrors) {
LOG.warn("RpcError on submitRoleChange for {}: {}", deviceContext.getPrimaryConnectionContext().getNodeId(), rpcError.toString());
}
finalFuture.set(RpcResultBuilder.<SetRoleOutput>failed().withRpcErrors(rpcErrors).build());
}
}
@Override
public void onFailure(final Throwable throwable) {
LOG.error("submitRoleChange onFailure for device:{}, role:{}", getDeviceInfo().getNodeId(), ofpRole, throwable);
finalFuture.setException(throwable);
}
}, MoreExecutors.directExecutor());
return finalFuture;
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.netconf.callhome.server.rev201015.netconf.callhome.server.allowed.devices.Device in project openflowplugin by opendaylight.
the class RoleService method getGenerationIdFromDevice.
public ListenableFuture<Uint64> getGenerationIdFromDevice(final Uint8 version) {
LOG.info("getGenerationIdFromDevice called for device: {}", getDeviceInfo().getNodeId().getValue());
// send a dummy no-change role request to get the generation-id of the switch
final RoleRequestInputBuilder roleRequestInputBuilder = new RoleRequestInputBuilder();
roleRequestInputBuilder.setRole(toOFJavaRole(OfpRole.NOCHANGE));
roleRequestInputBuilder.setVersion(version);
roleRequestInputBuilder.setGenerationId(Uint64.ZERO);
final SettableFuture<Uint64> finalFuture = SettableFuture.create();
final ListenableFuture<RpcResult<RoleRequestOutput>> genIdListenableFuture = handleServiceCall(roleRequestInputBuilder);
Futures.addCallback(genIdListenableFuture, new FutureCallback<RpcResult<RoleRequestOutput>>() {
@Override
public void onSuccess(final RpcResult<RoleRequestOutput> roleRequestOutputRpcResult) {
if (roleRequestOutputRpcResult.isSuccessful()) {
final RoleRequestOutput roleRequestOutput = roleRequestOutputRpcResult.getResult();
if (roleRequestOutput != null) {
LOG.debug("roleRequestOutput.getGenerationId()={}", roleRequestOutput.getGenerationId());
finalFuture.set(roleRequestOutput.getGenerationId());
} else {
LOG.info("roleRequestOutput is null in getGenerationIdFromDevice");
finalFuture.setException(new RoleChangeException("Exception in getting generationId for device:" + getDeviceInfo().getNodeId().getValue()));
}
} else {
LOG.error("getGenerationIdFromDevice RPC error {}", roleRequestOutputRpcResult.getErrors().iterator().next().getInfo());
finalFuture.setException(new RoleChangeException(ErrorUtil.errorsToString(roleRequestOutputRpcResult.getErrors())));
}
}
@Override
public void onFailure(final Throwable throwable) {
LOG.info("onFailure - getGenerationIdFromDevice RPC error", throwable);
finalFuture.setException(new ExecutionException(throwable));
}
}, MoreExecutors.directExecutor());
return finalFuture;
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.netconf.callhome.server.rev201015.netconf.callhome.server.allowed.devices.Device in project openflowplugin by opendaylight.
the class AbstractRequestCallback method onFailure.
@Override
public final void onFailure(final Throwable throwable) {
final RpcResultBuilder<T> builder;
if (null != eventIdentifier) {
EventsTimeCounter.markEnd(eventIdentifier);
}
if (throwable instanceof DeviceRequestFailedException) {
final Error err = ((DeviceRequestFailedException) throwable).getError();
final String errorString = String.format("Device reported error type %s code %s", err.getTypeString(), err.getCodeString());
builder = RpcResultBuilder.<T>failed().withError(RpcError.ErrorType.APPLICATION, errorString, throwable);
spyMessage(StatisticsGroup.TO_SWITCH_SUBMIT_FAILURE);
} else {
if (throwable != null) {
builder = RpcResultBuilder.<T>failed().withError(RpcError.ErrorType.APPLICATION, throwable.getMessage(), throwable);
} else {
Throwable deviceReadFailedThrowable = new Throwable("Failed to read from device.");
builder = RpcResultBuilder.<T>failed().withError(RpcError.ErrorType.APPLICATION, deviceReadFailedThrowable.getMessage(), deviceReadFailedThrowable);
}
spyMessage(StatisticsGroup.TO_SWITCH_SUBMIT_ERROR);
}
context.setResult(builder.build());
RequestContextUtil.closeRequestContext(context);
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.netconf.callhome.server.rev201015.netconf.callhome.server.allowed.devices.Device in project openflowplugin by opendaylight.
the class ConnectionManagerImplTest method testOnSwitchConnected1.
/**
* Test method for
* {@link org.opendaylight.openflowplugin.impl.connection.ConnectionManagerImpl#onSwitchConnected(
* org.opendaylight.openflowjava.protocol.api.connection.ConnectionAdapter)}.
* invoking onConnectionReady first, scenario:
* <ol>
* <li>send hello to device (rpc with void output)</li>
* <li>receive hello from device (notification)</li>
* <li>send getFeature to device (rpc with getFeatureOutput)</li>
* <li>wait for rpc to finish with getFeatureOutput</li>
* </ol>
*
* @throws InterruptedException - interrupted exception
*/
@Test
public void testOnSwitchConnected1() throws Exception {
connectionManagerImpl.onSwitchConnected(connection);
Mockito.verify(connection).setConnectionReadyListener(connectionReadyListenerAC.capture());
Mockito.verify(connection).setMessageListener(ofpListenerAC.capture());
// prepare void reply (hello rpc output)
final SettableFuture<RpcResult<HelloOutput>> voidResponseFx = SettableFuture.create();
Mockito.when(connection.hello(any(HelloInput.class))).thenReturn(voidResponseFx);
// prepare getFeature reply (getFeture rpc output)
final SettableFuture<RpcResult<GetFeaturesOutput>> featureResponseFx = SettableFuture.create();
Mockito.when(connection.getFeatures(any(GetFeaturesInput.class))).thenReturn(featureResponseFx);
// fire handshake
connectionReadyListenerAC.getValue().onConnectionReady();
// deliver hello send output (void)
Thread.sleep(100L);
final RpcResult<HelloOutput> helloResponse = RpcResultBuilder.success((HelloOutput) null).build();
voidResponseFx.set(helloResponse);
// set dpn last connected time to be before dpn hold time seconds from now
connectionManagerImpl.getDeviceConnectionStatusProvider().addDeviceLastConnectionTime(BigInteger.TEN, LocalDateTime.now().minusSeconds(DEVICE_CONNECTION_HOLD_TIME_IN_SECONDS.toJava()));
// send hello reply
final HelloMessage hello = new HelloMessageBuilder().setVersion(EncodeConstants.OF_VERSION_1_3).setXid(Uint32.ONE).build();
ofpListenerAC.getValue().onHelloMessage(hello);
// deliver getFeature output
Thread.sleep(100L);
final GetFeaturesOutput getFeatureOutput = new GetFeaturesOutputBuilder().setDatapathId(Uint64.TEN).setVersion(EncodeConstants.OF_VERSION_1_3).setXid(Uint32.TWO).setTables(Uint8.valueOf(15)).build();
final RpcResult<GetFeaturesOutput> rpcFeaturesOutput = RpcResultBuilder.success(getFeatureOutput).build();
featureResponseFx.set(rpcFeaturesOutput);
Mockito.verify(deviceConnectedHandler, Mockito.timeout(500)).deviceConnected(any(ConnectionContext.class));
}
Aggregations