Ray Milkey
Committed by Gerrit Code Review

Improvements for XOS integration app

- Add a default value for the tenant provider service
  id and don't require callers to set it when creating
  a tenant.
- Add javadocs to the volt tenant object.

Change-Id: I1144820eb3e311cffc87ecefaccf689127730dcf
...@@ -56,24 +56,39 @@ import static org.slf4j.LoggerFactory.getLogger; ...@@ -56,24 +56,39 @@ import static org.slf4j.LoggerFactory.getLogger;
56 @Component(immediate = true) 56 @Component(immediate = true)
57 @Service 57 @Service
58 public class OnosXOSIntegrationManager implements VoltTenantService { 58 public class OnosXOSIntegrationManager implements VoltTenantService {
59 + private static final String XOS_SERVER_ADDRESS_PROPERTY_NAME =
60 + "xosServerAddress";
61 + private static final String XOS_SERVER_PORT_PROPERTY_NAME =
62 + "xosServerPort";
63 + private static final String XOS_PROVIDER_SERVICE_PROPERTY_NAME =
64 + "xosProviderService";
59 65
60 private static final String TEST_XOS_SERVER_ADDRESS = "10.254.1.22"; 66 private static final String TEST_XOS_SERVER_ADDRESS = "10.254.1.22";
61 private static final int TEST_XOS_SERVER_PORT = 8000; 67 private static final int TEST_XOS_SERVER_PORT = 8000;
62 private static final String XOS_TENANT_BASE_URI = "/xoslib/volttenant/"; 68 private static final String XOS_TENANT_BASE_URI = "/xoslib/volttenant/";
69 + private static final int TEST_XOS_PROVIDER_SERVICE = 1;
63 70
64 private final Logger log = getLogger(getClass()); 71 private final Logger log = getLogger(getClass());
65 @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) 72 @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
66 protected CoreService coreService; 73 protected CoreService coreService;
67 @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) 74 @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
68 protected ComponentConfigService cfgService; 75 protected ComponentConfigService cfgService;
69 - @Property(name = "XOSServerAddress", 76 +
77 + @Property(name = XOS_SERVER_ADDRESS_PROPERTY_NAME,
70 value = TEST_XOS_SERVER_ADDRESS, 78 value = TEST_XOS_SERVER_ADDRESS,
71 label = "XOS Server address") 79 label = "XOS Server address")
72 protected String xosServerAddress = TEST_XOS_SERVER_ADDRESS; 80 protected String xosServerAddress = TEST_XOS_SERVER_ADDRESS;
73 - @Property(name = "XOSServerPort", 81 +
82 + @Property(name = XOS_SERVER_PORT_PROPERTY_NAME,
74 intValue = TEST_XOS_SERVER_PORT, 83 intValue = TEST_XOS_SERVER_PORT,
75 label = "XOS Server port") 84 label = "XOS Server port")
76 protected int xosServerPort = TEST_XOS_SERVER_PORT; 85 protected int xosServerPort = TEST_XOS_SERVER_PORT;
86 +
87 + @Property(name = XOS_PROVIDER_SERVICE_PROPERTY_NAME,
88 + intValue = TEST_XOS_PROVIDER_SERVICE,
89 + label = "XOS Provider Service")
90 + protected int xosProviderService = TEST_XOS_PROVIDER_SERVICE;
91 +
77 private ApplicationId appId; 92 private ApplicationId appId;
78 93
79 @Activate 94 @Activate
...@@ -244,7 +259,16 @@ public class OnosXOSIntegrationManager implements VoltTenantService { ...@@ -244,7 +259,16 @@ public class OnosXOSIntegrationManager implements VoltTenantService {
244 259
245 @Override 260 @Override
246 public VoltTenant addTenant(VoltTenant newTenant) { 261 public VoltTenant addTenant(VoltTenant newTenant) {
247 - String json = tenantToJson(newTenant); 262 + long providerServiceId = newTenant.providerService();
263 + if (providerServiceId == -1) {
264 + providerServiceId = xosProviderService;
265 + }
266 + VoltTenant tenantToCreate = VoltTenant.builder()
267 + .withProviderService(providerServiceId)
268 + .withServiceSpecificId(newTenant.serviceSpecificId())
269 + .withVlanId(newTenant.vlanId())
270 + .build();
271 + String json = tenantToJson(tenantToCreate);
248 postRest(json); 272 postRest(json);
249 return newTenant; 273 return newTenant;
250 } 274 }
...@@ -268,16 +292,23 @@ public class OnosXOSIntegrationManager implements VoltTenantService { ...@@ -268,16 +292,23 @@ public class OnosXOSIntegrationManager implements VoltTenantService {
268 private void readComponentConfiguration(ComponentContext context) { 292 private void readComponentConfiguration(ComponentContext context) {
269 Dictionary<?, ?> properties = context.getProperties(); 293 Dictionary<?, ?> properties = context.getProperties();
270 294
271 - String newXosServerAddress = Tools.get(properties, "XOSServerAddress"); 295 + String newXosServerAddress =
296 + Tools.get(properties, XOS_SERVER_ADDRESS_PROPERTY_NAME);
272 if (!isNullOrEmpty(newXosServerAddress)) { 297 if (!isNullOrEmpty(newXosServerAddress)) {
273 xosServerAddress = newXosServerAddress; 298 xosServerAddress = newXosServerAddress;
274 } 299 }
275 300
276 - String newXosServerPortString = Tools.get(properties, "XOSServerPort"); 301 + String newXosServerPortString =
302 + Tools.get(properties, XOS_SERVER_PORT_PROPERTY_NAME);
277 if (!isNullOrEmpty(newXosServerPortString)) { 303 if (!isNullOrEmpty(newXosServerPortString)) {
278 xosServerPort = Integer.parseInt(newXosServerPortString); 304 xosServerPort = Integer.parseInt(newXosServerPortString);
279 } 305 }
280 - log.info("XOS URL is now http://{}:{}", xosServerAddress, xosServerPort); 306 +
307 + String newXosProviderServiceString =
308 + Tools.get(properties, XOS_PROVIDER_SERVICE_PROPERTY_NAME);
309 + if (!isNullOrEmpty(newXosProviderServiceString)) {
310 + xosProviderService = Integer.parseInt(newXosProviderServiceString);
311 + }
281 } 312 }
282 } 313 }
283 314
......
...@@ -15,7 +15,6 @@ ...@@ -15,7 +15,6 @@
15 */ 15 */
16 package org.onosproject.xosintegration; 16 package org.onosproject.xosintegration;
17 17
18 -
19 import com.google.common.base.MoreObjects; 18 import com.google.common.base.MoreObjects;
20 19
21 public final class VoltTenant { 20 public final class VoltTenant {
...@@ -26,6 +25,15 @@ public final class VoltTenant { ...@@ -26,6 +25,15 @@ public final class VoltTenant {
26 private final String serviceSpecificId; 25 private final String serviceSpecificId;
27 private final String vlanId; 26 private final String vlanId;
28 27
28 + /**
29 + * Constructs a vOLT tenant object.
30 + *
31 + * @param humanReadableName name string
32 + * @param id identifier for the tenant
33 + * @param providerService provider service ID
34 + * @param serviceSpecificId id for the user
35 + * @param vlanId vlan id for the user
36 + */
29 private VoltTenant(String humanReadableName, long id, long providerService, 37 private VoltTenant(String humanReadableName, long id, long providerService,
30 String serviceSpecificId, String vlanId) { 38 String serviceSpecificId, String vlanId) {
31 this.humanReadableName = humanReadableName; 39 this.humanReadableName = humanReadableName;
...@@ -35,62 +43,131 @@ public final class VoltTenant { ...@@ -35,62 +43,131 @@ public final class VoltTenant {
35 this.vlanId = vlanId; 43 this.vlanId = vlanId;
36 } 44 }
37 45
46 + /**
47 + * Fetches a builder to make a tenant.
48 + *
49 + * @return tenant builder
50 + */
38 public static Builder builder() { 51 public static Builder builder() {
39 return new Builder(); 52 return new Builder();
40 } 53 }
41 54
55 + /**
56 + * Fetches the name of the tenant.
57 + *
58 + * @return human readable name
59 + */
42 public String humanReadableName() { 60 public String humanReadableName() {
43 return humanReadableName; 61 return humanReadableName;
44 } 62 }
45 63
64 + /**
65 + * Fetches the ID of the tenant object.
66 + *
67 + * @return ID of tenant object.
68 + */
46 public long id() { 69 public long id() {
47 return id; 70 return id;
48 } 71 }
49 72
73 + /**
74 + * Fetches the identifier for the provider service.
75 + *
76 + * @return provider service ID
77 + */
50 public long providerService() { 78 public long providerService() {
51 return providerService; 79 return providerService;
52 } 80 }
53 81
82 + /**
83 + * Fetches the server specific ID (user id).
84 + *
85 + * @return server specific ID
86 + */
54 public String serviceSpecificId() { 87 public String serviceSpecificId() {
55 return serviceSpecificId; 88 return serviceSpecificId;
56 } 89 }
57 90
91 + /**
92 + * Fetches the vlan id for this tenant.
93 + *
94 + * @return VLAN ID
95 + */
58 public String vlanId() { 96 public String vlanId() {
59 return vlanId; 97 return vlanId;
60 } 98 }
61 99
100 + /**
101 + * Builder class to allow callers to assemble tenants.
102 + */
103 +
62 public static final class Builder { 104 public static final class Builder {
63 private String humanReadableName = "unknown"; 105 private String humanReadableName = "unknown";
64 private long id = 0; 106 private long id = 0;
65 - private long providerService = 0; 107 + private long providerService = -1;
66 private String serviceSpecificId = "unknown"; 108 private String serviceSpecificId = "unknown";
67 private String vlanId = "unknown"; 109 private String vlanId = "unknown";
68 110
111 + /**
112 + * Sets the name string for the tenant.
113 + *
114 + * @param humanReadableName name
115 + * @return self
116 + */
69 public Builder withHumanReadableName(String humanReadableName) { 117 public Builder withHumanReadableName(String humanReadableName) {
70 this.humanReadableName = humanReadableName; 118 this.humanReadableName = humanReadableName;
71 return this; 119 return this;
72 } 120 }
73 121
122 + /**
123 + * Sets the identifier for the tenant.
124 + *
125 + * @param id identifier for the tenant
126 + * @return self
127 + */
74 public Builder withId(long id) { 128 public Builder withId(long id) {
75 this.id = id; 129 this.id = id;
76 return this; 130 return this;
77 } 131 }
78 132
79 - public Builder withProviderService(long providerService) { 133 + /**
80 - this.providerService = providerService; 134 + * Sets the server specific id (user id) for the tenant.
81 - return this; 135 + *
82 - } 136 + * @param serviceSpecificId server specific (user) id
83 - 137 + * @return self
138 + */
84 public Builder withServiceSpecificId(String serviceSpecificId) { 139 public Builder withServiceSpecificId(String serviceSpecificId) {
85 this.serviceSpecificId = serviceSpecificId; 140 this.serviceSpecificId = serviceSpecificId;
86 return this; 141 return this;
87 } 142 }
88 143
144 + /**
145 + * Sets the VLAN ID for the tenant.
146 + *
147 + * @param vlanId VLAN ID
148 + * @return self
149 + */
89 public Builder withVlanId(String vlanId) { 150 public Builder withVlanId(String vlanId) {
90 this.vlanId = vlanId; 151 this.vlanId = vlanId;
91 return this; 152 return this;
92 } 153 }
93 154
155 + /**
156 + * Sets the provider service ID.
157 + *
158 + * @param providerService provider service ID
159 + * @return self
160 + */
161 + public Builder withProviderService(long providerService) {
162 + this.providerService = providerService;
163 + return this;
164 + }
165 +
166 + /**
167 + * Constructs a VoltTenant from the assembled data.
168 + *
169 + * @return constructed tenant object
170 + */
94 public VoltTenant build() { 171 public VoltTenant build() {
95 return new VoltTenant(humanReadableName, id, providerService, 172 return new VoltTenant(humanReadableName, id, providerService,
96 serviceSpecificId, vlanId); 173 serviceSpecificId, vlanId);
......
...@@ -27,17 +27,13 @@ import org.onosproject.xosintegration.VoltTenantService; ...@@ -27,17 +27,13 @@ import org.onosproject.xosintegration.VoltTenantService;
27 @Command(scope = "onos", name = "add-tenant", 27 @Command(scope = "onos", name = "add-tenant",
28 description = "Lists the inventory of VOLT tenants and their contents") 28 description = "Lists the inventory of VOLT tenants and their contents")
29 public class VoltTenantsCreateCommand extends AbstractShellCommand { 29 public class VoltTenantsCreateCommand extends AbstractShellCommand {
30 - @Argument(index = 0, name = "provider service",
31 - description = "Tenant ID",
32 - required = true, multiValued = false)
33 - long providerService;
34 30
35 - @Argument(index = 1, name = "service specific ID", 31 + @Argument(index = 0, name = "service specific ID",
36 description = "service specific ID", 32 description = "service specific ID",
37 required = true, multiValued = false) 33 required = true, multiValued = false)
38 String serviceSpecificId; 34 String serviceSpecificId;
39 35
40 - @Argument(index = 2, name = "vlan ID", 36 + @Argument(index = 1, name = "vlan ID",
41 description = "vlan ID", 37 description = "vlan ID",
42 required = true, multiValued = false) 38 required = true, multiValued = false)
43 String vlanId; 39 String vlanId;
...@@ -47,7 +43,6 @@ public class VoltTenantsCreateCommand extends AbstractShellCommand { ...@@ -47,7 +43,6 @@ public class VoltTenantsCreateCommand extends AbstractShellCommand {
47 VoltTenantService service = get(VoltTenantService.class); 43 VoltTenantService service = get(VoltTenantService.class);
48 44
49 VoltTenant newTenant = VoltTenant.builder() 45 VoltTenant newTenant = VoltTenant.builder()
50 - .withProviderService(providerService)
51 .withServiceSpecificId(serviceSpecificId) 46 .withServiceSpecificId(serviceSpecificId)
52 .withVlanId(vlanId) 47 .withVlanId(vlanId)
53 .build(); 48 .build();
......