Example usage for com.google.common.util.concurrent AsyncFunction AsyncFunction

List of usage examples for com.google.common.util.concurrent AsyncFunction AsyncFunction

Introduction

In this page you can find the example usage for com.google.common.util.concurrent AsyncFunction AsyncFunction.

Prototype

AsyncFunction

Source Link

Usage

From source file:org.opendaylight.vpnservice.natservice.internal.ExternalRoutersListener.java

public void advToBgpAndInstallFibAndTsFlows(final BigInteger dpnId, final short tableId, final String vpnName,
        final long routerId, final String externalIp, VpnRpcService vpnService, final FibRpcService fibService,
        final IBgpManager bgpManager, final DataBroker dataBroker, final Logger log) {
    LOG.debug(/*w w w .j a v  a2s  . c  om*/
            "NAT Service : advToBgpAndInstallFibAndTsFlows() entry for DPN ID {}, tableId {}, vpnname {} and externalIp {}",
            dpnId, tableId, vpnName, externalIp);
    //Generate VPN label for the external IP
    GenerateVpnLabelInput labelInput = new GenerateVpnLabelInputBuilder().setVpnName(vpnName)
            .setIpPrefix(externalIp).build();
    Future<RpcResult<GenerateVpnLabelOutput>> labelFuture = vpnService.generateVpnLabel(labelInput);

    //On successful generation of the VPN label, advertise the route to the BGP and install the FIB routes.
    ListenableFuture<RpcResult<Void>> future = Futures.transform(
            JdkFutureAdapters.listenInPoolThread(labelFuture),
            new AsyncFunction<RpcResult<GenerateVpnLabelOutput>, RpcResult<Void>>() {

                @Override
                public ListenableFuture<RpcResult<Void>> apply(RpcResult<GenerateVpnLabelOutput> result)
                        throws Exception {
                    if (result.isSuccessful()) {
                        LOG.debug("NAT Service : inside apply with result success");
                        GenerateVpnLabelOutput output = result.getResult();
                        long label = output.getLabel();

                        //Inform BGP
                        String rd = NatUtil.getVpnRd(dataBroker, vpnName);
                        String nextHopIp = NatUtil.getEndpointIpAddressForDPN(dataBroker, dpnId);
                        NatUtil.addPrefixToBGP(bgpManager, rd, externalIp, nextHopIp, label, log);

                        //Get IPMaps from the DB for the router ID
                        List<IpMap> dbIpMaps = NaptManager.getIpMapList(dataBroker, routerId);
                        if (dbIpMaps != null) {
                            for (IpMap dbIpMap : dbIpMaps) {
                                String dbExternalIp = dbIpMap.getExternalIp();
                                //Select the IPMap, whose external IP is the IP for which FIB is installed
                                if (externalIp.equals(dbExternalIp)) {
                                    String dbInternalIp = dbIpMap.getInternalIp();
                                    IpMapKey dbIpMapKey = dbIpMap.getKey();
                                    LOG.debug("Setting label {} for internalIp {} and externalIp {}", label,
                                            dbInternalIp, externalIp);
                                    IpMap newIpm = new IpMapBuilder().setKey(dbIpMapKey)
                                            .setInternalIp(dbInternalIp).setExternalIp(dbExternalIp)
                                            .setLabel(label).build();
                                    MDSALUtil.syncWrite(dataBroker, LogicalDatastoreType.OPERATIONAL,
                                            naptManager.getIpMapIdentifier(routerId, dbInternalIp), newIpm);
                                    break;
                                }
                            }
                        } else {
                            LOG.error(
                                    "NAT Service : Failed to write label {} for externalIp {} for routerId {} in DS",
                                    label, externalIp, routerId);
                        }

                        //Install custom FIB routes
                        List<Instruction> customInstructions = new ArrayList<>();
                        customInstructions
                                .add(new InstructionInfo(InstructionType.goto_table, new long[] { tableId })
                                        .buildInstruction(0));
                        makeTunnelTableEntry(dpnId, label, customInstructions);
                        makeLFibTableEntry(dpnId, label, tableId);

                        CreateFibEntryInput input = new CreateFibEntryInputBuilder().setVpnName(vpnName)
                                .setSourceDpid(dpnId).setIpAddress(externalIp).setServiceId(label)
                                .setInstruction(customInstructions).build();
                        Future<RpcResult<Void>> future = fibService.createFibEntry(input);
                        return JdkFutureAdapters.listenInPoolThread(future);
                    } else {
                        LOG.error("NAT Service : inside apply with result failed");
                        String errMsg = String.format(
                                "Could not retrieve the label for prefix %s in VPN %s, %s", externalIp, vpnName,
                                result.getErrors());
                        return Futures.immediateFailedFuture(new RuntimeException(errMsg));
                    }
                }
            });

    Futures.addCallback(future, new FutureCallback<RpcResult<Void>>() {

        @Override
        public void onFailure(Throwable error) {
            log.error("NAT Service : Error in generate label or fib install process", error);
        }

        @Override
        public void onSuccess(RpcResult<Void> result) {
            if (result.isSuccessful()) {
                log.info("NAT Service : Successfully installed custom FIB routes for prefix {}", externalIp);
            } else {
                log.error(
                        "NAT Service : Error in rpc call to create custom Fib entries for prefix {} in DPN {}, {}",
                        externalIp, dpnId, result.getErrors());
            }
        }
    });
}

From source file:org.opendaylight.vpnservice.alivenessmonitor.internal.AlivenessMonitor.java

