Refactor connectivity intent creation to use builders
- Each connectivity intent now has only one constructor
- Intent constructors are now private for leaf classes and
protected for classes that can be derived from
- Each intent class has a Builder class that accumulates
parameters for intent creation
- Each intent class has a public static builder() method
to create a builder
- Each Builder class has a build() method to create the
intent from the accumulated parameters
- Added keys to a few intent types that were missing them
- Tightened up usage of checkNotNull(), taking advantage of
the return value to save some lines of code
- Modified callers to use the builders instead of directly
calling the constructors
Change-Id: I713185d5ecbadbf51f87ef7f68fec41102106c78
diff --git a/core/net/src/main/java/org/onosproject/net/intent/impl/compiler/HostToHostIntentCompiler.java b/core/net/src/main/java/org/onosproject/net/intent/impl/compiler/HostToHostIntentCompiler.java
index 60306b2..feea42f 100644
--- a/core/net/src/main/java/org/onosproject/net/intent/impl/compiler/HostToHostIntentCompiler.java
+++ b/core/net/src/main/java/org/onosproject/net/intent/impl/compiler/HostToHostIntentCompiler.java
@@ -97,9 +97,14 @@
HostToHostIntent intent) {
TrafficSelector selector = builder(intent.selector())
.matchEthSrc(src.mac()).matchEthDst(dst.mac()).build();
- return new PathIntent(intent.appId(), selector, intent.treatment(),
- path, intent.constraints(),
- intent.priority());
+ return PathIntent.builder()
+ .appId(intent.appId())
+ .selector(selector)
+ .treatment(intent.treatment())
+ .path(path)
+ .constraints(intent.constraints())
+ .priority(intent.priority())
+ .build();
}
}
diff --git a/core/net/src/main/java/org/onosproject/net/intent/impl/compiler/MplsIntentCompiler.java b/core/net/src/main/java/org/onosproject/net/intent/impl/compiler/MplsIntentCompiler.java
index 948dbd6..b59d7eb 100644
--- a/core/net/src/main/java/org/onosproject/net/intent/impl/compiler/MplsIntentCompiler.java
+++ b/core/net/src/main/java/org/onosproject/net/intent/impl/compiler/MplsIntentCompiler.java
@@ -75,11 +75,16 @@
*/
private Intent createPathIntent(Path path,
MplsIntent intent) {
- return new MplsPathIntent(intent.appId(),
- intent.selector(), intent.treatment(), path,
- intent.ingressLabel(), intent.egressLabel(),
- intent.constraints(),
- intent.priority());
+ return MplsPathIntent.builder()
+ .appId(intent.appId())
+ .selector(intent.selector())
+ .treatment(intent.treatment())
+ .path(path)
+ .ingressLabel(intent.ingressLabel())
+ .egressLabel(intent.egressLabel())
+ .constraints(intent.constraints())
+ .priority(intent.priority())
+ .build();
}
diff --git a/core/net/src/main/java/org/onosproject/net/intent/impl/compiler/MultiPointToSinglePointIntentCompiler.java b/core/net/src/main/java/org/onosproject/net/intent/impl/compiler/MultiPointToSinglePointIntentCompiler.java
index 6403019..fbdfa9c 100644
--- a/core/net/src/main/java/org/onosproject/net/intent/impl/compiler/MultiPointToSinglePointIntentCompiler.java
+++ b/core/net/src/main/java/org/onosproject/net/intent/impl/compiler/MultiPointToSinglePointIntentCompiler.java
@@ -16,7 +16,6 @@
package org.onosproject.net.intent.impl.compiler;
import java.util.Arrays;
-import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@@ -89,14 +88,16 @@
}
}
- Set<ConnectPoint> egress = ImmutableSet.of(intent.egressPoint());
- Intent result = new LinkCollectionIntent(intent.appId(),
- intent.selector(), intent.treatment(),
- Sets.newHashSet(links.values()),
- intent.ingressPoints(),
- ImmutableSet.of(intent.egressPoint()),
- Collections.emptyList(),
- intent.priority());
+ Intent result = LinkCollectionIntent.builder()
+ .appId(intent.appId())
+ .selector(intent.selector())
+ .treatment(intent.treatment())
+ .links(Sets.newHashSet(links.values()))
+ .ingressPoints(intent.ingressPoints())
+ .egressPoints(ImmutableSet.of(intent.egressPoint()))
+ .priority(intent.priority())
+ .build();
+
return Arrays.asList(result);
}
diff --git a/core/net/src/main/java/org/onosproject/net/intent/impl/compiler/PointToPointIntentCompiler.java b/core/net/src/main/java/org/onosproject/net/intent/impl/compiler/PointToPointIntentCompiler.java
index 0f897a4..208c8e2 100644
--- a/core/net/src/main/java/org/onosproject/net/intent/impl/compiler/PointToPointIntentCompiler.java
+++ b/core/net/src/main/java/org/onosproject/net/intent/impl/compiler/PointToPointIntentCompiler.java
@@ -91,10 +91,14 @@
*/
private Intent createPathIntent(Path path,
PointToPointIntent intent) {
- return new PathIntent(intent.appId(),
- intent.selector(), intent.treatment(), path,
- intent.constraints(),
- intent.priority());
+ return PathIntent.builder()
+ .appId(intent.appId())
+ .selector(intent.selector())
+ .treatment(intent.treatment())
+ .path(path)
+ .constraints(intent.constraints())
+ .priority(intent.priority())
+ .build();
}
}
diff --git a/core/net/src/main/java/org/onosproject/net/intent/impl/compiler/SinglePointToMultiPointIntentCompiler.java b/core/net/src/main/java/org/onosproject/net/intent/impl/compiler/SinglePointToMultiPointIntentCompiler.java
index 4b2260e..8a97b7b 100644
--- a/core/net/src/main/java/org/onosproject/net/intent/impl/compiler/SinglePointToMultiPointIntentCompiler.java
+++ b/core/net/src/main/java/org/onosproject/net/intent/impl/compiler/SinglePointToMultiPointIntentCompiler.java
@@ -16,7 +16,6 @@
package org.onosproject.net.intent.impl.compiler;
import java.util.Arrays;
-import java.util.Collections;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
@@ -66,13 +65,16 @@
links.addAll(path.links());
}
- Intent result = new LinkCollectionIntent(intent.appId(),
- intent.selector(),
- intent.treatment(), links,
- ImmutableSet.of(intent.ingressPoint()),
- intent.egressPoints(),
- Collections.emptyList(),
- intent.priority());
+ Intent result = LinkCollectionIntent.builder()
+ .appId(intent.appId())
+ .key(intent.key())
+ .selector(intent.selector())
+ .treatment(intent.treatment())
+ .links(links)
+ .ingressPoints(ImmutableSet.of(intent.ingressPoint()))
+ .egressPoints(intent.egressPoints())
+ .priority(intent.priority())
+ .build();
return Arrays.asList(result);
}