Sho SHIMIZU
Committed by Gerrit Code Review

Apply the naming convention to BatchOperationEntry

Resolve ONOS-889

Change-Id: I2001fabba138b9ff5be9a5943d3f020b4c38d195
......@@ -48,7 +48,17 @@ public class BatchOperationEntry<T extends Enum<?>, U> {
*
* @return the target object of this operation
*/
@Deprecated
public U getTarget() {
return target();
}
/**
* Gets the target object of this operation.
*
* @return the target object of this operation
*/
public U target() {
return target;
}
......@@ -57,7 +67,17 @@ public class BatchOperationEntry<T extends Enum<?>, U> {
*
* @return the operator of this operation
*/
@Deprecated
public T getOperator() {
return operator();
}
/**
* Gets the operator of this operation.
*
* @return the operator of this operation
*/
public T operator() {
return operator;
}
......
......@@ -44,7 +44,7 @@ public class FlowRuleBatchRequest {
@Override
public FlowRule apply(FlowRuleBatchEntry input) {
return input.getTarget();
return input.target();
}
}).toList();
}
......@@ -55,7 +55,7 @@ public class FlowRuleBatchRequest {
@Override
public FlowRule apply(FlowRuleBatchEntry input) {
return input.getTarget();
return input.target();
}
}).toList();
}
......
......@@ -147,7 +147,7 @@ public class BatchOperationTest {
public void testEntryConstruction() {
final TestEntry entry = new TestEntry(TestType.OP3, new TestTarget(3));
assertThat(entry.getOperator(), is(TestType.OP3));
assertThat(entry.getTarget().id, is(3));
assertThat(entry.operator(), is(TestType.OP3));
assertThat(entry.target().id, is(3));
}
}
......
......@@ -186,7 +186,7 @@ public class FlowRuleManager
ArrayListMultimap.create();
List<Future<CompletedBatchOperation>> futures = Lists.newArrayList();
for (FlowRuleBatchEntry fbe : batch.getOperations()) {
final FlowRule f = fbe.getTarget();
final FlowRule f = fbe.target();
perDeviceBatches.put(f.deviceId(), fbe);
}
......@@ -400,7 +400,7 @@ public class FlowRuleManager
FlowRuleBatchOperation batchOperation = request.asBatchOperation();
FlowRuleProvider flowRuleProvider =
getProvider(batchOperation.getOperations().get(0).getTarget().deviceId());
getProvider(batchOperation.getOperations().get(0).target().deviceId());
final Future<CompletedBatchOperation> result =
flowRuleProvider.executeBatch(batchOperation);
futureService.submit(new Runnable() {
......@@ -416,7 +416,7 @@ public class FlowRuleManager
Set<FlowRule> failures = new HashSet<>(batchOperation.size());
for (FlowRuleBatchEntry op : batchOperation.getOperations()) {
failures.add(op.getTarget());
failures.add(op.target());
}
res = new CompletedBatchOperation(false, failures);
store.batchOperationComplete(FlowRuleBatchEvent.completed(request, res));
......@@ -565,12 +565,12 @@ public class FlowRuleManager
log.debug("cleaning up batch");
// TODO convert these into a batch?
for (FlowRuleBatchEntry fbe : batches.values()) {
if (fbe.getOperator() == FlowRuleOperation.ADD ||
fbe.getOperator() == FlowRuleOperation.MODIFY) {
store.deleteFlowRule(fbe.getTarget());
} else if (fbe.getOperator() == FlowRuleOperation.REMOVE) {
store.removeFlowRule(new DefaultFlowEntry(fbe.getTarget()));
store.storeFlowRule(fbe.getTarget());
if (fbe.operator() == FlowRuleOperation.ADD ||
fbe.operator() == FlowRuleOperation.MODIFY) {
store.deleteFlowRule(fbe.target());
} else if (fbe.operator() == FlowRuleOperation.REMOVE) {
store.removeFlowRule(new DefaultFlowEntry(fbe.target()));
store.storeFlowRule(fbe.target());
}
}
}
......
......@@ -56,8 +56,8 @@ public class MockFlowRuleService implements FlowRuleService {
@Override
public Future<CompletedBatchOperation> applyBatch(FlowRuleBatchOperation batch) {
for (FlowRuleBatchEntry fbe : batch.getOperations()) {
FlowRule fr = fbe.getTarget();
switch (fbe.getOperator()) {
FlowRule fr = fbe.target();
switch (fbe.operator()) {
case ADD:
flows.add(fr);
break;
......
......@@ -363,7 +363,7 @@ public class DistributedFlowRuleStore
Collections.<FlowRule>emptySet()));
}
DeviceId deviceId = operation.getOperations().get(0).getTarget().deviceId();
DeviceId deviceId = operation.getOperations().get(0).target().deviceId();
ReplicaInfo replicaInfo = replicaInfoManager.getReplicaInfoFor(deviceId);
......@@ -407,8 +407,8 @@ public class DistributedFlowRuleStore
flowEntriesLock.writeLock().lock();
try {
for (FlowRuleBatchEntry batchEntry : operation.getOperations()) {
FlowRule flowRule = batchEntry.getTarget();
FlowRuleOperation op = batchEntry.getOperator();
FlowRule flowRule = batchEntry.target();
FlowRuleOperation op = batchEntry.operator();
if (did == null) {
did = flowRule.deviceId();
}
......@@ -640,13 +640,13 @@ public class DistributedFlowRuleStore
FlowRuleBatchOperation operation = SERIALIZER.decode(message.payload());
log.debug("received batch request {}", operation);
final DeviceId deviceId = operation.getOperations().get(0).getTarget().deviceId();
final DeviceId deviceId = operation.getOperations().get(0).target().deviceId();
ReplicaInfo replicaInfo = replicaInfoManager.getReplicaInfoFor(deviceId);
if (!local.equals(replicaInfo.master().orNull())) {
Set<FlowRule> failures = new HashSet<>(operation.size());
for (FlowRuleBatchEntry op : operation.getOperations()) {
failures.add(op.getTarget());
failures.add(op.target());
}
CompletedBatchOperation allFailed = new CompletedBatchOperation(false, failures);
// This node is no longer the master, respond as all failed.
......@@ -675,7 +675,7 @@ public class DistributedFlowRuleStore
// create everything failed response
Set<FlowRule> failures = new HashSet<>(operation.size());
for (FlowRuleBatchEntry op : operation.getOperations()) {
failures.add(op.getTarget());
failures.add(op.target());
}
result = new CompletedBatchOperation(false, failures);
}
......@@ -754,7 +754,7 @@ public class DistributedFlowRuleStore
final SMap<FlowId, ImmutableList<StoredFlowEntry>> backupFlowTable = smaps.get(deviceId);
// Following should be rewritten using async APIs
for (FlowRuleBatchEntry bEntry : toAdd) {
final FlowRule entry = bEntry.getTarget();
final FlowRule entry = bEntry.target();
final FlowId id = entry.id();
ImmutableList<StoredFlowEntry> original = backupFlowTable.get(id);
List<StoredFlowEntry> list = new ArrayList<>();
......@@ -762,7 +762,7 @@ public class DistributedFlowRuleStore
list.addAll(original);
}
list.remove(bEntry.getTarget());
list.remove(bEntry.target());
list.add((StoredFlowEntry) entry);
ImmutableList<StoredFlowEntry> newValue = ImmutableList.copyOf(list);
......@@ -777,7 +777,7 @@ public class DistributedFlowRuleStore
}
}
for (FlowRuleBatchEntry bEntry : toRemove) {
final FlowRule entry = bEntry.getTarget();
final FlowRule entry = bEntry.target();
final FlowId id = entry.id();
ImmutableList<StoredFlowEntry> original = backupFlowTable.get(id);
List<StoredFlowEntry> list = new ArrayList<>();
......@@ -785,7 +785,7 @@ public class DistributedFlowRuleStore
list.addAll(original);
}
list.remove(bEntry.getTarget());
list.remove(bEntry.target());
ImmutableList<StoredFlowEntry> newValue = ImmutableList.copyOf(list);
boolean success;
......
......@@ -266,13 +266,13 @@ public class SimpleFlowRuleStore
List<FlowRuleBatchEntry> toAdd = new ArrayList<>();
List<FlowRuleBatchEntry> toRemove = new ArrayList<>();
for (FlowRuleBatchEntry entry : batchOperation.getOperations()) {
final FlowRule flowRule = entry.getTarget();
if (entry.getOperator().equals(FlowRuleOperation.ADD)) {
final FlowRule flowRule = entry.target();
if (entry.operator().equals(FlowRuleOperation.ADD)) {
if (!getFlowEntries(flowRule.deviceId(), flowRule.id()).contains(flowRule)) {
storeFlowRule(flowRule);
toAdd.add(entry);
}
} else if (entry.getOperator().equals(FlowRuleOperation.REMOVE)) {
} else if (entry.operator().equals(FlowRuleOperation.REMOVE)) {
if (getFlowEntries(flowRule.deviceId(), flowRule.id()).contains(flowRule)) {
deleteFlowRule(flowRule);
toRemove.add(entry);
......
......@@ -110,16 +110,16 @@ public class NullFlowRuleProvider extends AbstractProvider implements FlowRulePr
public Future<CompletedBatchOperation> executeBatch(
BatchOperation<FlowRuleBatchEntry> batch) {
for (FlowRuleBatchEntry fbe : batch.getOperations()) {
switch (fbe.getOperator()) {
switch (fbe.operator()) {
case ADD:
applyFlowRule(fbe.getTarget());
applyFlowRule(fbe.target());
break;
case REMOVE:
removeFlowRule(fbe.getTarget());
removeFlowRule(fbe.target());
break;
case MODIFY:
removeFlowRule(fbe.getTarget());
applyFlowRule(fbe.getTarget());
removeFlowRule(fbe.target());
applyFlowRule(fbe.target());
break;
default:
log.error("Unknown flow operation: {}", fbe);
......
......@@ -201,7 +201,7 @@ public class OpenFlowRuleProvider extends AbstractProvider implements FlowRulePr
*/
Map<OFFlowMod, OpenFlowSwitch> mods = Maps.newIdentityHashMap();
for (FlowRuleBatchEntry fbe : batch.getOperations()) {
FlowRule flowRule = fbe.getTarget();
FlowRule flowRule = fbe.target();
final Dpid dpid = Dpid.dpid(flowRule.deviceId().uri());
OpenFlowSwitch sw = controller.getSwitch(dpid);
if (sw == null) {
......@@ -220,7 +220,7 @@ public class OpenFlowRuleProvider extends AbstractProvider implements FlowRulePr
FlowModBuilder.builder(flowRule, sw.factory(),
Optional.of(flowModXid));
OFFlowMod mod = null;
switch (fbe.getOperator()) {
switch (fbe.operator()) {
case ADD:
mod = builder.buildFlowAdd();
break;
......@@ -231,7 +231,7 @@ public class OpenFlowRuleProvider extends AbstractProvider implements FlowRulePr
mod = builder.buildFlowMod();
break;
default:
log.error("Unsupported batch operation {}", fbe.getOperator());
log.error("Unsupported batch operation {}", fbe.operator());
}
if (mod != null) {
mods.put(mod, sw);
......@@ -406,7 +406,7 @@ public class OpenFlowRuleProvider extends AbstractProvider implements FlowRulePr
FlowEntry fe = null;
FlowRuleBatchEntry fbe = fms.get(msg.getXid());
failedId = fbe.id();
FlowRule offending = fbe.getTarget();
FlowRule offending = fbe.target();
//TODO handle specific error msgs
switch (msg.getErrType()) {
case BAD_ACTION:
......@@ -482,11 +482,11 @@ public class OpenFlowRuleProvider extends AbstractProvider implements FlowRulePr
this.state = BatchState.CANCELLED;
cleanUp();
for (FlowRuleBatchEntry fbe : fms.values()) {
if (fbe.getOperator() == FlowRuleOperation.ADD ||
fbe.getOperator() == FlowRuleOperation.MODIFY) {
removeFlowRule(fbe.getTarget());
} else if (fbe.getOperator() == FlowRuleOperation.REMOVE) {
applyRule(fbe.getTarget());
if (fbe.operator() == FlowRuleOperation.ADD ||
fbe.operator() == FlowRuleOperation.MODIFY) {
removeFlowRule(fbe.target());
} else if (fbe.operator() == FlowRuleOperation.REMOVE) {
applyRule(fbe.target());
}
}
......@@ -554,7 +554,7 @@ public class OpenFlowRuleProvider extends AbstractProvider implements FlowRulePr
.add("pending devices", sws)
.add("devices in batch",
fms.values().stream()
.map((fbe) -> fbe.getTarget().deviceId())
.map((fbe) -> fbe.target().deviceId())
.distinct().collect(Collectors.toList()))
.add("failedId", failedId)
.add("latchCount", countDownLatch.getCount())
......