@Override
public Future<RpcResult<Void>> monitorProfileDelete(final MonitorProfileDeleteInput input) {
    LOG.debug("Monitor Profile delete for Id: {}", input.getProfileId());
    final SettableFuture<RpcResult<Void>> result = SettableFuture.create();
    final Long profileId = input.getProfileId();
    final ReadWriteTransaction tx = broker.newReadWriteTransaction();
    ListenableFuture<Optional<MonitorProfile>> readFuture = tx.read(LogicalDatastoreType.OPERATIONAL,
            getMonitorProfileId(profileId));
    ListenableFuture<RpcResult<Void>> writeFuture = Futures.transform(readFuture,
            new AsyncFunction<Optional<MonitorProfile>, RpcResult<Void>>() {

                @Override//from   ww  w  .j  ava  2  s  . c o  m
                public ListenableFuture<RpcResult<Void>> apply(final Optional<MonitorProfile> optProfile)
                        throws Exception {
                    if (optProfile.isPresent()) {
                        tx.delete(LogicalDatastoreType.OPERATIONAL, getMonitorProfileId(profileId));
                        Futures.addCallback(tx.submit(), new FutureCallback<Void>() {
                            @Override
                            public void onFailure(Throwable error) {
                                String msg = String.format(
                                        "Error when removing monitor profile %d from datastore", profileId);
                                LOG.error(msg, error);
                                result.set(RpcResultBuilder.<Void>failed()
                                        .withError(ErrorType.APPLICATION, msg, error).build());
                            }

                            @Override
                            public void onSuccess(Void noarg) {
                                MonitorProfile profile = optProfile.get();
                                String id = getUniqueProfileKey(profile.getFailureThreshold(),
                                        profile.getMonitorInterval(), profile.getMonitorWindow(),
                                        profile.getProtocolType());
                                releaseId(id);
                                result.set(RpcResultBuilder.<Void>success().build());
                            }
                        });
                    } else {
                        String msg = String.format("Monitor profile with Id: %d does not exist", profileId);
                        LOG.info(msg);
                        result.set(RpcResultBuilder.<Void>success()
                                .withWarning(ErrorType.PROTOCOL, "invalid-value", msg).build());
                    }
                    return result;
                }
            }, callbackExecutorService);

    Futures.addCallback(writeFuture, new FutureCallback<RpcResult<Void>>() {

        @Override
        public void onFailure(Throwable error) {
            String msg = String.format("Error when removing monitor profile %d from datastore", profileId);
            LOG.error(msg, error);
            result.set(RpcResultBuilder.<Void>failed().withError(ErrorType.APPLICATION, msg, error).build());
        }

        @Override
        public void onSuccess(RpcResult<Void> noarg) {
            LOG.debug("Successfully removed Monitor Profile {}", profileId);
        }
    }, callbackExecutorService);
    return result;
}

From source file:org.opendaylight.centinel.impl.CentinelImpl.java

/** 
 *    delete Alert Message Count Rule in configurational data store. 
 * // w ww. j  a va  2s  .c o m
 */

@Override
public Future<RpcResult<DeleteAlertMessageCountRuleOutput>> deleteAlertMessageCountRule(
        DeleteAlertMessageCountRuleInput input) {
    final ReadWriteTransaction tx = dataProvider.newReadWriteTransaction();
    final SettableFuture<RpcResult<DeleteAlertMessageCountRuleOutput>> futureResult = SettableFuture.create();
    LOG.info("DeleteAlertMessageCountRuleOutput: " + input);
    final DeleteAlertMessageCountRuleOutputBuilder deleteAlertMessageCountRuleOutputBuilder = new DeleteAlertMessageCountRuleOutputBuilder();
    deleteAlertMessageCountRuleOutputBuilder.setMessageCountOperator(input.getMessageCountOperator());
    deleteAlertMessageCountRuleOutputBuilder.setMessageCountCount(input.getMessageCountCount());
    deleteAlertMessageCountRuleOutputBuilder.setMessageCountGrace(input.getMessageCountGrace());
    deleteAlertMessageCountRuleOutputBuilder.setMessageCountBacklog(input.getMessageCountBacklog());
    deleteAlertMessageCountRuleOutputBuilder.setRuleID(input.getRuleID());
    deleteAlertMessageCountRuleOutputBuilder.setNodeType(input.getNodeType());
    deleteAlertMessageCountRuleOutputBuilder.setRuleTypeClassifier(input.getRuleTypeClassifier());
    deleteAlertMessageCountRuleOutputBuilder.setStreamID(input.getStreamID());
    deleteAlertMessageCountRuleOutputBuilder.setTimeStamp(input.getTimeStamp());
    deleteAlertMessageCountRuleOutputBuilder.setAlertTypeClassifier(input.getAlertTypeClassifier());

    ListenableFuture<Optional<AlertMessageCountRuleRecord>> readFutureOperational = tx
            .read(LogicalDatastoreType.OPERATIONAL, alertMessageCountRuleRecordId);

    ListenableFuture<Optional<AlertMessageCountRuleRecord>> readFutureConfigure = tx
            .read(LogicalDatastoreType.CONFIGURATION, alertMessageCountRuleRecordId);

    String configId = null;

    try {

        AlertMessageCountRuleRecord operationalRecord = readFutureOperational.get().get();
        List<StreamAlertMessageCountRuleList> streamAlertRuleList = new ArrayList<StreamAlertMessageCountRuleList>();

        if (!operationalRecord.getStreamAlertMessageCountRuleList().isEmpty()) {

            streamAlertRuleList = operationalRecord.getStreamAlertMessageCountRuleList();
            Iterator<StreamAlertMessageCountRuleList> itearator = streamAlertRuleList.iterator();

            StreamAlertMessageCountRuleList operationalObject = null;

            while (itearator.hasNext()) {

                operationalObject = itearator.next();
                if (operationalObject.getRuleID().equalsIgnoreCase(input.getRuleID())
                        && operationalObject.getStreamID().equalsIgnoreCase(input.getStreamID())) {

                    configId = operationalObject.getConfigID();

                }
            }

        }

    } catch (InterruptedException | ExecutionException e) {

        futureResult.set(RpcResultBuilder.<DeleteAlertMessageCountRuleOutput>failed()
                .withRpcErrors(((TransactionCommitFailedException) e).getErrorList()).build());
        return futureResult;

    }
    final String configID = configId;
    final ListenableFuture<Void> commitFuture = Futures.transform(readFutureConfigure,
            new AsyncFunction<Optional<AlertMessageCountRuleRecord>, Void>() {

                @Override
                public ListenableFuture<Void> apply(
                        final Optional<AlertMessageCountRuleRecord> alertMessageCountRuleRecord)
                        throws Exception {

                    List<StreamAlertMessageCountRuleList> streamAlertRuleList = new ArrayList<StreamAlertMessageCountRuleList>();

                    if (alertMessageCountRuleRecord.isPresent()) {

                        streamAlertRuleList = alertMessageCountRuleRecord.get()
                                .getStreamAlertMessageCountRuleList();
                        StreamAlertMessageCountRuleList configObject = null;
                        Iterator<StreamAlertMessageCountRuleList> iterator = streamAlertRuleList.iterator();

                        while (iterator.hasNext()) {

                            configObject = iterator.next();

                            if (configObject.getConfigID().equalsIgnoreCase(configID)) {

                                tx.delete(LogicalDatastoreType.CONFIGURATION, alertMessageCountRuleRecordId
                                        .child(StreamAlertMessageCountRuleList.class, configObject.getKey()));

                            }
                        }

                    }

                    return tx.submit();
                }

            });
    Futures.addCallback(commitFuture, new FutureCallback<Void>() {
        @Override
        public void onSuccess(final Void result) {

            futureResult.set(RpcResultBuilder.<DeleteAlertMessageCountRuleOutput>success(
                    deleteAlertMessageCountRuleOutputBuilder.build()).build());
        }

        @Override
        public void onFailure(final Throwable ex) {

            LOG.debug("Failed to commit Rule", ex);

            futureResult.set(RpcResultBuilder.<DeleteAlertMessageCountRuleOutput>failed()
                    .withRpcErrors(((TransactionCommitFailedException) ex).getErrorList()).build());

        }
    });

    return futureResult;
}

