networkstatic

Set-Controller

Nov 5th, 2013
103
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 3.67 KB | None | 0 0
  1.     public Boolean setBridgeOFController(Node node, String bridgeIdentifier, Map<ConfigConstants, Object> configs) {
  2.  
  3.         try{
  4.             if (connectionService == null) {
  5.                 logger.error("Couldn't refer to the ConnectionService");
  6.                 return false;
  7.             }
  8.             Connection connection = this.getConnection(node);
  9.             if (connection == null) {
  10.                 return false;
  11.             }
  12.  
  13.             if (connection != null) {
  14.  
  15.                 List<InetAddress> ofControlAddr = getControllerIPAddresses();
  16.                 short ofControlPort = getControllerOFPort();
  17.  
  18.                 InetAddress addr = InetAddress.getLocalHost();
  19.                 String newController = "new_controller";
  20.                 Controller controllerRow = new Controller();
  21.                 controllerRow.setTarget("tcp:6633:192.168.254.128");
  22.                 InsertOperation addCtlRequest = new InsertOperation(Controller.NAME.getName(), newController, controllerRow);
  23.  
  24.                 String brCntrlUuid = null;
  25.                 Map<String, Table<?>> brTableCache = inventoryServiceInternal.getTableCache(node, Bridge.NAME.getName());
  26.                 for (String uuid : brTableCache.keySet()) {
  27.                     Bridge bridge = (Bridge)brTableCache.get(uuid);
  28.                     if (bridge.getName().contains(bridgeIdentifier)) {
  29.                         brCntrlUuid = uuid;
  30.                     }
  31.                 }
  32.  
  33.                 Operation addControlRequest = null;
  34.                 UUID controlUuidPair = new UUID(newController);
  35.                 System.out.println("WTF "+ controlUuidPair);
  36.                 Mutation bm = new Mutation("controller", Mutator.INSERT, controlUuidPair);
  37.                 List<Mutation> mutations = new ArrayList<Mutation>();
  38.                 mutations.add(bm);
  39.  
  40.                 UUID uuid = new UUID(brCntrlUuid);
  41.                 Condition condition = new Condition("_uuid", Function.EQUALS, uuid);
  42.                 List<Condition> where = new ArrayList<Condition>();
  43.                 where.add(condition);
  44.                 addControlRequest = new MutateOperation(Bridge.NAME.getName(), where, mutations);
  45.  
  46.                 TransactBuilder transaction = new TransactBuilder();
  47.                 transaction.addOperations(new ArrayList<Operation>(Arrays.asList(addCtlRequest, addControlRequest)));
  48.  
  49.                 ListenableFuture<List<OperationResult>> transResponse = connection.getRpc().transact(transaction);
  50.                 List<OperationResult> tr = transResponse.get();
  51.                 List<Operation> requests = transaction.getRequests();
  52.                 Status status = new Status(StatusCode.SUCCESS);
  53.                 for (int i = 0; i < tr.size() ; i++) {
  54.                     if (i < requests.size()) requests.get(i).setResult(tr.get(i));
  55.                     if (tr.get(i).getError() != null && tr.get(i).getError().trim().length() > 0) {
  56.                         OperationResult result = tr.get(i);
  57.                         status = new Status(StatusCode.BADREQUEST, result.getError() + " : " + result.getDetails());
  58.                     }
  59.                 }
  60.  
  61.                 if (tr.size() > requests.size()) {
  62.                     OperationResult result = tr.get(tr.size()-1);
  63.                     logger.error("Error creating Bridge : {}\n Error : {}\n Details : {}", bridgeIdentifier,
  64.                             result.getError(),
  65.                             result.getDetails());
  66.                     status = new Status(StatusCode.BADREQUEST, result.getError() + " : " + result.getDetails());
  67.  
  68.                 }
  69.             }
  70.         }catch(Exception e){
  71.             e.printStackTrace();
  72.         }
  73.         return true;
  74.     }
Advertisement
Add Comment
Please, Sign In to add comment