Search in sources :

Example 1 with MonitorProfileCreateOutput

use of org.opendaylight.yang.gen.v1.urn.opendaylight.genius.alivenessmonitor.rev160411.MonitorProfileCreateOutput 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());
}
Also used : MonitorProfileCreateOutput(org.opendaylight.yang.gen.v1.urn.opendaylight.genius.alivenessmonitor.rev160411.MonitorProfileCreateOutput) MonitorProfileCreateInput(org.opendaylight.yang.gen.v1.urn.opendaylight.genius.alivenessmonitor.rev160411.MonitorProfileCreateInput) MonitorProfileCreateInputBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.genius.alivenessmonitor.rev160411.MonitorProfileCreateInputBuilder) ProfileBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.genius.alivenessmonitor.rev160411.monitor.profile.create.input.ProfileBuilder) MonitorProfileBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.genius.alivenessmonitor.rev160411.monitor.profiles.MonitorProfileBuilder) Test(org.junit.Test)

Example 2 with MonitorProfileCreateOutput

use of org.opendaylight.yang.gen.v1.urn.opendaylight.genius.alivenessmonitor.rev160411.MonitorProfileCreateOutput 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();
}
Also used : MonitorProfileCreateOutput(org.opendaylight.yang.gen.v1.urn.opendaylight.genius.alivenessmonitor.rev160411.MonitorProfileCreateOutput) MonitorProfileCreateInput(org.opendaylight.yang.gen.v1.urn.opendaylight.genius.alivenessmonitor.rev160411.MonitorProfileCreateInput) MonitorProfileCreateInputBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.genius.alivenessmonitor.rev160411.MonitorProfileCreateInputBuilder) InstanceIdentifier(org.opendaylight.yangtools.yang.binding.InstanceIdentifier) ProfileBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.genius.alivenessmonitor.rev160411.monitor.profile.create.input.ProfileBuilder) MonitorProfileBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.genius.alivenessmonitor.rev160411.monitor.profiles.MonitorProfileBuilder)

Example 3 with MonitorProfileCreateOutput

use of org.opendaylight.yang.gen.v1.urn.opendaylight.genius.alivenessmonitor.rev160411.MonitorProfileCreateOutput 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)));
}
Also used : MonitorProfileCreateOutput(org.opendaylight.yang.gen.v1.urn.opendaylight.genius.alivenessmonitor.rev160411.MonitorProfileCreateOutput) ReadFailedException(org.opendaylight.controller.md.sal.common.api.data.ReadFailedException) Optional(com.google.common.base.Optional) MonitorProfileCreateInput(org.opendaylight.yang.gen.v1.urn.opendaylight.genius.alivenessmonitor.rev160411.MonitorProfileCreateInput) MonitorProfileCreateInputBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.genius.alivenessmonitor.rev160411.MonitorProfileCreateInputBuilder) MonitorProfile(org.opendaylight.yang.gen.v1.urn.opendaylight.genius.alivenessmonitor.rev160411.monitor.profiles.MonitorProfile) ProfileBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.genius.alivenessmonitor.rev160411.monitor.profile.create.input.ProfileBuilder) MonitorProfileBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.genius.alivenessmonitor.rev160411.monitor.profiles.MonitorProfileBuilder) Test(org.junit.Test)

Example 4 with MonitorProfileCreateOutput

use of org.opendaylight.yang.gen.v1.urn.opendaylight.genius.alivenessmonitor.rev160411.MonitorProfileCreateOutput 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();
}
Also used : MonitorProfileCreateOutput(org.opendaylight.yang.gen.v1.urn.opendaylight.genius.alivenessmonitor.rev160411.MonitorProfileCreateOutput) RpcResult(org.opendaylight.yangtools.yang.common.RpcResult) MonitorProfileGetOutput(org.opendaylight.yang.gen.v1.urn.opendaylight.genius.alivenessmonitor.rev160411.MonitorProfileGetOutput) ExecutionException(java.util.concurrent.ExecutionException) Profile(org.opendaylight.yang.gen.v1.urn.opendaylight.genius.alivenessmonitor.rev160411.monitor.profile.create.input.Profile) ExecutionException(java.util.concurrent.ExecutionException)