From source file:org.opendaylight.centinel.impl.CentinelAlertConditionImpl.java

@Override
public Future<RpcResult<UpdateAlertFieldValueRuleOutput>> updateAlertFieldValueRule(
        final UpdateAlertFieldValueRuleInput input) {
    final ReadWriteTransaction tx = dataProvider.newReadWriteTransaction();
    final SettableFuture<RpcResult<UpdateAlertFieldValueRuleOutput>> futureResult = SettableFuture.create();
    boolean idMatches = false;
    if (input.getStreamID() == null || input.getStreamID().isEmpty() || input.getStreamID().trim().isEmpty()
            || input.getRuleID() == null || input.getRuleID().isEmpty() || input.getRuleID().trim().isEmpty()) {
        LOG.debug("Invalid Parameters for UpdateAlertFieldValueRule");
        return Futures.immediateFailedCheckedFuture(
                new TransactionCommitFailedException("inalid-input", RpcResultBuilder.newError(
                        ErrorType.APPLICATION, "invalid-input", "StreamId and RuleId are mandatory fields")));
    }//from w  ww . j  ava2  s.  c  o m
    final UpdateAlertFieldValueRuleOutputBuilder updateAlertFieldValueRuleOutputBuilder = new UpdateAlertFieldValueRuleOutputBuilder();
    updateAlertFieldValueRuleOutputBuilder.setFieldValueBacklog(input.getFieldValueBacklog());
    updateAlertFieldValueRuleOutputBuilder.setFieldValueField(input.getFieldValueField());
    updateAlertFieldValueRuleOutputBuilder.setFieldValueGrace(input.getFieldValueGrace());
    updateAlertFieldValueRuleOutputBuilder.setFieldValueThreshhold(input.getFieldValueThreshhold());
    updateAlertFieldValueRuleOutputBuilder.setFieldValueThreshholdType(input.getFieldValueThreshholdType());
    updateAlertFieldValueRuleOutputBuilder.setFieldValueThreshholdType(input.getFieldValueThreshholdType());
    updateAlertFieldValueRuleOutputBuilder.setRuleID(input.getRuleID());
    updateAlertFieldValueRuleOutputBuilder.setNodeType(input.getNodeType());
    updateAlertFieldValueRuleOutputBuilder.setRuleTypeClassifier(input.getRuleTypeClassifier());
    updateAlertFieldValueRuleOutputBuilder.setStreamID(input.getStreamID());
    updateAlertFieldValueRuleOutputBuilder.setTimeStamp(input.getTimeStamp());
    updateAlertFieldValueRuleOutputBuilder.setAlertTypeClassifier(input.getAlertTypeClassifier());
    updateAlertFieldValueRuleOutputBuilder.setAlertName(input.getAlertName());

    ListenableFuture<Optional<AlertFieldValueRuleRecord>> readFutureOperational = tx
            .read(LogicalDatastoreType.OPERATIONAL, alertFieldValueRuleRecordId);

    ListenableFuture<Optional<AlertFieldValueRuleRecord>> readFutureConfigure = tx
            .read(LogicalDatastoreType.CONFIGURATION, alertFieldValueRuleRecordId);

    String configId = null;

    try {
        Optional<AlertFieldValueRuleRecord> record = readFutureOperational.get();
        if (record.isPresent()) {
            AlertFieldValueRuleRecord operationalRecord = readFutureOperational.get().get();
            List<StreamAlertFieldValueRuleList> streamAlertRuleList = new ArrayList<StreamAlertFieldValueRuleList>();

            if (!operationalRecord.getStreamAlertFieldValueRuleList().isEmpty()) {
                streamAlertRuleList = operationalRecord.getStreamAlertFieldValueRuleList();
                Iterator<StreamAlertFieldValueRuleList> itearator = streamAlertRuleList.iterator();
                StreamAlertFieldValueRuleList operationalObject = null;

                while (itearator.hasNext()) {
                    operationalObject = itearator.next();
                    if (operationalObject.getRuleID().equalsIgnoreCase(input.getRuleID())
                            && operationalObject.getStreamID().equalsIgnoreCase(input.getStreamID())) {
                        configId = operationalObject.getConfigID();
                        idMatches = true;

                    }
                }
                if (!idMatches) {
                    return Futures.immediateFailedCheckedFuture(new TransactionCommitFailedException(
                            "invalid-input", RpcResultBuilder.newError(ErrorType.APPLICATION, "invalid-input",
                                    "Invalid Stream/Rule id or The stream/rule is not present in operational data store")));

                }

            }

        } else {
            return Futures.immediateFailedCheckedFuture(new TransactionCommitFailedException("invalid-input",
                    RpcResultBuilder.newError(ErrorType.APPLICATION, "invalid-input",
                            "Record is not present in operational data store")));
        }
    } catch (InterruptedException | ExecutionException e) {
        futureResult.set(RpcResultBuilder.<UpdateAlertFieldValueRuleOutput>failed()
                .withRpcErrors(((TransactionCommitFailedException) e).getErrorList()).build());
        return futureResult;

    }
    final String configID = configId;
    final ListenableFuture<Void> commitFuture = Futures.transform(readFutureConfigure,
            new AsyncFunction<Optional<AlertFieldValueRuleRecord>, Void>() {

                @Override
                public ListenableFuture<Void> apply(
                        final Optional<AlertFieldValueRuleRecord> alertFieldValueRuleRecord) throws Exception {

                    List<StreamAlertFieldValueRuleList> streamAlertRuleList = new ArrayList<StreamAlertFieldValueRuleList>();
                    List<StreamAlertFieldValueRuleList> updatedStreamAlertRuleList = new ArrayList<StreamAlertFieldValueRuleList>();
                    if (alertFieldValueRuleRecord.isPresent()) {
                        streamAlertRuleList = alertFieldValueRuleRecord.get()
                                .getStreamAlertFieldValueRuleList();
                        StreamAlertFieldValueRuleList configObject = null;
                        Iterator<StreamAlertFieldValueRuleList> iterator = streamAlertRuleList.iterator();
                        while (iterator.hasNext()) {
                            configObject = iterator.next();

                            if (configObject.getConfigID().equalsIgnoreCase(configID)) {
                                updatedStreamAlertRuleList
                                        .add(buildUpdateAlertFieldValueRuleRecord(input, configObject));

                                tx.merge(LogicalDatastoreType.CONFIGURATION, alertFieldValueRuleRecordId,
                                        new AlertFieldValueRuleRecordBuilder()
                                                .setStreamAlertFieldValueRuleList(updatedStreamAlertRuleList)
                                                .build());

                            }
                        }

                    }

                    return tx.submit();
                }

            });
    Futures.addCallback(commitFuture, new FutureCallback<Void>() {

        @Override
        public void onSuccess(final Void result) {

            futureResult.set(RpcResultBuilder
                    .<UpdateAlertFieldValueRuleOutput>success(updateAlertFieldValueRuleOutputBuilder.build())
                    .build());
        }

        @Override
        public void onFailure(final Throwable ex) {

            LOG.info("Failed to commit Rule", ex);

            futureResult.set(RpcResultBuilder.<UpdateAlertFieldValueRuleOutput>failed()
                    .withRpcErrors(((TransactionCommitFailedException) ex).getErrorList()).build());

        }
    });

    return futureResult;
}

