From 2085e0751a1a800c05ca798f9f8a80c08464e3b2 Mon Sep 17 00:00:00 2001 From: Jonathan Hart Date: Thu, 12 Feb 2015 11:44:03 -0800 Subject: [PATCH] Removed deprecated IntentStore#batchWrite() API. Also javadoc fixes. Change-Id: I4ccd109a22189f4762afec15a719e42a3b9e4f7b --- .../onosproject/net/intent/IntentStore.java | 17 ++-- .../intent/impl/DistributedIntentStore.java | 14 +--- .../store/intent/impl/GossipIntentStore.java | 24 ++---- .../intent/impl/HazelcastIntentStore.java | 12 +-- .../store/intent/impl/SimpleIntentStore.java | 77 ++----------------- .../store/trivial/impl/SimpleIntentStore.java | 66 ---------------- 6 files changed, 32 insertions(+), 178 deletions(-) diff --git a/core/api/src/main/java/org/onosproject/net/intent/IntentStore.java b/core/api/src/main/java/org/onosproject/net/intent/IntentStore.java index ceb5493b32..b6f7aedbd3 100644 --- a/core/api/src/main/java/org/onosproject/net/intent/IntentStore.java +++ b/core/api/src/main/java/org/onosproject/net/intent/IntentStore.java @@ -15,7 +15,6 @@ */ package org.onosproject.net.intent; -import org.onosproject.net.intent.BatchWrite.Operation; import org.onosproject.store.Store; import java.util.List; @@ -61,16 +60,18 @@ public interface IntentStore extends Store { } /** - * Execute writes in a batch. - * If the specified BatchWrite is empty, write will not be executed. + * Writes an IntentData object to the store. * - * @param batch BatchWrite to execute - * @return failed operations + * @param newData new intent data to write */ - @Deprecated - List batchWrite(BatchWrite batch); - default void write(IntentData newData) {} + + /** + * Writes a batch of IntentData objects to the store. A batch has no + * semantics, this is simply a convenience API. + * + * @param updates collection of intent data objects to write + */ default void batchWrite(Iterable updates) {} /** diff --git a/core/store/dist/src/main/java/org/onosproject/store/intent/impl/DistributedIntentStore.java b/core/store/dist/src/main/java/org/onosproject/store/intent/impl/DistributedIntentStore.java index 8d56098d19..fd76653963 100644 --- a/core/store/dist/src/main/java/org/onosproject/store/intent/impl/DistributedIntentStore.java +++ b/core/store/dist/src/main/java/org/onosproject/store/intent/impl/DistributedIntentStore.java @@ -22,7 +22,6 @@ import com.google.common.cache.CacheBuilder; import com.google.common.cache.CacheLoader; import com.google.common.cache.LoadingCache; import com.google.common.collect.ImmutableSet; -import com.google.common.collect.Lists; import org.apache.felix.scr.annotations.Activate; import org.apache.felix.scr.annotations.Component; import org.apache.felix.scr.annotations.Deactivate; @@ -32,8 +31,6 @@ import org.apache.felix.scr.annotations.Service; import org.onlab.metrics.MetricsService; import org.onlab.util.KryoNamespace; import org.onosproject.core.MetricsHelper; -import org.onosproject.net.intent.BatchWrite; -import org.onosproject.net.intent.BatchWrite.Operation; import org.onosproject.net.intent.Intent; import org.onosproject.net.intent.IntentEvent; import org.onosproject.net.intent.IntentId; @@ -45,24 +42,17 @@ import org.onosproject.store.AbstractStore; import org.onosproject.store.serializers.KryoNamespaces; import org.onosproject.store.serializers.KryoSerializer; import org.onosproject.store.serializers.StoreSerializer; -import org.onosproject.store.service.BatchWriteRequest; -import org.onosproject.store.service.BatchWriteRequest.Builder; -import org.onosproject.store.service.BatchWriteResult; import org.onosproject.store.service.DatabaseAdminService; import org.onosproject.store.service.DatabaseService; import org.onosproject.store.service.impl.CMap; import org.slf4j.Logger; -import java.util.ArrayList; -import java.util.Collections; import java.util.EnumSet; -import java.util.HashSet; import java.util.List; import java.util.Map; import java.util.Set; import java.util.concurrent.ConcurrentHashMap; -import static com.google.common.base.Preconditions.checkArgument; import static org.onlab.metrics.MetricsUtil.startTimer; import static org.onlab.metrics.MetricsUtil.stopTimer; import static org.onosproject.net.intent.IntentState.FAILED; @@ -292,7 +282,7 @@ public class DistributedIntentStore } } - @Override + /*@Override public List batchWrite(BatchWrite batch) { if (batch.isEmpty()) { return Collections.emptyList(); @@ -370,5 +360,5 @@ public class DistributedIntentStore // everything failed return batch.operations(); } - } + }*/ } diff --git a/core/store/dist/src/main/java/org/onosproject/store/intent/impl/GossipIntentStore.java b/core/store/dist/src/main/java/org/onosproject/store/intent/impl/GossipIntentStore.java index d81435fd2e..c78b5f979f 100644 --- a/core/store/dist/src/main/java/org/onosproject/store/intent/impl/GossipIntentStore.java +++ b/core/store/dist/src/main/java/org/onosproject/store/intent/impl/GossipIntentStore.java @@ -23,7 +23,6 @@ import org.apache.felix.scr.annotations.ReferenceCardinality; import org.apache.felix.scr.annotations.Service; import org.onlab.util.KryoNamespace; import org.onosproject.cluster.ClusterService; -import org.onosproject.net.intent.BatchWrite; import org.onosproject.net.intent.Intent; import org.onosproject.net.intent.IntentData; import org.onosproject.net.intent.IntentEvent; @@ -45,11 +44,7 @@ import org.slf4j.Logger; import java.util.List; import java.util.stream.Collectors; -import static org.onosproject.net.intent.IntentState.FAILED; -import static org.onosproject.net.intent.IntentState.INSTALLED; -import static org.onosproject.net.intent.IntentState.INSTALLING; -import static org.onosproject.net.intent.IntentState.WITHDRAWING; -import static org.onosproject.net.intent.IntentState.WITHDRAWN; +import static org.onosproject.net.intent.IntentState.*; import static org.slf4j.LoggerFactory.getLogger; /** @@ -143,12 +138,6 @@ public class GossipIntentStore return null; } - @Override - public List batchWrite(BatchWrite batch) { - // Deprecated - return null; - } - private IntentData copyData(IntentData original) { if (original == null) { return null; @@ -163,10 +152,13 @@ public class GossipIntentStore } /** - * TODO. - * @param currentData - * @param newData - * @return + * Determines whether an intent data update is allowed. The update must + * either have a higher version than the current data, or the state + * transition between two updates of the same version must be sane. + * + * @param currentData existing intent data in the store + * @param newData new intent data update proposal + * @return true if we can apply the update, otherwise false */ private boolean isUpdateAcceptable(IntentData currentData, IntentData newData) { diff --git a/core/store/dist/src/main/java/org/onosproject/store/intent/impl/HazelcastIntentStore.java b/core/store/dist/src/main/java/org/onosproject/store/intent/impl/HazelcastIntentStore.java index e66d7cae24..8514dedf75 100644 --- a/core/store/dist/src/main/java/org/onosproject/store/intent/impl/HazelcastIntentStore.java +++ b/core/store/dist/src/main/java/org/onosproject/store/intent/impl/HazelcastIntentStore.java @@ -20,7 +20,6 @@ import com.codahale.metrics.Timer.Context; import com.google.common.base.Verify; import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableSet; -import com.google.common.collect.Lists; import com.hazelcast.config.Config; import com.hazelcast.config.MapConfig; import com.hazelcast.core.EntryAdapter; @@ -53,8 +52,6 @@ import org.onosproject.store.serializers.KryoNamespaces; import org.onosproject.store.serializers.KryoSerializer; import org.slf4j.Logger; -import java.util.ArrayList; -import java.util.Collections; import java.util.EnumSet; import java.util.List; import java.util.Map; @@ -66,7 +63,10 @@ import java.util.concurrent.Future; import static com.google.common.base.Preconditions.checkArgument; import static org.onlab.metrics.MetricsUtil.startTimer; import static org.onlab.metrics.MetricsUtil.stopTimer; -import static org.onosproject.net.intent.IntentState.*; +import static org.onosproject.net.intent.IntentState.FAILED; +import static org.onosproject.net.intent.IntentState.INSTALLED; +import static org.onosproject.net.intent.IntentState.INSTALL_REQ; +import static org.onosproject.net.intent.IntentState.WITHDRAWN; import static org.slf4j.LoggerFactory.getLogger; //TODO Note: this store will be removed @@ -277,7 +277,7 @@ public class HazelcastIntentStore */ } - @Override + /*@Override public List batchWrite(BatchWrite batch) { if (batch.isEmpty()) { return Collections.emptyList(); @@ -297,7 +297,7 @@ public class HazelcastIntentStore notifyDelegate(events); return failed; - } + }*/ private void batchWriteAsync(BatchWrite batch, List failed, List>>> futures) { diff --git a/core/store/dist/src/main/java/org/onosproject/store/intent/impl/SimpleIntentStore.java b/core/store/dist/src/main/java/org/onosproject/store/intent/impl/SimpleIntentStore.java index 89952ced87..2bc5b63017 100644 --- a/core/store/dist/src/main/java/org/onosproject/store/intent/impl/SimpleIntentStore.java +++ b/core/store/dist/src/main/java/org/onosproject/store/intent/impl/SimpleIntentStore.java @@ -20,8 +20,6 @@ import org.apache.felix.scr.annotations.Activate; import org.apache.felix.scr.annotations.Component; import org.apache.felix.scr.annotations.Deactivate; import org.apache.felix.scr.annotations.Service; -import org.onosproject.net.intent.BatchWrite; -import org.onosproject.net.intent.BatchWrite.Operation; import org.onosproject.net.intent.Intent; import org.onosproject.net.intent.IntentData; import org.onosproject.net.intent.IntentEvent; @@ -110,76 +108,15 @@ public class SimpleIntentStore */ } - /* - * Execute writes in a batch. - * - * @param batch BatchWrite to execute - * @return failed operations - */ - @Override - public List batchWrite(BatchWrite batch) { - throw new UnsupportedOperationException("deprecated"); - /* - if (batch.isEmpty()) { - return Collections.emptyList(); - } - - List failed = Lists.newArrayList(); - for (Operation op : batch.operations()) { - switch (op.type()) { - case CREATE_INTENT: - checkArgument(op.args().size() == 1, - "CREATE_INTENT takes 1 argument. %s", op); - Intent intent = (Intent) op.args().get(0); - // TODO: what if it failed? -// createIntent(intent); FIXME - break; - - case REMOVE_INTENT: - checkArgument(op.args().size() == 1, - "REMOVE_INTENT takes 1 argument. %s", op); - IntentId intentId = (IntentId) op.args().get(0); -// removeIntent(intentId); FIXME - break; - - case REMOVE_INSTALLED: - checkArgument(op.args().size() == 1, - "REMOVE_INSTALLED takes 1 argument. %s", op); - intentId = (IntentId) op.args().get(0); - removeInstalledIntents(intentId); - break; - - case SET_INSTALLABLE: - checkArgument(op.args().size() == 2, - "SET_INSTALLABLE takes 2 arguments. %s", op); - intentId = (IntentId) op.args().get(0); - @SuppressWarnings("unchecked") - List installableIntents = (List) op.args().get(1); - setInstallableIntents(intentId, installableIntents); - break; - - case SET_STATE: - checkArgument(op.args().size() == 2, - "SET_STATE takes 2 arguments. %s", op); - intent = (Intent) op.args().get(0); - IntentState newState = (IntentState) op.args().get(1); - setState(intent, newState); - break; - - default: - break; - } - } - return failed; - */ - } - /** - * TODO. - * @param currentData - * @param newData - * @return + * Determines whether an intent data update is allowed. The update must + * either have a higher version than the current data, or the state + * transition between two updates of the same version must be sane. + * + * @param currentData existing intent data in the store + * @param newData new intent data update proposal + * @return true if we can apply the update, otherwise false */ private boolean isUpdateAcceptable(IntentData currentData, IntentData newData) { diff --git a/core/store/trivial/src/main/java/org/onosproject/store/trivial/impl/SimpleIntentStore.java b/core/store/trivial/src/main/java/org/onosproject/store/trivial/impl/SimpleIntentStore.java index 906b942c5e..7e5eb12034 100644 --- a/core/store/trivial/src/main/java/org/onosproject/store/trivial/impl/SimpleIntentStore.java +++ b/core/store/trivial/src/main/java/org/onosproject/store/trivial/impl/SimpleIntentStore.java @@ -20,8 +20,6 @@ import org.apache.felix.scr.annotations.Activate; import org.apache.felix.scr.annotations.Component; import org.apache.felix.scr.annotations.Deactivate; import org.apache.felix.scr.annotations.Service; -import org.onosproject.net.intent.BatchWrite; -import org.onosproject.net.intent.BatchWrite.Operation; import org.onosproject.net.intent.Intent; import org.onosproject.net.intent.IntentData; import org.onosproject.net.intent.IntentEvent; @@ -87,70 +85,6 @@ public class SimpleIntentStore return (data != null) ? data.installables() : null; } - /* - * Execute writes in a batch. - * - * @param batch BatchWrite to execute - * @return failed operations - */ - @Override - public List batchWrite(BatchWrite batch) { - throw new UnsupportedOperationException("deprecated"); - /* - if (batch.isEmpty()) { - return Collections.emptyList(); - } - - List failed = Lists.newArrayList(); - for (Operation op : batch.operations()) { - switch (op.type()) { - case CREATE_INTENT: - checkArgument(op.args().size() == 1, - "CREATE_INTENT takes 1 argument. %s", op); - Intent intent = (Intent) op.args().get(0); - // TODO: what if it failed? -// createIntent(intent); FIXME - break; - - case REMOVE_INTENT: - checkArgument(op.args().size() == 1, - "REMOVE_INTENT takes 1 argument. %s", op); - IntentId intentId = (IntentId) op.args().get(0); -// removeIntent(intentId); FIXME - break; - - case REMOVE_INSTALLED: - checkArgument(op.args().size() == 1, - "REMOVE_INSTALLED takes 1 argument. %s", op); - intentId = (IntentId) op.args().get(0); - removeInstalledIntents(intentId); - break; - - case SET_INSTALLABLE: - checkArgument(op.args().size() == 2, - "SET_INSTALLABLE takes 2 arguments. %s", op); - intentId = (IntentId) op.args().get(0); - @SuppressWarnings("unchecked") - List installableIntents = (List) op.args().get(1); - setInstallableIntents(intentId, installableIntents); - break; - - case SET_STATE: - checkArgument(op.args().size() == 2, - "SET_STATE takes 2 arguments. %s", op); - intent = (Intent) op.args().get(0); - IntentState newState = (IntentState) op.args().get(1); - setState(intent, newState); - break; - - default: - break; - } - } - return failed; - */ - } - @Override public void write(IntentData newData) { //FIXME need to compare the versions