Example 5 with MonitorProfileCreateOutput

use of org.opendaylight.yang.gen.v1.urn.opendaylight.genius.alivenessmonitor.rev160411.MonitorProfileCreateOutput 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;
}
Also used : Optional(com.google.common.base.Optional) MonitorProfile(org.opendaylight.yang.gen.v1.urn.opendaylight.genius.alivenessmonitor.rev160411.monitor.profiles.MonitorProfile) RpcResult(org.opendaylight.yangtools.yang.common.RpcResult) MonitorProfileBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.genius.alivenessmonitor.rev160411.monitor.profiles.MonitorProfileBuilder) EtherTypes(org.opendaylight.yang.gen.v1.urn.opendaylight.genius.alivenessmonitor.rev160411.EtherTypes) Profile(org.opendaylight.yang.gen.v1.urn.opendaylight.genius.alivenessmonitor.rev160411.monitor.profile.create.input.Profile) MonitorProfile(org.opendaylight.yang.gen.v1.urn.opendaylight.genius.alivenessmonitor.rev160411.monitor.profiles.MonitorProfile) MonitorProfileCreateOutputBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.genius.alivenessmonitor.rev160411.MonitorProfileCreateOutputBuilder) MonitorProfileCreateOutput(org.opendaylight.yang.gen.v1.urn.opendaylight.genius.alivenessmonitor.rev160411.MonitorProfileCreateOutput) ReadWriteTransaction(org.opendaylight.controller.md.sal.binding.api.ReadWriteTransaction)

Aggregations

MonitorProfileCreateOutput (org.opendaylight.yang.gen.v1.urn.opendaylight.genius.alivenessmonitor.rev160411.MonitorProfileCreateOutput)6 MonitorProfileBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.genius.alivenessmonitor.rev160411.monitor.profiles.MonitorProfileBuilder)4 MonitorProfileCreateInput (org.opendaylight.yang.gen.v1.urn.opendaylight.genius.alivenessmonitor.rev160411.MonitorProfileCreateInput)3 MonitorProfileCreateInputBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.genius.alivenessmonitor.rev160411.MonitorProfileCreateInputBuilder)3 Profile (org.opendaylight.yang.gen.v1.urn.opendaylight.genius.alivenessmonitor.rev160411.monitor.profile.create.input.Profile)3 ProfileBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.genius.alivenessmonitor.rev160411.monitor.profile.create.input.ProfileBuilder)3 RpcResult (org.opendaylight.yangtools.yang.common.RpcResult)3 Optional (com.google.common.base.Optional)2 ExecutionException (java.util.concurrent.ExecutionException)2 Test (org.junit.Test)2 MonitorProfileGetOutput (org.opendaylight.yang.gen.v1.urn.opendaylight.genius.alivenessmonitor.rev160411.MonitorProfileGetOutput)2 MonitorProfile (org.opendaylight.yang.gen.v1.urn.opendaylight.genius.alivenessmonitor.rev160411.monitor.profiles.MonitorProfile)2 ReadWriteTransaction (org.opendaylight.controller.md.sal.binding.api.ReadWriteTransaction)1 ReadFailedException (org.opendaylight.controller.md.sal.common.api.data.ReadFailedException)1 EtherTypes (org.opendaylight.yang.gen.v1.urn.opendaylight.genius.alivenessmonitor.rev160411.EtherTypes)1 MonitorProfileCreateOutputBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.genius.alivenessmonitor.rev160411.MonitorProfileCreateOutputBuilder)1 InstanceIdentifier (org.opendaylight.yangtools.yang.binding.InstanceIdentifier)1