From source file:org.opendaylight.vpnservice.alivenessmonitor.internal.AlivenessMonitor.java

private void removeMonitorIdFromInterfaceAssociation(final Long monitorId, final String interfaceName) {
    LOG.debug("Remove monitorId {} from Interface association {}", monitorId, interfaceName);
    final ReadWriteTransaction tx = broker.newReadWriteTransaction();
    ListenableFuture<Optional<InterfaceMonitorEntry>> readFuture = tx.read(LogicalDatastoreType.OPERATIONAL,
            getInterfaceMonitorMapId(interfaceName));
    ListenableFuture<Void> updateFuture = Futures.transform(readFuture,
            new AsyncFunction<Optional<InterfaceMonitorEntry>, Void>() {

                @Override/*from  ww  w  .java 2 s .c o m*/
                public ListenableFuture<Void> apply(Optional<InterfaceMonitorEntry> optEntry) throws Exception {
                    if (optEntry.isPresent()) {
                        InterfaceMonitorEntry entry = optEntry.get();
                        List<Long> monitorIds = entry.getMonitorIds();
                        monitorIds.remove(monitorId);
                        InterfaceMonitorEntry newEntry = new InterfaceMonitorEntryBuilder(entry)
                                .setKey(new InterfaceMonitorEntryKey(interfaceName)).setMonitorIds(monitorIds)
                                .build();
                        tx.put(LogicalDatastoreType.OPERATIONAL, getInterfaceMonitorMapId(interfaceName),
                                newEntry, CREATE_MISSING_PARENT);
                        return tx.submit();
                    } else {
                        LOG.warn("No Interface map entry found {} to remove monitorId {}", interfaceName,
                                monitorId);
                        tx.cancel();
                        return Futures.immediateFuture(null);
                    }
                }
            });

    Futures.addCallback(updateFuture, new FutureCallbackImpl(
            String.format("Dis-association of monitorId %d with Interface %s", monitorId, interfaceName)));
}

From source file:org.opendaylight.centinel.impl.CentinelImpl.java

/** 
 *    delete alert field Content rule in configurational data store. 
 * //www  . j  av  a  2  s .c om
 */

