use of org.opendaylight.yang.gen.v1.urn.opendaylight.genius.alivenessmonitor.rev160411.MonitorProfileCreateInput in project genius by opendaylight.
the class AlivenessMonitorTest method testMonitorProfileCreate.
@Test
public void testMonitorProfileCreate() throws InterruptedException, ExecutionException {
MonitorProfileCreateInput input = new MonitorProfileCreateInputBuilder().setProfile(new ProfileBuilder().setFailureThreshold(10L).setMonitorInterval(10000L).setMonitorWindow(10L).setProtocolType(EtherTypes.Arp).build()).build();
doReturn(Futures.immediateCheckedFuture(Optional.absent())).when(readWriteTx).read(eq(LogicalDatastoreType.OPERATIONAL), argThat(isType(MonitorProfile.class)));
doReturn(Futures.immediateCheckedFuture(null)).when(readWriteTx).submit();
RpcResult<MonitorProfileCreateOutput> output = alivenessMonitor.monitorProfileCreate(input).get();
assertTrue("Monitor Profile Create result", output.isSuccessful());
assertNotNull("Monitor Profile Output", output.getResult().getProfileId());
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.genius.alivenessmonitor.rev160411.MonitorProfileCreateInput in project genius by opendaylight.
the class AlivenessMonitorTest method createProfile.
@SuppressWarnings("unchecked")
private long createProfile() throws InterruptedException, ExecutionException {
MonitorProfileCreateInput input = new MonitorProfileCreateInputBuilder().setProfile(new ProfileBuilder().setFailureThreshold(10L).setMonitorInterval(10000L).setMonitorWindow(10L).setProtocolType(EtherTypes.Arp).build()).build();
doReturn(Futures.immediateCheckedFuture(Optional.absent())).when(readWriteTx).read(eq(LogicalDatastoreType.OPERATIONAL), any(InstanceIdentifier.class));
doReturn(Futures.immediateCheckedFuture(null)).when(readWriteTx).submit();
RpcResult<MonitorProfileCreateOutput> output = alivenessMonitor.monitorProfileCreate(input).get();
return output.getResult().getProfileId();
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.genius.alivenessmonitor.rev160411.MonitorProfileCreateInput in project genius by opendaylight.
the class AlivenessMonitorTest method testMonitorProfileCreateAlreadyExist.
@Test
public void testMonitorProfileCreateAlreadyExist() throws InterruptedException, ExecutionException {
MonitorProfileCreateInput input = new MonitorProfileCreateInputBuilder().setProfile(new ProfileBuilder().setFailureThreshold(10L).setMonitorInterval(10000L).setMonitorWindow(10L).setProtocolType(EtherTypes.Arp).build()).build();
@SuppressWarnings("unchecked") Optional<MonitorProfile> optionalProfile = mock(Optional.class);
CheckedFuture<Optional<MonitorProfile>, ReadFailedException> proFuture = Futures.immediateCheckedFuture(optionalProfile);
doReturn(true).when(optionalProfile).isPresent();
doReturn(proFuture).when(readWriteTx).read(eq(LogicalDatastoreType.OPERATIONAL), argThat(isType(MonitorProfile.class)));
RpcResult<MonitorProfileCreateOutput> output = alivenessMonitor.monitorProfileCreate(input).get();
assertTrue("Monitor Profile Create result", output.isSuccessful());
assertThat(output.getErrors(), CoreMatchers.hasItem(hasErrorType(ErrorType.PROTOCOL)));
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.genius.alivenessmonitor.rev160411.MonitorProfileCreateInput in project netvirt by opendaylight.
the class AlivenessMonitorUtils method createMonitorProfile.
// TODO Clean up the exception handling
@SuppressWarnings("checkstyle:IllegalCatch")
public static Optional<Long> createMonitorProfile(AlivenessMonitorService alivenessMonitor, MonitorProfileCreateInput monitorProfileCreateInput) {
try {
Future<RpcResult<MonitorProfileCreateOutput>> result = alivenessMonitor.monitorProfileCreate(monitorProfileCreateInput);
RpcResult<MonitorProfileCreateOutput> rpcResult = result.get();
if (rpcResult.isSuccessful()) {
return Optional.of(rpcResult.getResult().getProfileId());
} else {
LOG.warn("RPC Call to Get Profile Id Id returned with Errors {}.. Trying to fetch existing profile ID", rpcResult.getErrors());
try {
Profile createProfile = monitorProfileCreateInput.getProfile();
Future<RpcResult<MonitorProfileGetOutput>> existingProfile = alivenessMonitor.monitorProfileGet(buildMonitorGetProfile(createProfile.getMonitorInterval(), createProfile.getMonitorWindow(), createProfile.getFailureThreshold(), createProfile.getProtocolType()));
RpcResult<MonitorProfileGetOutput> rpcGetResult = existingProfile.get();
if (rpcGetResult.isSuccessful()) {
return Optional.of(rpcGetResult.getResult().getProfileId());
} else {
LOG.warn("RPC Call to Get Existing Profile Id returned with Errors {}", rpcGetResult.getErrors());
}
} catch (Exception e) {
LOG.warn("Exception when getting existing profile", e);
}
}
} catch (InterruptedException | ExecutionException e) {
LOG.warn("Exception when allocating profile Id", e);
}
return Optional.absent();
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.genius.alivenessmonitor.rev160411.MonitorProfileCreateInput in project genius by opendaylight.
the class AlivenessMonitor method monitorProfileCreate.
@Override
public Future<RpcResult<MonitorProfileCreateOutput>> monitorProfileCreate(final MonitorProfileCreateInput input) {
LOG.debug("Monitor Profile Create operation - {}", input.getProfile());
final SettableFuture<RpcResult<MonitorProfileCreateOutput>> returnFuture = SettableFuture.create();
Profile profile = input.getProfile();
final Long failureThreshold = profile.getFailureThreshold();
final Long monitorInterval = profile.getMonitorInterval();
final Long monitorWindow = profile.getMonitorWindow();
final EtherTypes ethType = profile.getProtocolType();
String idKey = getUniqueProfileKey(failureThreshold, monitorInterval, monitorWindow, ethType);
final Long profileId = (long) getUniqueId(idKey);
final ReadWriteTransaction tx = dataBroker.newReadWriteTransaction();
ListenableFuture<Optional<MonitorProfile>> readFuture = tx.read(LogicalDatastoreType.OPERATIONAL, getMonitorProfileId(profileId));
ListenableFuture<RpcResult<MonitorProfileCreateOutput>> resultFuture = Futures.transformAsync(readFuture, optProfile -> {
if (optProfile.isPresent()) {
tx.cancel();
MonitorProfileCreateOutput output = new MonitorProfileCreateOutputBuilder().setProfileId(profileId).build();
String msg = String.format("Monitor profile %s already present for the given input", input);
LOG.warn(msg);
returnFuture.set(RpcResultBuilder.success(output).withWarning(ErrorType.PROTOCOL, "profile-exists", msg).build());
} else {
final MonitorProfile monitorProfile = new MonitorProfileBuilder().setId(profileId).setFailureThreshold(failureThreshold).setMonitorInterval(monitorInterval).setMonitorWindow(monitorWindow).setProtocolType(ethType).build();
tx.put(LogicalDatastoreType.OPERATIONAL, getMonitorProfileId(profileId), monitorProfile, CREATE_MISSING_PARENT);
Futures.addCallback(tx.submit(), new FutureCallback<Void>() {
@Override
public void onFailure(Throwable error) {
String msg = String.format("Error when storing monitorprofile %s in datastore", monitorProfile);
LOG.error("Error when storing monitorprofile {} in datastore", monitorProfile, error);
returnFuture.set(RpcResultBuilder.<MonitorProfileCreateOutput>failed().withError(ErrorType.APPLICATION, msg, error).build());
}
@Override
public void onSuccess(Void noarg) {
MonitorProfileCreateOutput output = new MonitorProfileCreateOutputBuilder().setProfileId(profileId).build();
returnFuture.set(RpcResultBuilder.success(output).build());
}
}, callbackExecutorService);
}
return returnFuture;
}, callbackExecutorService);
Futures.addCallback(resultFuture, new FutureCallback<RpcResult<MonitorProfileCreateOutput>>() {
@Override
public void onFailure(Throwable error) {
// This would happen when any error happens during reading for
// monitoring profile
String msg = String.format("Error in creating monitorprofile - %s", input);
returnFuture.set(RpcResultBuilder.<MonitorProfileCreateOutput>failed().withError(ErrorType.APPLICATION, msg, error).build());
LOG.error("Error in creating monitorprofile - {} ", input, error);
}
@Override
public void onSuccess(RpcResult<MonitorProfileCreateOutput> result) {
LOG.debug("Successfully created monitor Profile {} ", input);
}
}, callbackExecutorService);
return returnFuture;
}
Aggregations