Committed by
Ray Milkey
[ONOS-3114] flowclassifierid
Change-Id: I731278516c4375dc036726058b8969a767be84ca
Showing
5 changed files
with
15 additions
and
12 deletions
... | @@ -15,6 +15,8 @@ | ... | @@ -15,6 +15,8 @@ |
15 | */ | 15 | */ |
16 | package org.onosproject.vtnrsc; | 16 | package org.onosproject.vtnrsc; |
17 | 17 | ||
18 | +import static com.google.common.base.Preconditions.checkNotNull; | ||
19 | + | ||
18 | import com.google.common.base.MoreObjects; | 20 | import com.google.common.base.MoreObjects; |
19 | 21 | ||
20 | import java.util.UUID; | 22 | import java.util.UUID; |
... | @@ -33,6 +35,7 @@ public final class FlowClassifierId { | ... | @@ -33,6 +35,7 @@ public final class FlowClassifierId { |
33 | * @param flowClassifierId flow classifier id. | 35 | * @param flowClassifierId flow classifier id. |
34 | */ | 36 | */ |
35 | private FlowClassifierId(final UUID flowClassifierId) { | 37 | private FlowClassifierId(final UUID flowClassifierId) { |
38 | + checkNotNull(flowClassifierId, "Flow classifier id can not be null"); | ||
36 | this.flowClassifierId = flowClassifierId; | 39 | this.flowClassifierId = flowClassifierId; |
37 | } | 40 | } |
38 | 41 | ||
... | @@ -42,7 +45,7 @@ public final class FlowClassifierId { | ... | @@ -42,7 +45,7 @@ public final class FlowClassifierId { |
42 | * @param flowClassifierId flow classifier id | 45 | * @param flowClassifierId flow classifier id |
43 | * @return new flow classifier id | 46 | * @return new flow classifier id |
44 | */ | 47 | */ |
45 | - public static FlowClassifierId flowClassifierId(final UUID flowClassifierId) { | 48 | + public static FlowClassifierId of(final UUID flowClassifierId) { |
46 | return new FlowClassifierId(flowClassifierId); | 49 | return new FlowClassifierId(flowClassifierId); |
47 | } | 50 | } |
48 | 51 | ||
... | @@ -52,7 +55,7 @@ public final class FlowClassifierId { | ... | @@ -52,7 +55,7 @@ public final class FlowClassifierId { |
52 | * @param flowClassifierId flow classifier id | 55 | * @param flowClassifierId flow classifier id |
53 | * @return new flow classifier id | 56 | * @return new flow classifier id |
54 | */ | 57 | */ |
55 | - public static FlowClassifierId flowClassifierId(final String flowClassifierId) { | 58 | + public static FlowClassifierId of(final String flowClassifierId) { |
56 | return new FlowClassifierId(UUID.fromString(flowClassifierId)); | 59 | return new FlowClassifierId(UUID.fromString(flowClassifierId)); |
57 | } | 60 | } |
58 | 61 | ... | ... |
... | @@ -32,11 +32,11 @@ import java.util.UUID; | ... | @@ -32,11 +32,11 @@ import java.util.UUID; |
32 | public class FlowClassifierIdTest { | 32 | public class FlowClassifierIdTest { |
33 | 33 | ||
34 | final FlowClassifierId flowClassifierId1 = FlowClassifierId | 34 | final FlowClassifierId flowClassifierId1 = FlowClassifierId |
35 | - .flowClassifierId("78dcd363-fc23-aeb6-f44b-56dc5e2fb3ae"); | 35 | + .of("78dcd363-fc23-aeb6-f44b-56dc5e2fb3ae"); |
36 | final FlowClassifierId sameAsFlowClassifierId1 = FlowClassifierId | 36 | final FlowClassifierId sameAsFlowClassifierId1 = FlowClassifierId |
37 | - .flowClassifierId("78dcd363-fc23-aeb6-f44b-56dc5e2fb3ae"); | 37 | + .of("78dcd363-fc23-aeb6-f44b-56dc5e2fb3ae"); |
38 | final FlowClassifierId flowClassifierId2 = FlowClassifierId | 38 | final FlowClassifierId flowClassifierId2 = FlowClassifierId |
39 | - .flowClassifierId("dace4513-24fc-4fae-af4b-321c5e2eb3d1"); | 39 | + .of("dace4513-24fc-4fae-af4b-321c5e2eb3d1"); |
40 | 40 | ||
41 | /** | 41 | /** |
42 | * Checks that the FlowClassifierId class is immutable. | 42 | * Checks that the FlowClassifierId class is immutable. |
... | @@ -61,7 +61,7 @@ public class FlowClassifierIdTest { | ... | @@ -61,7 +61,7 @@ public class FlowClassifierIdTest { |
61 | @Test | 61 | @Test |
62 | public void testConstruction() { | 62 | public void testConstruction() { |
63 | final String flowClassifierIdValue = "dace4513-24fc-4fae-af4b-321c5e2eb3d1"; | 63 | final String flowClassifierIdValue = "dace4513-24fc-4fae-af4b-321c5e2eb3d1"; |
64 | - final FlowClassifierId flowClassifierId = FlowClassifierId.flowClassifierId(flowClassifierIdValue); | 64 | + final FlowClassifierId flowClassifierId = FlowClassifierId.of(flowClassifierIdValue); |
65 | assertThat(flowClassifierId, is(notNullValue())); | 65 | assertThat(flowClassifierId, is(notNullValue())); |
66 | assertThat(flowClassifierId.value(), is(UUID.fromString(flowClassifierIdValue))); | 66 | assertThat(flowClassifierId.value(), is(UUID.fromString(flowClassifierIdValue))); |
67 | } | 67 | } | ... | ... |
... | @@ -82,11 +82,11 @@ public class FlowClassifierWebResource extends AbstractWebResource { | ... | @@ -82,11 +82,11 @@ public class FlowClassifierWebResource extends AbstractWebResource { |
82 | @Produces(MediaType.APPLICATION_JSON) | 82 | @Produces(MediaType.APPLICATION_JSON) |
83 | public Response getFlowClassifier(@PathParam("flow_id") String id) { | 83 | public Response getFlowClassifier(@PathParam("flow_id") String id) { |
84 | 84 | ||
85 | - if (!service.hasFlowClassifier(FlowClassifierId.flowClassifierId(UUID.fromString(id)))) { | 85 | + if (!service.hasFlowClassifier(FlowClassifierId.of(UUID.fromString(id)))) { |
86 | return Response.status(NOT_FOUND).entity(FLOW_CLASSIFIER_NOT_FOUND).build(); | 86 | return Response.status(NOT_FOUND).entity(FLOW_CLASSIFIER_NOT_FOUND).build(); |
87 | } | 87 | } |
88 | FlowClassifier flowClassifier = nullIsNotFound( | 88 | FlowClassifier flowClassifier = nullIsNotFound( |
89 | - service.getFlowClassifier(FlowClassifierId.flowClassifierId(UUID.fromString(id))), | 89 | + service.getFlowClassifier(FlowClassifierId.of(UUID.fromString(id))), |
90 | FLOW_CLASSIFIER_NOT_FOUND); | 90 | FLOW_CLASSIFIER_NOT_FOUND); |
91 | 91 | ||
92 | ObjectNode result = new ObjectMapper().createObjectNode(); | 92 | ObjectNode result = new ObjectMapper().createObjectNode(); |
... | @@ -182,7 +182,7 @@ public class FlowClassifierWebResource extends AbstractWebResource { | ... | @@ -182,7 +182,7 @@ public class FlowClassifierWebResource extends AbstractWebResource { |
182 | @DELETE | 182 | @DELETE |
183 | public Response deleteFlowClassifier(@PathParam("flow_id") String id) throws IOException { | 183 | public Response deleteFlowClassifier(@PathParam("flow_id") String id) throws IOException { |
184 | try { | 184 | try { |
185 | - FlowClassifierId flowClassifierId = FlowClassifierId.flowClassifierId(UUID.fromString(id)); | 185 | + FlowClassifierId flowClassifierId = FlowClassifierId.of(UUID.fromString(id)); |
186 | service.removeFlowClassifier(flowClassifierId); | 186 | service.removeFlowClassifier(flowClassifierId); |
187 | return Response.status(201).entity("SUCCESS").build(); | 187 | return Response.status(201).entity("SUCCESS").build(); |
188 | } catch (Exception e) { | 188 | } catch (Exception e) { | ... | ... |
... | @@ -62,7 +62,7 @@ public final class FlowClassifierCodec extends JsonCodec<FlowClassifier> { | ... | @@ -62,7 +62,7 @@ public final class FlowClassifierCodec extends JsonCodec<FlowClassifier> { |
62 | 62 | ||
63 | String flowClassifierId = nullIsIllegal(json.get(FLOW_CLASSIFIER_ID), | 63 | String flowClassifierId = nullIsIllegal(json.get(FLOW_CLASSIFIER_ID), |
64 | FLOW_CLASSIFIER_ID + MISSING_MEMBER_MESSAGE).asText(); | 64 | FLOW_CLASSIFIER_ID + MISSING_MEMBER_MESSAGE).asText(); |
65 | - resultBuilder.setFlowClassifierId(FlowClassifierId.flowClassifierId(UUID.fromString(flowClassifierId))); | 65 | + resultBuilder.setFlowClassifierId(FlowClassifierId.of(UUID.fromString(flowClassifierId))); |
66 | 66 | ||
67 | String tenantId = nullIsIllegal(json.get(TENANT_ID), TENANT_ID + MISSING_MEMBER_MESSAGE).asText(); | 67 | String tenantId = nullIsIllegal(json.get(TENANT_ID), TENANT_ID + MISSING_MEMBER_MESSAGE).asText(); |
68 | resultBuilder.setTenantId(TenantId.tenantId(tenantId)); | 68 | resultBuilder.setTenantId(TenantId.tenantId(tenantId)); |
... | @@ -131,4 +131,4 @@ public final class FlowClassifierCodec extends JsonCodec<FlowClassifier> { | ... | @@ -131,4 +131,4 @@ public final class FlowClassifierCodec extends JsonCodec<FlowClassifier> { |
131 | .put("DST_PORT", flowClassifier.dstPort().toString()); | 131 | .put("DST_PORT", flowClassifier.dstPort().toString()); |
132 | return result; | 132 | return result; |
133 | } | 133 | } |
134 | -} | ||
... | \ No newline at end of file | ... | \ No newline at end of file |
134 | +} | ... | ... |
... | @@ -83,7 +83,7 @@ public final class PortChainCodec extends JsonCodec<PortChain> { | ... | @@ -83,7 +83,7 @@ public final class PortChainCodec extends JsonCodec<PortChain> { |
83 | arrayNode = (ArrayNode) json.path(FLOW_CLASSIFIERS); | 83 | arrayNode = (ArrayNode) json.path(FLOW_CLASSIFIERS); |
84 | if (arrayNode != null) { | 84 | if (arrayNode != null) { |
85 | List<FlowClassifierId> list = Lists.newArrayList(); | 85 | List<FlowClassifierId> list = Lists.newArrayList(); |
86 | - arrayNode.forEach(i -> list.add(FlowClassifierId.flowClassifierId(UUID.fromString(i.asText())))); | 86 | + arrayNode.forEach(i -> list.add(FlowClassifierId.of(UUID.fromString(i.asText())))); |
87 | resultBuilder.setFlowClassifiers(list); | 87 | resultBuilder.setFlowClassifiers(list); |
88 | } | 88 | } |
89 | 89 | ... | ... |
-
Please register or login to post a comment