@Override
public Future<RpcResult<DeleteAlertFieldContentRuleOutput>> deleteAlertFieldContentRule(
        DeleteAlertFieldContentRuleInput input) {
    final ReadWriteTransaction tx = dataProvider.newReadWriteTransaction();
    final SettableFuture<RpcResult<DeleteAlertFieldContentRuleOutput>> futureResult = SettableFuture.create();
    LOG.info("DeleteAlertFieldContentRuleOutput: " + input);
    final DeleteAlertFieldContentRuleOutputBuilder deleteAlertFieldContentRuleOutputBuilder = new DeleteAlertFieldContentRuleOutputBuilder();
    deleteAlertFieldContentRuleOutputBuilder.setFieldContentBacklog(input.getFieldContentBacklog());
    deleteAlertFieldContentRuleOutputBuilder
            .setFieldContentCompareToValue(input.getFieldContentCompareToValue());
    deleteAlertFieldContentRuleOutputBuilder.setFieldContentField(input.getFieldContentField());
    deleteAlertFieldContentRuleOutputBuilder.setFieldContentGrace(input.getFieldContentGrace());
    deleteAlertFieldContentRuleOutputBuilder.setRuleID(input.getRuleID());
    deleteAlertFieldContentRuleOutputBuilder.setNodeType(input.getNodeType());
    deleteAlertFieldContentRuleOutputBuilder.setRuleTypeClassifier(input.getRuleTypeClassifier());
    deleteAlertFieldContentRuleOutputBuilder.setStreamID(input.getStreamID());
    deleteAlertFieldContentRuleOutputBuilder.setTimeStamp(input.getTimeStamp());
    deleteAlertFieldContentRuleOutputBuilder.setAlertTypeClassifier(input.getAlertTypeClassifier());

    ListenableFuture<Optional<AlertFieldContentRuleRecord>> readFutureOperational = tx
            .read(LogicalDatastoreType.OPERATIONAL, alertFeildContentRuleRecordId);

    ListenableFuture<Optional<AlertFieldContentRuleRecord>> readFutureConfigure = tx
            .read(LogicalDatastoreType.CONFIGURATION, alertFeildContentRuleRecordId);

    String configId = null;

    try {

        AlertFieldContentRuleRecord operationalRecord = readFutureOperational.get().get();
        List<StreamAlertFieldContentRuleList> streamAlertRuleList = new ArrayList<StreamAlertFieldContentRuleList>();

        if (!operationalRecord.getStreamAlertFieldContentRuleList().isEmpty()) {

            streamAlertRuleList = operationalRecord.getStreamAlertFieldContentRuleList();
            Iterator<StreamAlertFieldContentRuleList> itearator = streamAlertRuleList.iterator();

            StreamAlertFieldContentRuleList operationalObject = null;

            while (itearator.hasNext()) {

                operationalObject = itearator.next();
                if (operationalObject.getRuleID().equalsIgnoreCase(input.getRuleID())
                        && operationalObject.getStreamID().equalsIgnoreCase(input.getStreamID())) {

                    configId = operationalObject.getConfigID();

                }
            }

        }

    } catch (InterruptedException | ExecutionException e) {

        futureResult.set(RpcResultBuilder.<DeleteAlertFieldContentRuleOutput>failed()
                .withRpcErrors(((TransactionCommitFailedException) e).getErrorList()).build());
        return futureResult;

    }
    final String configID = configId;
    final ListenableFuture<Void> commitFuture = Futures.transform(readFutureConfigure,
            new AsyncFunction<Optional<AlertFieldContentRuleRecord>, Void>() {

                @Override
                public ListenableFuture<Void> apply(
                        final Optional<AlertFieldContentRuleRecord> alertFieldContentRuleRecord)
                        throws Exception {

                    List<StreamAlertFieldContentRuleList> streamAlertRuleList = new ArrayList<StreamAlertFieldContentRuleList>();

                    if (alertFieldContentRuleRecord.isPresent()) {

                        streamAlertRuleList = alertFieldContentRuleRecord.get()
                                .getStreamAlertFieldContentRuleList();
                        StreamAlertFieldContentRuleList configObject = null;
                        Iterator<StreamAlertFieldContentRuleList> iterator = streamAlertRuleList.iterator();

                        while (iterator.hasNext()) {

                            configObject = iterator.next();

                            if (configObject.getConfigID().equalsIgnoreCase(configID)) {

                                tx.delete(LogicalDatastoreType.CONFIGURATION, alertFeildContentRuleRecordId
                                        .child(StreamAlertFieldContentRuleList.class, configObject.getKey()));

                            }
                        }

                    }

                    return tx.submit();
                }

            });
    Futures.addCallback(commitFuture, new FutureCallback<Void>() {
        @Override
        public void onSuccess(final Void result) {

            futureResult.set(RpcResultBuilder.<DeleteAlertFieldContentRuleOutput>success(
                    deleteAlertFieldContentRuleOutputBuilder.build()).build());
        }

        @Override
        public void onFailure(final Throwable ex) {

            LOG.debug("Failed to commit Rule", ex);

            futureResult.set(RpcResultBuilder.<DeleteAlertFieldContentRuleOutput>failed()
                    .withRpcErrors(((TransactionCommitFailedException) ex).getErrorList()).build());

        }
    });

    return futureResult;
}

From source file:org.opendaylight.vpnservice.alivenessmonitor.internal.AlivenessMonitor.java

private void updateMonitorStatusTo(final Long monitorId, final MonitorStatus newStatus,
        final Predicate<MonitorStatus> isValidStatus) {
    final String monitorKey = monitorIdKeyCache.getUnchecked(monitorId);
    if (monitorKey == null) {
        LOG.warn("No monitor Key associated with id {} to change the monitor status to {}", monitorId,
                newStatus);// w w  w.  jav  a2 s . c o m
        return;
    }
    final ReadWriteTransaction tx = broker.newReadWriteTransaction();

    ListenableFuture<Optional<MonitoringState>> readResult = tx.read(LogicalDatastoreType.OPERATIONAL,
            getMonitorStateId(monitorKey));

    ListenableFuture<Void> writeResult = Futures.transform(readResult,
            new AsyncFunction<Optional<MonitoringState>, Void>() {
                @Override
                public ListenableFuture<Void> apply(Optional<MonitoringState> optState) throws Exception {
                    if (optState.isPresent()) {
                        MonitoringState state = optState.get();
                        if (isValidStatus.apply(state.getStatus())) {
                            MonitoringState updatedState = new MonitoringStateBuilder()
                                    .setMonitorKey(monitorKey).setStatus(newStatus).build();
                            tx.merge(LogicalDatastoreType.OPERATIONAL, getMonitorStateId(monitorKey),
                                    updatedState);
                        } else {
                            LOG.warn("Invalid Monitoring status {}, cannot be updated to {} for monitorId {}",
                                    state.getStatus(), newStatus, monitorId);
                        }
                    } else {
                        LOG.warn(
                                "No associated monitoring state data available to update the status to {} for {}",
                                newStatus, monitorId);
                    }
                    return tx.submit();
                }
            });

    Futures.addCallback(writeResult, new FutureCallbackImpl(
            String.format("Monitor status update for %d to %s", monitorId, newStatus.toString())));
}

From source file:org.opendaylight.centinel.impl.CentinelAlertConditionImpl.java

