alshabib
Committed by Gerrit Code Review

tying up the apps - when auth is successful connectivity happens

Change-Id: Ic8d60b9421580af9168855d7bc553a0b19a5f0ca
...@@ -17,6 +17,7 @@ package org.onosproject.xosintegration; ...@@ -17,6 +17,7 @@ package org.onosproject.xosintegration;
17 17
18 import com.eclipsesource.json.JsonArray; 18 import com.eclipsesource.json.JsonArray;
19 import com.eclipsesource.json.JsonObject; 19 import com.eclipsesource.json.JsonObject;
20 +import com.google.common.collect.Maps;
20 import com.sun.jersey.api.client.Client; 21 import com.sun.jersey.api.client.Client;
21 import com.sun.jersey.api.client.ClientHandlerException; 22 import com.sun.jersey.api.client.ClientHandlerException;
22 import com.sun.jersey.api.client.ClientResponse; 23 import com.sun.jersey.api.client.ClientResponse;
...@@ -49,15 +50,14 @@ import org.osgi.service.component.ComponentContext; ...@@ -49,15 +50,14 @@ import org.osgi.service.component.ComponentContext;
49 import org.slf4j.Logger; 50 import org.slf4j.Logger;
50 51
51 import java.util.Dictionary; 52 import java.util.Dictionary;
53 +import java.util.Map;
52 import java.util.Set; 54 import java.util.Set;
53 import java.util.stream.Collectors; 55 import java.util.stream.Collectors;
54 import java.util.stream.IntStream; 56 import java.util.stream.IntStream;
55 57
56 import static com.google.common.base.Strings.isNullOrEmpty; 58 import static com.google.common.base.Strings.isNullOrEmpty;
57 import static com.google.common.net.MediaType.JSON_UTF_8; 59 import static com.google.common.net.MediaType.JSON_UTF_8;
58 -import static java.net.HttpURLConnection.HTTP_CREATED; 60 +import static java.net.HttpURLConnection.*;
59 -import static java.net.HttpURLConnection.HTTP_NO_CONTENT;
60 -import static java.net.HttpURLConnection.HTTP_OK;
61 import static org.slf4j.LoggerFactory.getLogger; 61 import static org.slf4j.LoggerFactory.getLogger;
62 62
63 63
...@@ -116,12 +116,16 @@ public class OnosXOSIntegrationManager implements VoltTenantService { ...@@ -116,12 +116,16 @@ public class OnosXOSIntegrationManager implements VoltTenantService {
116 protected int xosProviderService = TEST_XOS_PROVIDER_SERVICE; 116 protected int xosProviderService = TEST_XOS_PROVIDER_SERVICE;
117 117
118 private ApplicationId appId; 118 private ApplicationId appId;
119 + private Map<String, ConnectPoint> nodeToPort;
119 120
120 @Activate 121 @Activate
121 public void activate(ComponentContext context) { 122 public void activate(ComponentContext context) {
122 log.info("XOS app is starting"); 123 log.info("XOS app is starting");
123 cfgService.registerProperties(getClass()); 124 cfgService.registerProperties(getClass());
124 appId = coreService.registerApplication("org.onosproject.xosintegration"); 125 appId = coreService.registerApplication("org.onosproject.xosintegration");
126 +
127 + setupMap();
128 +
125 readComponentConfiguration(context); 129 readComponentConfiguration(context);
126 130
127 log.info("XOS({}) started", appId.id()); 131 log.info("XOS({}) started", appId.id());
...@@ -138,6 +142,16 @@ public class OnosXOSIntegrationManager implements VoltTenantService { ...@@ -138,6 +142,16 @@ public class OnosXOSIntegrationManager implements VoltTenantService {
138 readComponentConfiguration(context); 142 readComponentConfiguration(context);
139 } 143 }
140 144
145 + private void setupMap() {
146 + nodeToPort = Maps.newHashMap();
147 +
148 + nodeToPort.put("cordcompute01.onlab.us", new ConnectPoint(FABRIC_DEVICE_ID,
149 + PortNumber.portNumber(4)));
150 +
151 + nodeToPort.put("cordcompute02.onlab.us", new ConnectPoint(FABRIC_DEVICE_ID,
152 + PortNumber.portNumber(3)));
153 + }
154 +
141 /** 155 /**
142 * Converts a JSON representation of a tenant into a tenant object. 156 * Converts a JSON representation of a tenant into a tenant object.
143 * 157 *
...@@ -237,7 +251,7 @@ public class OnosXOSIntegrationManager implements VoltTenantService { ...@@ -237,7 +251,7 @@ public class OnosXOSIntegrationManager implements VoltTenantService {
237 * @param json JSON string to post 251 * @param json JSON string to post
238 */ 252 */
239 @Deprecated 253 @Deprecated
240 - private void postRest(String json) { 254 + private String postRest(String json) {
241 WebResource.Builder builder = getClientBuilder(); 255 WebResource.Builder builder = getClientBuilder();
242 ClientResponse response; 256 ClientResponse response;
243 257
...@@ -245,13 +259,14 @@ public class OnosXOSIntegrationManager implements VoltTenantService { ...@@ -245,13 +259,14 @@ public class OnosXOSIntegrationManager implements VoltTenantService {
245 response = builder.post(ClientResponse.class, json); 259 response = builder.post(ClientResponse.class, json);
246 } catch (ClientHandlerException e) { 260 } catch (ClientHandlerException e) {
247 log.warn("Unable to contact REST server: {}", e.getMessage()); 261 log.warn("Unable to contact REST server: {}", e.getMessage());
248 - return; 262 + return "{ 'error' : 'oops no one home' }";
249 } 263 }
250 264
251 if (response.getStatus() != HTTP_CREATED) { 265 if (response.getStatus() != HTTP_CREATED) {
252 log.info("REST POST request returned error code {}", 266 log.info("REST POST request returned error code {}",
253 response.getStatus()); 267 response.getStatus());
254 } 268 }
269 + return response.getEntity(String.class);
255 } 270 }
256 271
257 /** 272 /**
...@@ -310,15 +325,27 @@ public class OnosXOSIntegrationManager implements VoltTenantService { ...@@ -310,15 +325,27 @@ public class OnosXOSIntegrationManager implements VoltTenantService {
310 .build(); 325 .build();
311 String json = tenantToJson(tenantToCreate); 326 String json = tenantToJson(tenantToCreate);
312 327
313 - provisionDataPlane(tenantToCreate); 328 + //provisionDataPlane(tenantToCreate);
314 329
315 - postRest(json); 330 + String retJson = postRest(json);
316 331
317 - provisionFabric(VlanId.vlanId(Short.parseShort(newTenant.vlanId()))); 332 + fetchCPELocation(newTenant, retJson);
318 333
319 return newTenant; 334 return newTenant;
320 } 335 }
321 336
337 + private void fetchCPELocation(VoltTenant newTenant, String jsonString) {
338 + JsonObject json = JsonObject.readFrom(jsonString);
339 +
340 + if (json.get("computeNodeName") != null) {
341 + ConnectPoint point = nodeToPort.get(json.get("computeNodeName"));
342 +
343 + provisionFabric(VlanId.vlanId(Short.parseShort(newTenant.vlanId())),
344 + point);
345 + }
346 +
347 + }
348 +
322 @Override 349 @Override
323 public VoltTenant getTenant(long id) { 350 public VoltTenant getTenant(long id) {
324 String jsonString = getRest(Long.toString(id)); 351 String jsonString = getRest(Long.toString(id));
...@@ -375,13 +402,27 @@ public class OnosXOSIntegrationManager implements VoltTenantService { ...@@ -375,13 +402,27 @@ public class OnosXOSIntegrationManager implements VoltTenantService {
375 flowObjectiveService.forward(FABRIC_PORT.deviceId(), forwardToGateway); 402 flowObjectiveService.forward(FABRIC_PORT.deviceId(), forwardToGateway);
376 } 403 }
377 404
378 - private void provisionFabric(VlanId vlanId) { 405 + private void provisionFabric(VlanId vlanId, ConnectPoint point) {
379 - String json = "{\"vlan\":" + vlanId + ",\"ports\":["; 406 + //String json = "{\"vlan\":" + vlanId + ",\"ports\":[";
380 - json += "{\"device\":\"" + FABRIC_DEVICE_ID.toString() + "\",\"port\":\"" 407 + //json += "{\"device\":\"" + FABRIC_DEVICE_ID.toString() + "\",\"port\":\""
381 - + FABRIC_OLT_CONNECT_POINT.toString() + "\"},"; 408 + // + FABRIC_OLT_CONNECT_POINT.toString() + "\"},";
382 - json += "{\"device\":\"" + FABRIC_DEVICE_ID.toString() + "\",\"port\":\"" 409 + //json += "{\"device\":\"" + FABRIC_DEVICE_ID.toString() + "\",\"port\":\""
383 - + FABRIC_VCPE_CONNECT_POINT.toString() + "\"}"; 410 + // + FABRIC_VCPE_CONNECT_POINT.toString() + "\"}";
384 - json += "]}"; 411 + //json += "]}";
412 +
413 + JsonObject node = new JsonObject();
414 + node.add("vlan", vlanId.toShort());
415 + JsonArray array = new JsonArray();
416 + JsonObject cp1 = new JsonObject();
417 + JsonObject cp2 = new JsonObject();
418 + cp1.add("device", point.deviceId().toString());
419 + cp1.add("port", point.port().toLong());
420 + cp2.add("device", FABRIC_DEVICE_ID.toString());
421 + cp2.add("port", FABRIC_OLT_CONNECT_POINT.toString());
422 + array.add(cp1);
423 + array.add(cp2);
424 + node.add("ports", array);
425 +
385 426
386 String baseUrl = "http://" + FABRIC_CONTROLLER_ADDRESS + ":" 427 String baseUrl = "http://" + FABRIC_CONTROLLER_ADDRESS + ":"
387 + Integer.toString(FABRIC_SERVER_PORT); 428 + Integer.toString(FABRIC_SERVER_PORT);
...@@ -391,7 +432,7 @@ public class OnosXOSIntegrationManager implements VoltTenantService { ...@@ -391,7 +432,7 @@ public class OnosXOSIntegrationManager implements VoltTenantService {
391 .type(JSON_UTF_8.toString()); 432 .type(JSON_UTF_8.toString());
392 433
393 try { 434 try {
394 - builder.post(ClientResponse.class, json); 435 + builder.post(ClientResponse.class, node);
395 } catch (ClientHandlerException e) { 436 } catch (ClientHandlerException e) {
396 log.warn("Unable to contact fabric REST server:", e.getMessage()); 437 log.warn("Unable to contact fabric REST server:", e.getMessage());
397 return; 438 return;
......