@Override
public Future<RpcResult<DeleteAlertMessageCountRuleOutput>> deleteAlertMessageCountRule(
        DeleteAlertMessageCountRuleInput input) {
    final ReadWriteTransaction tx = dataProvider.newReadWriteTransaction();
    final SettableFuture<RpcResult<DeleteAlertMessageCountRuleOutput>> futureResult = SettableFuture.create();
    boolean idMatches = false;
    if (input.getStreamID() == null || input.getStreamID().isEmpty() || input.getStreamID().trim().isEmpty()
            || input.getRuleID() == null || input.getRuleID().isEmpty() || input.getRuleID().trim().isEmpty()) {
        LOG.debug("Invalid Parameters for DeleteAlertMessageCountRule");
        return Futures.immediateFailedCheckedFuture(
                new TransactionCommitFailedException("inalid-input", RpcResultBuilder.newError(
                        ErrorType.APPLICATION, "invalid-input", "StreamId and RuleId are mandatory fields")));
    }/*w w w.  j  a  v  a  2s. c o m*/
    final DeleteAlertMessageCountRuleOutputBuilder deleteAlertMessageCountRuleOutputBuilder = new DeleteAlertMessageCountRuleOutputBuilder();
    deleteAlertMessageCountRuleOutputBuilder.setMessageCountOperator(input.getMessageCountOperator());
    deleteAlertMessageCountRuleOutputBuilder.setMessageCountCount(input.getMessageCountCount());
    deleteAlertMessageCountRuleOutputBuilder.setMessageCountGrace(input.getMessageCountGrace());
    deleteAlertMessageCountRuleOutputBuilder.setMessageCountBacklog(input.getMessageCountBacklog());
    deleteAlertMessageCountRuleOutputBuilder.setRuleID(input.getRuleID());
    deleteAlertMessageCountRuleOutputBuilder.setNodeType(input.getNodeType());
    deleteAlertMessageCountRuleOutputBuilder.setRuleTypeClassifier(input.getRuleTypeClassifier());
    deleteAlertMessageCountRuleOutputBuilder.setStreamID(input.getStreamID());
    deleteAlertMessageCountRuleOutputBuilder.setTimeStamp(input.getTimeStamp());
    deleteAlertMessageCountRuleOutputBuilder.setAlertTypeClassifier(input.getAlertTypeClassifier());
    deleteAlertMessageCountRuleOutputBuilder.setAlertName(input.getAlertName());
    deleteAlertMessageCountRuleOutputBuilder.setConfigID(input.getConfigID());

    ListenableFuture<Optional<AlertMessageCountRuleRecord>> readFutureOperational = tx
            .read(LogicalDatastoreType.OPERATIONAL, alertMessageCountRuleRecordId);

    ListenableFuture<Optional<AlertMessageCountRuleRecord>> readFutureConfigure = tx
            .read(LogicalDatastoreType.CONFIGURATION, alertMessageCountRuleRecordId);

    String configId = null;

    try {

        Optional<AlertMessageCountRuleRecord> record = readFutureOperational.get();
        if (record.isPresent()) {
            AlertMessageCountRuleRecord operationalRecord = readFutureOperational.get().get();

            List<StreamAlertMessageCountRuleList> streamAlertRuleList = new ArrayList<StreamAlertMessageCountRuleList>();

            if (!operationalRecord.getStreamAlertMessageCountRuleList().isEmpty()) {

                streamAlertRuleList = operationalRecord.getStreamAlertMessageCountRuleList();
                Iterator<StreamAlertMessageCountRuleList> itearator = streamAlertRuleList.iterator();

                StreamAlertMessageCountRuleList operationalObject = null;

                while (itearator.hasNext()) {

                    operationalObject = itearator.next();
                    if (operationalObject.getRuleID().equalsIgnoreCase(input.getRuleID())
                            && operationalObject.getStreamID().equalsIgnoreCase(input.getStreamID())) {

                        configId = operationalObject.getConfigID();
                        idMatches = true;

                    }
                }
                if (!idMatches) {
                    return Futures.immediateFailedCheckedFuture(new TransactionCommitFailedException(
                            "invalid-input", RpcResultBuilder.newError(ErrorType.APPLICATION, "invalid-input",
                                    "Invalid Stream/Rule id or The stream/rule is not present in operational data store")));

                }

            }

        } else {
            return Futures.immediateFailedCheckedFuture(new TransactionCommitFailedException("invalid-input",
                    RpcResultBuilder.newError(ErrorType.APPLICATION, "invalid-input",
                            "Record is not present in operational data store")));
        }
    } catch (InterruptedException | ExecutionException e) {

        futureResult.set(RpcResultBuilder.<DeleteAlertMessageCountRuleOutput>failed()
                .withRpcErrors(((TransactionCommitFailedException) e).getErrorList()).build());
        return futureResult;

    }
    final String configID = configId;
    final ListenableFuture<Void> commitFuture = Futures.transform(readFutureConfigure,
            new AsyncFunction<Optional<AlertMessageCountRuleRecord>, Void>() {

                @Override
                public ListenableFuture<Void> apply(
                        final Optional<AlertMessageCountRuleRecord> alertMessageCountRuleRecord)
                        throws Exception {

                    List<StreamAlertMessageCountRuleList> streamAlertRuleList = new ArrayList<StreamAlertMessageCountRuleList>();

                    if (alertMessageCountRuleRecord.isPresent()) {

                        streamAlertRuleList = alertMessageCountRuleRecord.get()
                                .getStreamAlertMessageCountRuleList();
                        StreamAlertMessageCountRuleList configObject = null;
                        Iterator<StreamAlertMessageCountRuleList> iterator = streamAlertRuleList.iterator();

                        while (iterator.hasNext()) {

                            configObject = iterator.next();

                            if (configObject.getConfigID().equalsIgnoreCase(configID)) {

                                tx.delete(LogicalDatastoreType.CONFIGURATION, alertMessageCountRuleRecordId
                                        .child(StreamAlertMessageCountRuleList.class, configObject.getKey()));

                            }
                        }

                    }

                    return tx.submit();
                }

            });
    Futures.addCallback(commitFuture, new FutureCallback<Void>() {
        @Override
        public void onSuccess(final Void result) {

            futureResult.set(RpcResultBuilder.<DeleteAlertMessageCountRuleOutput>success(
                    deleteAlertMessageCountRuleOutputBuilder.build()).build());
        }

        @Override
        public void onFailure(final Throwable ex) {

            LOG.info("Failed to commit Rule", ex);

            futureResult.set(RpcResultBuilder.<DeleteAlertMessageCountRuleOutput>failed()
                    .withRpcErrors(((TransactionCommitFailedException) ex).getErrorList()).build());

        }
    });

    return futureResult;
}

From source file:org.opendaylight.centinel.impl.CentinelImpl.java

/** 
 *    delete alertfield value rule in configurational data store. 
 * /*w w  w  .j a v  a 2s.  c  o m*/
 */

@Override
public Future<RpcResult<DeleteAlertFieldValueRuleOutput>> deleteAlertFieldValueRule(
        final DeleteAlertFieldValueRuleInput input) {
    final ReadWriteTransaction tx = dataProvider.newReadWriteTransaction();
    final SettableFuture<RpcResult<DeleteAlertFieldValueRuleOutput>> futureResult = SettableFuture.create();
    LOG.info("deleteAlertFieldValueRuleOutput: " + input);
    final DeleteAlertFieldValueRuleOutputBuilder deleteAlertFieldValueRuleOutputBuilder = new DeleteAlertFieldValueRuleOutputBuilder();
    deleteAlertFieldValueRuleOutputBuilder.setFieldValueBacklog(input.getFieldValueBacklog());
    deleteAlertFieldValueRuleOutputBuilder.setFieldValueField(input.getFieldValueField());
    deleteAlertFieldValueRuleOutputBuilder.setFieldValueGrace(input.getFieldValueGrace());
    deleteAlertFieldValueRuleOutputBuilder.setFieldValueThreshhold(input.getFieldValueThreshhold());
    deleteAlertFieldValueRuleOutputBuilder.setFieldValueThreshholdType(input.getFieldValueThreshholdType());
    deleteAlertFieldValueRuleOutputBuilder.setFieldValueThreshholdType(input.getFieldValueThreshholdType());
    deleteAlertFieldValueRuleOutputBuilder.setRuleID(input.getRuleID());
    deleteAlertFieldValueRuleOutputBuilder.setNodeType(input.getNodeType());
    deleteAlertFieldValueRuleOutputBuilder.setRuleTypeClassifier(input.getRuleTypeClassifier());
    deleteAlertFieldValueRuleOutputBuilder.setStreamID(input.getStreamID());
    deleteAlertFieldValueRuleOutputBuilder.setTimeStamp(input.getTimeStamp());
    deleteAlertFieldValueRuleOutputBuilder.setAlertTypeClassifier(input.getAlertTypeClassifier());

    ListenableFuture<Optional<AlertFieldValueRuleRecord>> readFutureOperational = tx
            .read(LogicalDatastoreType.OPERATIONAL, alertFieldValueRuleRecordId);

    ListenableFuture<Optional<AlertFieldValueRuleRecord>> readFutureConfigure = tx
            .read(LogicalDatastoreType.CONFIGURATION, alertFieldValueRuleRecordId);

    String configId = null;

    try {
        AlertFieldValueRuleRecord operationalRecord = readFutureOperational.get().get();
        List<StreamAlertFieldValueRuleList> streamAlertRuleList = new ArrayList<StreamAlertFieldValueRuleList>();

        if (!operationalRecord.getStreamAlertFieldValueRuleList().isEmpty()) {
            streamAlertRuleList = operationalRecord.getStreamAlertFieldValueRuleList();
            Iterator<StreamAlertFieldValueRuleList> itearator = streamAlertRuleList.iterator();
            StreamAlertFieldValueRuleList operationalObject = null;

            while (itearator.hasNext()) {
                operationalObject = itearator.next();
                if (operationalObject.getRuleID().equalsIgnoreCase(input.getRuleID())
                        && operationalObject.getStreamID().equalsIgnoreCase(input.getStreamID())) {
                    configId = operationalObject.getConfigID();

                }
            }

        }

    } catch (InterruptedException | ExecutionException e) {
        futureResult.set(RpcResultBuilder.<DeleteAlertFieldValueRuleOutput>failed()
                .withRpcErrors(((TransactionCommitFailedException) e).getErrorList()).build());
        return futureResult;

    }
    final String configID = configId;
    final ListenableFuture<Void> commitFuture = Futures.transform(readFutureConfigure,
            new AsyncFunction<Optional<AlertFieldValueRuleRecord>, Void>() {

                @Override
                public ListenableFuture<Void> apply(
                        final Optional<AlertFieldValueRuleRecord> alertFieldValueRuleRecord) throws Exception {

                    List<StreamAlertFieldValueRuleList> streamAlertRuleList = new ArrayList<StreamAlertFieldValueRuleList>();

                    if (alertFieldValueRuleRecord.isPresent()) {

                        streamAlertRuleList = alertFieldValueRuleRecord.get()
                                .getStreamAlertFieldValueRuleList();
                        StreamAlertFieldValueRuleList configObject = null;
                        Iterator<StreamAlertFieldValueRuleList> iterator = streamAlertRuleList.iterator();
                        while (iterator.hasNext()) {
                            configObject = iterator.next();

                            if (configObject.getConfigID().equalsIgnoreCase(configID)) {

                                tx.delete(LogicalDatastoreType.CONFIGURATION, alertFieldValueRuleRecordId
                                        .child(StreamAlertFieldValueRuleList.class, configObject.getKey()));

                            }
                        }

                    }

                    return tx.submit();
                }

            });
    Futures.addCallback(commitFuture, new FutureCallback<Void>() {
        @Override
        public void onSuccess(final Void result) {

            futureResult.set(RpcResultBuilder
                    .<DeleteAlertFieldValueRuleOutput>success(deleteAlertFieldValueRuleOutputBuilder.build())
                    .build());
        }

        @Override
        public void onFailure(final Throwable ex) {

            LOG.debug("Failed to commit Rule", ex);

            futureResult.set(RpcResultBuilder.<DeleteAlertFieldValueRuleOutput>failed()
                    .withRpcErrors(((TransactionCommitFailedException) ex).getErrorList()).build());

        }
    });

    return futureResult;
}

From source file:org.opendaylight.centinel.impl.CentinelImpl.java

@Override
public void onDataChanged(AsyncDataChangeEvent<InstanceIdentifier<?>, DataObject> change) {

    LOG.info("onDataChanged called ");
    final ReadWriteTransaction tx = dataProvider.newReadWriteTransaction();

    DataObject dataObject = change.getUpdatedSubtree();

    if (dataObject instanceof AlertMessageCountRuleRecord) {

        AlertMessageCountRuleRecord record = (AlertMessageCountRuleRecord) dataObject;
        Iterator<DataObject> iterator = change.getCreatedData().values().iterator();
        if (iterator.hasNext()) {
            StreamAlertMessageCountRuleList tempStreamAlertMessageCountRuleList = null;
            DataObject messageCountObject = iterator.next();
            if (!(messageCountObject instanceof StreamAlertMessageCountRuleList)) {
                tempStreamAlertMessageCountRuleList = (StreamAlertMessageCountRuleList) record
                        .getStreamAlertMessageCountRuleList().get(0);
            } else if (messageCountObject instanceof StreamAlertMessageCountRuleList) {
                tempStreamAlertMessageCountRuleList = (StreamAlertMessageCountRuleList) messageCountObject;
            }//from  ww  w . j av  a2  s .co  m

            final StreamAlertMessageCountRuleList streamAlertMessageCountRuleList = tempStreamAlertMessageCountRuleList;

            LOG.info("Alert message count rule list: " + streamAlertMessageCountRuleList);
            ListenableFuture<Optional<AlertMessageCountRuleRecord>> readFuture = tx
                    .read(LogicalDatastoreType.OPERATIONAL, alertMessageCountRuleRecordId);

            final ListenableFuture<Void> commitFuture = Futures.transform(readFuture,
                    new AsyncFunction<Optional<AlertMessageCountRuleRecord>, Void>() {

                        @Override
                        public ListenableFuture<Void> apply(
                                final Optional<AlertMessageCountRuleRecord> alertMessageCountRuleRecord)
                                throws Exception {

                            List<StreamAlertMessageCountRuleList> streamAlertRuleList = new ArrayList<StreamAlertMessageCountRuleList>();

                            if (alertMessageCountRuleRecord.isPresent()) {
                                streamAlertRuleList = alertMessageCountRuleRecord.get()
                                        .getStreamAlertMessageCountRuleList();

                            }
                            streamAlertRuleList.add(streamAlertMessageCountRuleList);
                            tx.put(LogicalDatastoreType.OPERATIONAL, alertMessageCountRuleRecordId,
                                    new AlertMessageCountRuleRecordBuilder()
                                            .setStreamAlertMessageCountRuleList(streamAlertRuleList).build());
                            return tx.submit();

                        }
                    });
            Futures.addCallback(commitFuture, new FutureCallback<Void>() {
                @Override
                public void onSuccess(final Void result) {
                    LOG.debug("Rule commited sucessfully to operational datastore on data change");

                }

                @Override
                public void onFailure(final Throwable ex) {

                    LOG.debug("Failed to commit Rule to operational datastore on data change", ex);

                }
            });

        }

        LOG.info("onDataChanged - new Centinel config: {}", record);
    }

    else if (dataObject instanceof AlertFieldValueRuleRecord) {

        AlertFieldValueRuleRecord record = (AlertFieldValueRuleRecord) dataObject;
        Iterator<DataObject> iterator = change.getCreatedData().values().iterator();
        if (iterator.hasNext()) {

            StreamAlertFieldValueRuleList tempStreamAlertFieldValueRuleList = null;
            DataObject fieldValueObject = iterator.next();
            if (!(fieldValueObject instanceof StreamAlertFieldValueRuleList)) {
                tempStreamAlertFieldValueRuleList = (StreamAlertFieldValueRuleList) record
                        .getStreamAlertFieldValueRuleList().get(0);
            } else if (fieldValueObject instanceof StreamAlertFieldValueRuleList) {
                tempStreamAlertFieldValueRuleList = (StreamAlertFieldValueRuleList) fieldValueObject;
            }

            final StreamAlertFieldValueRuleList streamAlertFieldValueRuleList = tempStreamAlertFieldValueRuleList;
            LOG.info("Alert Field value rule list: " + streamAlertFieldValueRuleList);
            ListenableFuture<Optional<AlertFieldValueRuleRecord>> readFuture = tx
                    .read(LogicalDatastoreType.OPERATIONAL, alertFieldValueRuleRecordId);

            final ListenableFuture<Void> commitFuture = Futures.transform(readFuture,
                    new AsyncFunction<Optional<AlertFieldValueRuleRecord>, Void>() {

                        @Override
                        public ListenableFuture<Void> apply(
                                final Optional<AlertFieldValueRuleRecord> alertFieldValueRuleRecord)
                                throws Exception {

                            List<StreamAlertFieldValueRuleList> streamAlertRuleList = new ArrayList<StreamAlertFieldValueRuleList>();

                            if (alertFieldValueRuleRecord.isPresent()) {
                                streamAlertRuleList = alertFieldValueRuleRecord.get()
                                        .getStreamAlertFieldValueRuleList();

                            }
                            streamAlertRuleList.add(streamAlertFieldValueRuleList);
                            tx.put(LogicalDatastoreType.OPERATIONAL, alertFieldValueRuleRecordId,
                                    new AlertFieldValueRuleRecordBuilder()
                                            .setStreamAlertFieldValueRuleList(streamAlertRuleList).build());
                            return tx.submit();

                        }
                    });
            Futures.addCallback(commitFuture, new FutureCallback<Void>() {
                @Override
                public void onSuccess(final Void result) {
                    LOG.debug("Rule commited sucessfully to operational datastore on data change");

                }

                @Override
                public void onFailure(final Throwable ex) {

                    LOG.debug("Failed to commit Rule to operational datastore on data change", ex);

                }
            });

        }

    }

    else if (dataObject instanceof AlertFieldContentRuleRecord) {
        AlertFieldContentRuleRecord record = (AlertFieldContentRuleRecord) dataObject;
        Iterator<DataObject> iterator = change.getCreatedData().values().iterator();
        if (iterator.hasNext()) {

            StreamAlertFieldContentRuleList tempStreamAlertFieldContentRuleList = null;
            DataObject fieldContentObject = iterator.next();
            if (!(fieldContentObject instanceof StreamAlertFieldContentRuleList)) {
                tempStreamAlertFieldContentRuleList = (StreamAlertFieldContentRuleList) record
                        .getStreamAlertFieldContentRuleList().get(0);
            } else if (fieldContentObject instanceof StreamAlertFieldContentRuleList) {
                tempStreamAlertFieldContentRuleList = (StreamAlertFieldContentRuleList) fieldContentObject;
            }

            final StreamAlertFieldContentRuleList streamAlertFieldContentRuleList = tempStreamAlertFieldContentRuleList;
            LOG.info("Alert Field content rule list: " + streamAlertFieldContentRuleList);
            ListenableFuture<Optional<AlertFieldContentRuleRecord>> readFuture = tx
                    .read(LogicalDatastoreType.OPERATIONAL, alertFeildContentRuleRecordId);

            final ListenableFuture<Void> commitFuture = Futures.transform(readFuture,
                    new AsyncFunction<Optional<AlertFieldContentRuleRecord>, Void>() {

                        @Override
                        public ListenableFuture<Void> apply(
                                final Optional<AlertFieldContentRuleRecord> alertFieldContentRuleRecord)
                                throws Exception {

                            List<StreamAlertFieldContentRuleList> streamAlertRuleList = new ArrayList<StreamAlertFieldContentRuleList>();

                            if (alertFieldContentRuleRecord.isPresent()) {
                                streamAlertRuleList = alertFieldContentRuleRecord.get()
                                        .getStreamAlertFieldContentRuleList();

                            }
                            streamAlertRuleList.add(streamAlertFieldContentRuleList);
                            tx.put(LogicalDatastoreType.OPERATIONAL, alertFeildContentRuleRecordId,
                                    new AlertFieldContentRuleRecordBuilder()
                                            .setStreamAlertFieldContentRuleList(streamAlertRuleList).build());
                            return tx.submit();

                        }
                    });
            Futures.addCallback(commitFuture, new FutureCallback<Void>() {
                @Override
                public void onSuccess(final Void result) {
                    LOG.debug("Rule commited sucessfully to operational datastore on data change");

                }

                @Override
                public void onFailure(final Throwable ex) {

                    LOG.debug("Failed to commit Rule to operational datastore on data change", ex);

                }
            });

        }
    }

}