예제 #1
0
  public ServerInfo convert(@SuppressWarnings("rawtypes") final Class type, final Object value) {
    // get the main config.
    final NeoGlobalConfig.DescriptorImpl globalConfigDescriptor =
        (NeoGlobalConfig.DescriptorImpl) Jenkins.getInstance().getDescriptor(NeoGlobalConfig.class);

    if (globalConfigDescriptor == null) {
      LOGGER.log(
          Level.FINEST,
          "No NeoLoad server settings found. Please add servers before configuring jobs. (getLicenseServerOptions)");
      return null;
    }

    // find the serverInfo based on the unique ID.
    @SuppressWarnings("unchecked")
    final Collection<ServerInfo> allServerInfo =
        CollectionUtils.union(
            globalConfigDescriptor.getNtsInfo(), globalConfigDescriptor.getCollabInfo());
    for (final ServerInfo si : allServerInfo) {
      if (si.getUniqueID().equals(value)) {
        return si;
      }
    }

    return null;
  }
예제 #2
0
  // THIS BLOCK CONTAINS JAVA CODE.
  private long removeRefServerInfo(long lIndex) {
    //
    // loop through the elements in the actual container, in order to find the one
    // at lIndex. Once it is found, then loop through the reference list and remove
    // the corresponding reference for that element.
    //
    ServerInfo refActualElement = GetServerInfo(lIndex);

    if (refActualElement == null) return lIndex; // oh well.

    // Loop through the reference list and remove the corresponding reference
    // for the specified element.
    //
    for (int intIndex = 0; intIndex < elementList.size(); intIndex++) {
      Object theObject = elementList.get(intIndex);

      if ((theObject == null) || !(theObject instanceof ServerInfo)) continue;

      ServerInfo tempRef = (ServerInfo) (theObject);

      if ((ServerInfo.getCPtr(tempRef) == ServerInfo.getCPtr(refActualElement))) {
        elementList.remove(tempRef);
        break;
      }
    }

    return lIndex;
  }
예제 #3
0
  /** Monitoring logic used by background thread */
  public void run() {
    try {
      boolean cleanRemoteSessions = false;
      synchronized (servers) {
        for (Map.Entry<String, ServerInfo> server : servers.entrySet()) {
          ServerInfo info = server.getValue();
          info.isUp = checkServerUp(info);

          if (!info.isUp) {
            downServers.add(info.id);
          } else {
            if (!downServers.isEmpty() && downServers.remove(info.id)) {
              cleanRemoteSessions = true;
            }
          }
        }
      }
      if (cleanRemoteSessions) {
        sessionService.cleanUpRemoteSessions();
      }
    } catch (Exception ex) {
      sessionDebug.error(
          "cleanRemoteSessions Background thread has encountered an Exception: " + ex.getMessage(),
          ex);
    }
  }
 public void connenctToServer(ServerInfo info) {
   Log.d(TAG, "connenctToServer");
   if (info.getServerType().equals("wifi-direct")) {
     if (mDirectService != null) mDirectService.connectToServer(info);
   } else if (info.getServerType().equals("wifi") || info.getServerType().equals("wifi-ap")) {
     if (mWifiOrAPService != null) mWifiOrAPService.connectToServer(info);
   }
 }
예제 #5
0
  /** Use Logical Name */
  public ServerInfo getServerInfoByName(String name) {
    String ids[] = this.getServerIDs();
    for (String id : ids) {
      ServerInfo info = this.serverInfos.get(id);
      if (StringUtil.equals(info.getName(), name)) return info.duplicate();
    }

    return null;
  }
예제 #6
0
  /** Use infoID to get the ServerInformation */
  public ServerInfo getServerInfo(String infoID) {
    if (infoID == null) return null;

    // logger.messagePrintln(ServerInfo.class,"searching for:"+accountID);
    ServerInfo info = serverInfos.get(infoID);
    // keep stored copied private !
    if (info != null) return info.duplicate();

    return null;
  }
예제 #7
0
  /**
   * @return <code>true</code> if the given request sender identity is the bootstrap server (same IP
   *     address)
   */
  public synchronized boolean isBootstrapServer(Identity identity) {
    if (bootstrapServerInfo == null) {
      return false;
    }

    return bootstrapServerInfo.getAddress().getAddress() != null
        && bootstrapServerInfo
            .getAddress()
            .getAddress()
            .equals(identity.getPeerAddress().getAddress());
  }
예제 #8
0
 /**
  * Override toString
  *
  * @return
  */
 @Override
 public String toString() {
   final StringBuffer sb = new StringBuffer();
   sb.append("ClusterStateService: ");
   sb.append("{ lastSelected=").append(lastSelected);
   sb.append(", timeout=").append(timeout).append("\n");
   sb.append(" Current Server Selection List:").append("\n");
   for (ServerInfo serverInfo : getServerSelectionList()) {
     sb.append(serverInfo.toString());
   }
   sb.append('}');
   return sb.toString();
 }
예제 #9
0
  /** Return ServerInfo as Vector of VAttributeSets */
  public ArrayList<AttributeSet> getInfoAttrSets() {
    // synchronize !
    synchronized (this.serverInfos) {
      Set<String> keys = this.serverInfos.keySet();
      ArrayList<AttributeSet> sets = new ArrayList<AttributeSet>(keys.size());

      for (String key : keys) {
        ServerInfo info = serverInfos.get(key);
        sets.add(info.getAttributeSet());
      }

      return sets;
    }
  }
예제 #10
0
 /**
  * Actively checks and updates the status of the server instance identified by serverId
  *
  * @param serverId server instance id
  * @return true if server is up, false otherwise
  */
 boolean checkServerUp(String serverId) {
   if ((serverId == null) || (serverId.isEmpty())) {
     return false;
   }
   if (serverId.equalsIgnoreCase(this.localServerId)) {
     return true;
   }
   if ((servers == null) || servers.isEmpty()) {
     return false;
   }
   ServerInfo info = servers.get(serverId);
   info.isUp = checkServerUp(info);
   return info.isUp;
 }
예제 #11
0
  private void stopAllInner() throws Exception {

    for (ServerInfo server : servers) {
      Socket s = new Socket(server.getHost(), server.getTerminationPort());
      s.getOutputStream();
      s.getInputStream();

      // If the MiniServer is remote, terminate the local SSH window for it too
      if (server.getHost().equals("localhost") == false) {
        s = new Socket("localhost", server.getTerminationPort());
        s.getOutputStream();
        s.getInputStream();
      }
    }

    Runtime.getRuntime().halt(0);
  }
예제 #12
0
 private void GetScreenValues() {
   serverInfo.setServerIP(serverIP.getText().toString());
   serverInfo.setPlayerPort(playerPort.getText().toString());
   serverInfo.setCliPort(cliPort.getText().toString());
   serverInfo.setWebPort(webPort.getText().toString());
   serverInfo.setPlayerName(playerName.getText().toString());
   serverInfo.setUSERNAME(userName.getText().toString());
   serverInfo.setPASSWORD(passWord.getText().toString());
 }
예제 #13
0
 private void SetScreenValues() {
   serverIP.setText(serverInfo.getServerIP());
   playerPort.setText(serverInfo.getPlayerPort());
   cliPort.setText(serverInfo.getCliPort());
   webPort.setText(serverInfo.getWebPort());
   playerName.setText(serverInfo.getPlayerName());
   userName.setText(serverInfo.getUSERNAME());
   passWord.setText(serverInfo.getPASSWORD());
 }
예제 #14
0
  /** Stored new ServerInfo and writes to file (if persistant) Returnes updated serverInfo */
  public ServerInfo store(ServerInfo info) {
    logger.debugPrintf("store(): attrs=%s\n", info.getAttributeSet());

    synchronized (this.serverInfos) {
      // ===
      // Before adding new Info: check whether persistant database is
      // loaded !
      // ===
      checkIsLoaded();
      // remove before put!
      remove(info);
      // synchronized put: UPDATES SERVERINFO KEY!
      put(info);
      // enters mutex again
      save();

      // do NOT return reference to object into ServerRegistry
      return info.duplicate();
    }
  }
예제 #15
0
  /**
   * Constructs an instance for the cluster service
   *
   * @param localServerId id of the server instance in which this ClusterStateService instance is
   *     running
   * @param timeout timeout for waiting on an individual server (millisec)
   * @param period checking cycle period (millisecs)
   * @param members map if server id - > url for all cluster members
   * @throws Exception
   */
  protected ClusterStateService(
      SessionService sessionService,
      String localServerId,
      int timeout,
      long period,
      Map<String, String> members)
      throws Exception {
    if ((localServerId == null) || (localServerId.isEmpty())) {
      String message =
          "ClusterStateService: Local Server Id argument is null, unable to instantiate Cluster State Service!";
      sessionDebug.error(message);
      throw new IllegalArgumentException(message);
    }
    // Ensure we Synchronize this Instantiation.
    synchronized (this) {
      this.sessionService = sessionService;
      this.localServerId = localServerId;
      this.timeout = timeout;
      this.period = period;
      serverSelectionList = new ServerInfo[members.size()];

      for (Map.Entry<String, String> entry : members.entrySet()) {
        ServerInfo info = new ServerInfo();
        info.id = entry.getKey();
        URL url = new URL(entry.getValue() + "/namingservice");
        info.url = url;
        info.protocol = url.getProtocol();
        info.address = new InetSocketAddress(url.getHost(), url.getPort());
        // Fix for Deadlock. If this is our server, set to true, else false.
        info.isUp = isLocalServerId(info.id);
        info.isLocal = info.isUp; // Set our Local Server Indicator, per above interrogation.

        // Check for Down Servers.
        if (!info.isUp) {
          downServers.add(info.id);
        }

        // Add Server to Server List.
        servers.put(info.id, info);
        // Associate to a Server Selection Bucket.
        serverSelectionList[getNextSelected()] = info;
        if (sessionDebug.messageEnabled()) {
          sessionDebug.error("Added Server to ClusterStateService: " + info.toString());
        }
      } // End of For Loop.

      // to ensure that ordering in different server instances is identical
      Arrays.sort(serverSelectionList);
      SystemTimer.getTimer().schedule(this, new Date((System.currentTimeMillis() / 1000) * 1000));
    } // End of Synchronized Block.
  }
예제 #16
0
  /** Put ServerInfo into registry */
  private void put(ServerInfo info) {
    synchronized (serverInfos) {
      // store private copy !
      info = info.duplicate();

      updateServerInfoID(info);

      logger.debugPrintf("+++ Storing info:%s\n", info);

      ServerInfo prev = this.serverInfos.get(info.getID());

      if (prev == info) logger.infoPrintf(">>> updating ServerInfo:%s\n", info);
      else if (prev != null)
        logger.infoPrintf(">>> WARNING: Overwriting previous object with:%s\n", info);
      else logger.infoPrintf(">>> storing new ServerInfo:%s\n", info);

      this.serverInfos.put(info.getID(), info);
      // mark dirty:
      this.isSaved = false;
    }
  }
예제 #17
0
  private long getCPtrAddRefServerInfo(ServerInfo element) {
    // Whenever adding a reference to the list, I remove it first (if already there.)
    // That way we never store more than one reference per actual contained object.
    //
    for (int intIndex = 0; intIndex < elementList.size(); intIndex++) {
      Object theObject = elementList.get(intIndex);

      if ((theObject == null) || !(theObject instanceof ServerInfo)) continue;

      ServerInfo tempRef = (ServerInfo) (theObject);

      if ((ServerInfo.getCPtr(tempRef) == ServerInfo.getCPtr(element))) {
        elementList.remove(
            tempRef); // It was already there, so let's remove it before adding (below.)
        break;
      }
    }
    // Now we add it...
    //
    ServerInfo tempLocalRef = element;
    elementList.add(tempLocalRef);
    return ServerInfo.getCPtr(element);
  } // Hope I get away with overloading this for every type. Otherwise,
예제 #18
0
  public ServerInfo remove(ServerInfo info) {
    if (info == null) return null;

    logger.infoPrintf("--- Removing ServerInfo:%s\n", info);

    ServerInfo prev = null;

    synchronized (this.serverInfos) {
      String key = info.getID(); // return NULL if key hasn't been
      // set/info hasn't been stored !
      if (key != null) prev = this.getServerInfo(key);
      removeByKey(key);
      return prev;
    }
  }
예제 #19
0
  /**
   * Main method to search for a Server Info object. When a search field is null it means "don't
   * care". Use port number less then 0 for a don't care. Use port number EQUAL to 0 for default
   * port ! Returns multiple matching ServerInfo descriptions or NULL when it can't find any
   * matching server descriptions.
   *
   * @param scheme if NULL then don't care (match any)
   * @param hostname if NULL then don't care (match any)
   * @param port if port==-1 => don't care, if port==0 => default and if port>0 match explicit port
   *     number
   * @param userInfo if NULL then don't care (match any)
   */
  public ServerInfo[] getServerInfos(String scheme, String host, int port, String optUserInfo) {

    logger.debugPrintf(
        ">>> find {scheme,host,port,user}=%s,%s,%s,%s\n", scheme, host, port, optUserInfo);
    // if (scheme.compareTo("srb")==0)
    // {
    // logger.debugPrintln(this,"SRB"); // breakpoint
    // }
    ServerInfo infoArr[] = new ServerInfo[serverInfos.size()];
    infoArr = this.serverInfos.values().toArray(infoArr);

    Vector<ServerInfo> result = new Vector<ServerInfo>();

    for (ServerInfo info : infoArr) {
      logger.debugPrintf(" - comparing:%s", info);

      if (info.matches(scheme, host, port, optUserInfo)) {
        logger.debugPrintf(" - adding:%s\n", info);
        // =========================
        // Add Duplicate !
        // ==========================
        result.add(info.duplicate());
      }
    }

    if (result.size() <= 0) {
      logger.debugPrintf("<<< Returning NULL ServerInfos\n");
      return null;
    }

    ServerInfo arr[] = new ServerInfo[result.size()];
    arr = result.toArray(arr);
    logger.debugPrintf("<<< Returning #%d ServerInfos\n", arr.length);

    return arr;
  }
  @Override
  public View onCreateView(
      LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {

    serverInfo = (ServerInfo) getArguments().getSerializable(AccountSettings.KEY_SERVER_INFO);

    View v = inflater.inflate(R.layout.account_details, container, false);

    editAccountName = (EditText) v.findViewById(R.id.account_name);
    editAccountName.setText(serverInfo.getAccountName());
    editAccountName.addTextChangedListener(this);

    setHasOptionsMenu(true);
    return v;
  }
예제 #21
0
  /** Returns <SCHEME-#Key> server ID */
  protected String createUniqueID(ServerInfo info) {
    String scheme = info.getScheme();

    synchronized (this.serverInfos) {
      for (int i = 0; i < 1000; i++) {
        String key = scheme.toUpperCase() + "-" + i;
        if (this.serverInfos.get(key) == null) {
          // debug(">>> New Server ID="+key);
          return key;
        }
      }
    }

    throw new Error("To much server configurations.");
  }
예제 #22
0
  /** Update Actual ServerInfo ID */
  protected void updateServerInfoID(ServerInfo info) {
    synchronized (this.serverInfos) {
      // Check whether muliple user IDs are allowed!
      String userInf = "";

      if (info.getNeedUserinfo() || (StringUtil.isWhiteSpace(info.getUserinfo()) == false)) {
        // use explicit userinfo
        userInf = info.getUserinfo() + "@";
      }

      // Normalize capitals.

      String fixedID =
          userInf
              + info.getScheme().toUpperCase()
              + "-"
              + StringUtil.noNull(info.getHostname()).toUpperCase()
              + ":"
              + info.getPort();
      info.setID(fixedID);
    }
  }
예제 #23
0
  /**
   * Exercises as many fields of the monitoring stats classes as possible. So that we can check that
   * they are being populated.
   */
  public void testMe() throws SQLException {
    String queryString =
        "WITH MEMBER [Measures].[Foo] AS\n"
            + " [Measures].[Unit Sales]"
            + " + case when [Measures].[Unit Sales] > 0\n"
            + "   then CInt( ([Measures].[Foo], [Time].PrevMember) )\n"
            + "   end\n"
            + "SELECT [Measures].[Foo] on 0\n"
            + "from [Sales]\n"
            + "where [Time].[1997].[Q3].[9]";

    final OlapStatement statement1 = getTestContext().getOlap4jConnection().createStatement();
    CellSet cellSet = statement1.executeOlapQuery(queryString);
    StringWriter stringWriter = new StringWriter();
    new RectangularCellSetFormatter(true).format(cellSet, new PrintWriter(stringWriter));
    statement1.close();
    println(stringWriter);

    final MondrianServer mondrianServer = MondrianServer.forConnection(getConnection());
    final Monitor monitor = mondrianServer.getMonitor();
    final ServerInfo server = monitor.getServer();

    println("# stmts open: " + server.statementCurrentlyOpenCount());

    println("# connections open: " + server.connectionCurrentlyOpenCount());

    println("# rows fetched: " + server.sqlStatementRowFetchCount);

    println("# sql stmts open: " + server.sqlStatementCurrentlyOpenCount());

    // # sql stmts by category (cell query, member query, other)
    //  -- if you want to do this, capture sql statement events

    // cell cache requests
    // cell cache misses
    // cell cache hits
    final List<ConnectionInfo> connections = monitor.getConnections();
    ConnectionInfo lastConnection = connections.get(connections.size() - 1);
    final List<StatementInfo> statements = monitor.getStatements();
    StatementInfo lastStatement = statements.get(statements.size() - 1);
    println(
        "# cell cache requests, misses, hits; "
            + "by server, connection, mdx statement: "
            + server.cellCacheRequestCount
            + ", "
            + server.cellCacheMissCount()
            + ", "
            + server.cellCacheHitCount
            + "; "
            + lastConnection.cellCacheRequestCount
            + ", "
            + (lastConnection.cellCacheRequestCount - lastConnection.cellCacheHitCount)
            + ", "
            + lastConnection.cellCacheHitCount
            + "; "
            + lastStatement.cellCacheRequestCount
            + ", "
            + lastStatement.cellCacheMissCount
            + ", "
            + lastStatement.cellCacheHitCount);

    // cache misses in the last minute
    // cache hits in the last minute
    // -- build a layer on top of monitor that polls say every 15 seconds,
    //    and keeps results for a few minutes

    println("number of mdx statements currently open: " + server.statementCurrentlyOpenCount());
    println(
        "number of mdx statements currently executing: "
            + server.statementCurrentlyExecutingCount());

    println(
        "jvm memory: "
            + server.jvmHeapBytesUsed
            + ", max: "
            + server.jvmHeapBytesMax
            + ", committed: "
            + server.jvmHeapBytesCommitted);

    println(
        "number of segments: "
            + server.segmentCount
            + ", ever created: "
            + server.segmentCreateCount
            + ", number of cells: "
            + server.cellCount
            + ", number of cell coordinates: "
            + server.cellCoordinateCount
            + ", average cell dimensionality: "
            + ((float) server.cellCoordinateCount / (float) server.cellCount));

    println("Statement: " + lastStatement);
    println("Connection: " + lastConnection);
    println("Server: " + server);

    // number of mdx function calls cumulative
    // how many operations have been evaluated in sql?
    // number of members in cache
    // number of cells in segments
    // mdx query time
    // sql query time
    // sql rows
    // olap4j connection pool size
    // sql connection pool size
    // thread count
    // # schemas in schema cache
    // cells fulfilled by sql statements
    // mondrian server count (other stats relate to just one server)
    //
    // Events:
    //
    // SQL statement start
    // SQL statment stop
    // external cache call
    // sort
    // (other expensive operations similar to sort?)
  }
예제 #24
0
 public void publishNanopub(Nanopub nanopub) throws IOException {
   if (serverInfo == null) {
     if (serverUrls == null || serverUrls.isEmpty()) {
       serverIterator = new ServerIterator();
     } else {
       serverIterator = new ServerIterator(serverUrls);
     }
     serverInfo = serverIterator.next();
   }
   artifactCode = TrustyUriUtils.getArtifactCode(nanopub.getUri().toString());
   if (verbose) {
     System.out.println("---");
     System.out.println("Trying to publish nanopub: " + artifactCode);
   }
   while (serverInfo != null) {
     String serverUrl = serverInfo.getPublicUrl();
     try {
       if (!ServerInfo.load(serverUrl).isPostNanopubsEnabled()) {
         serverInfo = serverIterator.next();
         continue;
       }
     } catch (ServerInfoException ex) {
       serverInfo = serverIterator.next();
       continue;
     }
     if (verbose) {
       System.out.println("Trying server: " + serverUrl);
     }
     try {
       HttpPost post = new HttpPost(serverUrl);
       String nanopubString = NanopubUtils.writeToString(nanopub, RDFFormat.TRIG);
       post.setEntity(new StringEntity(nanopubString, "UTF-8"));
       post.setHeader("Content-Type", RDFFormat.TRIG.getDefaultMIMEType());
       HttpResponse response = HttpClientBuilder.create().build().execute(post);
       int code = response.getStatusLine().getStatusCode();
       if (code >= 200 && code < 300) {
         if (usedServers.containsKey(serverUrl)) {
           usedServers.put(serverUrl, usedServers.get(serverUrl) + 1);
         } else {
           usedServers.put(serverUrl, 1);
         }
         if (verbose) {
           System.out.println("Published: " + artifactCode);
         }
         return;
       } else {
         if (verbose) {
           System.out.println(
               "Response: " + code + " " + response.getStatusLine().getReasonPhrase());
         }
       }
     } catch (IOException ex) {
       if (verbose) {
         System.out.println(ex.getClass().getName() + ": " + ex.getMessage());
       }
     } catch (OpenRDFException ex) {
       if (verbose) {
         System.out.println(ex.getClass().getName() + ": " + ex.getMessage());
       }
     }
     serverInfo = serverIterator.next();
   }
   serverInfo = null;
   throw new IOException("Failed to publish the nanopub");
 }
예제 #25
0
  private void spawnInner(
      int processes,
      int serverIndex,
      int maxHeap,
      String frameworkCode,
      ArrayList<ServerInfo> logins,
      String[] args,
      int terminationPort)
      throws Exception {

    String ownLocation = new File(".").getAbsolutePath();
    System.out.println("ownLocation=" + ownLocation);

    DistributedLockProvider provider = Globals.instantiateLockProvider(frameworkCode);

    String localClasspath;

    if (System.getProperty("java.class.path").contains("Chainbench.jar"))
      localClasspath = ownLocation + "/Chainbench.jar";
    else {
      final String CP_STUB = ".;./bin;./lib/*;./lib/ojdbc6.jar;./lib/aspectjrt.jar";

      localClasspath = provider.getMiniServerClasspath(CP_STUB);
    }

    int pathEnvVarIndex = -1;

    // Need to copy env vars across or get a Windows networking error
    Map<String, String> variables = System.getenv();
    String[] envp = new String[variables.size()];
    int i = 0;
    for (Map.Entry<String, String> entry : variables.entrySet()) {
      String name = entry.getKey();
      String value = entry.getValue();

      if (name.toLowerCase().equals("path")) {
        pathEnvVarIndex = i;
        System.out.println("PATH AT INDEX" + i);
        System.out.println("PATH=" + value);
      }

      envp[i++] = name + "=" + value;
    }

    Params.setServerIndex(args, serverIndex);

    String flattened = Params.spaceSeparatedList(args);
    System.out.println("Flattened=" + flattened);

    String debugFlags =
        (serverIndex == 0)
            ? " -debug -Xrunjdwp:transport=dt_socket,server=y,suspend=n,address=1234 "
            : "";

    String cmdStub;
    String miniserverClasspath;
    String extraProps = "";

    if (serverIndex != 0 && logins.size() != 0) {
      int remoteBoxIndex = serverIndex % (logins.size());
      ServerInfo login = logins.get(remoteBoxIndex);
      cmdStub =
          "cmd /K start java -cp "
              + localClasspath
              + " com.hp.software.chainbench.SSH "
              + login.getHost()
              + " "
              + login.getUsername()
              + " "
              + login.getPassword()
              + " "
              + terminationPort
              + " "
              + " java ";

      miniserverClasspath = "./Chainbench.jar";

      // Speeds up JDBC cxns on Linux -
      // see http://stackoverflow.com/questions/5503063/oracle-getconnection-slow
      extraProps = "-Djava.security.egd=file:/dev/./urandom";

      ServerInfo remote = (ServerInfo) login.clone();
      remote.setTerminationPort(terminationPort);
      servers.add(remote);
    } else {
      miniserverClasspath = localClasspath;
      cmdStub = "cmd /K start java ";

      ServerInfo local = new ServerInfo("localhost", null, null, terminationPort);
      servers.add(local);
    }

    String loadTimeWeaver = "";
    if (Params.getSlowdownMode(args).equals(Constants.SLOWDOWN_ASPECT)) {
      loadTimeWeaver = " -javaagent:./lib/aspectjweaver.jar ";
    } else if (Params.getSlowdownMode(args).equals(Constants.SLOWDOWN_REVISER)) {
      loadTimeWeaver =
          " -javaagent:./lib/gluonj.jar=debug:com.hp.software.chainbench.SlowdownReviser ";
    }

    String propsStub =
        // " -XX:+HeapDumpOnOutOfMemoryError  " +
        " -Xms"
            + maxHeap
            + "m"
            + " -Xmx"
            + maxHeap
            + "m"
            + loadTimeWeaver
            + debugFlags
            + extraProps;

    String props = provider.getJavaProps(propsStub, args);

    String cmd =
        cmdStub
            + " "
            + props
            + " "
            + " -cp "
            + miniserverClasspath
            + " com.hp.software.chainbench.MiniServer "
            + flattened;
    System.out.println(cmd);

    /* " -Dgemfire.remove-unresponsive-client=true " +
    " -Dgemfire.enable-network-partition-detection=true " +
    " -Dgemfire.departure-correlation-window=30 " +
    " -Dgemfire.conserve-sockets=false " +
    " -Dgemfire.ack-severe-alert-threshold=5  " + */
    //
    /* " -Dhazelcast.initial.min.cluster.size=" + processes +
    // " -Dhazelcast.restart.on.max.idle=true " +
    // " -Dhazelcast.max.no.heartbeat.seconds=15  " +
    // " -Dhazelcast.in.thread.priority=10 " +
    // " -Dhazelcast.out.thread.priority=10 " +
    // " -Dhazelcast.service.thread.priority=10 " + */
    //
    /* " -Djgroups.bind_addr=" + bindAddress + "  " +
    " -Djgroups.diagnostics_addr=" + bindAddress + "  " +
    " -Dsm.ini.groupname=testGroupName   " + */

    File dir = new File(ownLocation);
    Process p = Runtime.getRuntime().exec(cmd, envp, dir);

    localProcesses.add(p);
  }
예제 #26
0
 public String getPublishedNanopubUrl() {
   if (serverInfo == null || artifactCode == null) {
     return null;
   }
   return serverInfo.getPublicUrl() + artifactCode;
 }
예제 #27
0
  /**
   * This will not reuse any session, it will create the session and close it at the end
   *
   * @param commandInfo Encapsulated information about command. E.g :- executable name parameters
   *     etc ...
   * @param serverInfo The SSHing server information.
   * @param authenticationInfo Security data needs to be communicated with remote server.
   * @param commandOutput The output of the command.
   * @param configReader configuration required for ssh/gshissh connection
   * @throws SSHApiException throw exception when error occurs
   */
  public static void executeCommand(
      CommandInfo commandInfo,
      ServerInfo serverInfo,
      AuthenticationInfo authenticationInfo,
      CommandOutput commandOutput,
      ConfigReader configReader)
      throws SSHApiException {

    if (authenticationInfo instanceof GSIAuthenticationInfo) {
      System.setProperty(
          X509_CERT_DIR,
          (String)
              ((GSIAuthenticationInfo) authenticationInfo).getProperties().get("X509_CERT_DIR"));
    }

    JSch jsch = new ExtendedJSch();

    log.debug(
        "Connecting to server - "
            + serverInfo.getHost()
            + ":"
            + serverInfo.getPort()
            + " with user name - "
            + serverInfo.getUserName());

    Session session;

    try {
      session =
          jsch.getSession(serverInfo.getUserName(), serverInfo.getHost(), serverInfo.getPort());
    } catch (JSchException e) {
      throw new SSHApiException(
          "An exception occurred while creating SSH session."
              + "Connecting server - "
              + serverInfo.getHost()
              + ":"
              + serverInfo.getPort()
              + " connecting user name - "
              + serverInfo.getUserName(),
          e);
    }

    java.util.Properties config = configReader.getProperties();
    session.setConfig(config);

    // =============================================================
    // Handling vanilla SSH pieces
    // =============================================================
    if (authenticationInfo instanceof SSHPasswordAuthentication) {
      String password =
          ((SSHPasswordAuthentication) authenticationInfo)
              .getPassword(serverInfo.getUserName(), serverInfo.getHost());

      session.setUserInfo(new SSHAPIUIKeyboardInteractive(password));

      // TODO figure out why we need to set password to session
      session.setPassword(password);

    } else if (authenticationInfo instanceof SSHPublicKeyFileAuthentication) {
      SSHPublicKeyFileAuthentication sshPublicKeyFileAuthentication =
          (SSHPublicKeyFileAuthentication) authenticationInfo;

      String privateKeyFile =
          sshPublicKeyFileAuthentication.getPrivateKeyFile(
              serverInfo.getUserName(), serverInfo.getHost());

      logDebug("The private key file for vanilla SSH " + privateKeyFile);

      String publicKeyFile =
          sshPublicKeyFileAuthentication.getPrivateKeyFile(
              serverInfo.getUserName(), serverInfo.getHost());

      logDebug("The public key file for vanilla SSH " + publicKeyFile);

      Identity identityFile;

      try {
        identityFile = GSISSHIdentityFile.newInstance(privateKeyFile, null, jsch);
      } catch (JSchException e) {
        throw new SSHApiException(
            "An exception occurred while initializing keys using files. "
                + "(private key and public key)."
                + "Connecting server - "
                + serverInfo.getHost()
                + ":"
                + serverInfo.getPort()
                + " connecting user name - "
                + serverInfo.getUserName()
                + " private key file - "
                + privateKeyFile
                + ", public key file - "
                + publicKeyFile,
            e);
      }

      // Add identity to identity repository
      GSISSHIdentityRepository identityRepository = new GSISSHIdentityRepository(jsch);
      identityRepository.add(identityFile);

      // Set repository to session
      session.setIdentityRepository(identityRepository);

      // Set the user info
      SSHKeyPasswordHandler sshKeyPasswordHandler =
          new SSHKeyPasswordHandler((SSHKeyAuthentication) authenticationInfo);

      session.setUserInfo(sshKeyPasswordHandler);

    } else if (authenticationInfo instanceof SSHPublicKeyAuthentication) {

      SSHPublicKeyAuthentication sshPublicKeyAuthentication =
          (SSHPublicKeyAuthentication) authenticationInfo;

      Identity identityFile;

      try {
        String name = serverInfo.getUserName() + "_" + serverInfo.getHost();
        identityFile =
            GSISSHIdentityFile.newInstance(
                name,
                sshPublicKeyAuthentication.getPrivateKey(
                    serverInfo.getUserName(), serverInfo.getHost()),
                sshPublicKeyAuthentication.getPublicKey(
                    serverInfo.getUserName(), serverInfo.getHost()),
                jsch);
      } catch (JSchException e) {
        throw new SSHApiException(
            "An exception occurred while initializing keys using byte arrays. "
                + "(private key and public key)."
                + "Connecting server - "
                + serverInfo.getHost()
                + ":"
                + serverInfo.getPort()
                + " connecting user name - "
                + serverInfo.getUserName(),
            e);
      }

      // Add identity to identity repository
      GSISSHIdentityRepository identityRepository = new GSISSHIdentityRepository(jsch);
      identityRepository.add(identityFile);

      // Set repository to session
      session.setIdentityRepository(identityRepository);

      // Set the user info
      SSHKeyPasswordHandler sshKeyPasswordHandler =
          new SSHKeyPasswordHandler((SSHKeyAuthentication) authenticationInfo);

      session.setUserInfo(sshKeyPasswordHandler);
    }

    // Not a good way, but we dont have any choice
    if (session instanceof ExtendedSession) {
      if (authenticationInfo instanceof GSIAuthenticationInfo) {
        ((ExtendedSession) session)
            .setAuthenticationInfo((GSIAuthenticationInfo) authenticationInfo);
      }
    }

    try {
      session.connect();
    } catch (JSchException e) {
      throw new SSHApiException(
          "An exception occurred while connecting to server."
              + "Connecting server - "
              + serverInfo.getHost()
              + ":"
              + serverInfo.getPort()
              + " connecting user name - "
              + serverInfo.getUserName(),
          e);
    }

    String command = commandInfo.getCommand();

    Channel channel;
    try {
      channel = session.openChannel("exec");
      ((ChannelExec) channel).setCommand(command);
    } catch (JSchException e) {
      session.disconnect();

      throw new SSHApiException(
          "Unable to execute command - "
              + command
              + " on server - "
              + serverInfo.getHost()
              + ":"
              + serverInfo.getPort()
              + " connecting user name - "
              + serverInfo.getUserName(),
          e);
    }

    channel.setInputStream(null);
    ((ChannelExec) channel).setErrStream(commandOutput.getStandardError());

    try {
      channel.connect();
    } catch (JSchException e) {

      channel.disconnect();
      session.disconnect();

      throw new SSHApiException(
          "Unable to retrieve command output. Command - "
              + command
              + " on server - "
              + serverInfo.getHost()
              + ":"
              + serverInfo.getPort()
              + " connecting user name - "
              + serverInfo.getUserName(),
          e);
    }

    commandOutput.onOutput(channel);

    channel.disconnect();
    session.disconnect();
  }
  public void findResources(ServerInfo serverInfo)
      throws URISyntaxException, DavException, HttpException, IOException {
    // CardDAV
    Log.i(TAG, "*** Starting CardDAV resource detection");
    WebDavResource principal = getCurrentUserPrincipal(serverInfo, "carddav");
    URI uriAddressBookHomeSet = null;
    try {
      principal.propfind(Mode.HOME_SETS);
      uriAddressBookHomeSet = principal.getProperties().getAddressbookHomeSet();
    } catch (Exception e) {
      Log.i(TAG, "Couldn't find address-book home set", e);
    }
    if (uriAddressBookHomeSet != null) {
      Log.i(TAG, "Found address-book home set: " + uriAddressBookHomeSet);

      WebDavResource homeSetAddressBooks = new WebDavResource(principal, uriAddressBookHomeSet);
      if (checkHomesetCapabilities(homeSetAddressBooks, "addressbook")) {
        serverInfo.setCardDAV(true);
        homeSetAddressBooks.propfind(Mode.CARDDAV_COLLECTIONS);

        List<WebDavResource> possibleAddressBooks = new LinkedList<>();
        possibleAddressBooks.add(homeSetAddressBooks);
        if (homeSetAddressBooks.getMembers() != null)
          possibleAddressBooks.addAll(homeSetAddressBooks.getMembers());

        List<ServerInfo.ResourceInfo> addressBooks = new LinkedList<>();
        for (WebDavResource resource : possibleAddressBooks) {
          final WebDavResource.Properties properties = resource.getProperties();
          if (properties.isAddressBook()) {
            Log.i(TAG, "Found address book: " + resource.getLocation().getPath());
            ServerInfo.ResourceInfo info =
                new ServerInfo.ResourceInfo(
                    ServerInfo.ResourceInfo.Type.ADDRESS_BOOK,
                    properties.isReadOnly(),
                    resource.getLocation().toString(),
                    properties.getDisplayName(),
                    properties.getDescription(),
                    properties.getColor());

            addressBooks.add(info);
          }
        }
        serverInfo.setAddressBooks(addressBooks);
      } else Log.w(TAG, "Found address-book home set, but it doesn't advertise CardDAV support");
    }

    // CalDAV
    Log.i(TAG, "*** Starting CalDAV resource detection");
    principal = getCurrentUserPrincipal(serverInfo, "caldav");
    URI uriCalendarHomeSet = null;
    try {
      principal.propfind(Mode.HOME_SETS);
      uriCalendarHomeSet = principal.getProperties().getCalendarHomeSet();
    } catch (Exception e) {
      Log.i(TAG, "Couldn't find calendar home set", e);
    }
    if (uriCalendarHomeSet != null) {
      Log.i(TAG, "Found calendar home set: " + uriCalendarHomeSet);

      WebDavResource homeSetCalendars = new WebDavResource(principal, uriCalendarHomeSet);
      if (checkHomesetCapabilities(homeSetCalendars, "calendar-access")) {
        serverInfo.setCalDAV(true);
        homeSetCalendars.propfind(Mode.CALDAV_COLLECTIONS);

        List<WebDavResource> possibleCalendars = new LinkedList<>();
        possibleCalendars.add(homeSetCalendars);
        if (homeSetCalendars.getMembers() != null)
          possibleCalendars.addAll(homeSetCalendars.getMembers());

        List<ServerInfo.ResourceInfo> calendars = new LinkedList<>(),
            todoLists = new LinkedList<>();
        for (WebDavResource resource : possibleCalendars) {
          final WebDavResource.Properties properties = resource.getProperties();
          if (properties.isCalendar()) {
            Log.i(TAG, "Found calendar: " + resource.getLocation().getPath());
            ServerInfo.ResourceInfo info =
                new ServerInfo.ResourceInfo(
                    ServerInfo.ResourceInfo.Type.CALENDAR,
                    properties.isReadOnly(),
                    resource.getLocation().toString(),
                    properties.getDisplayName(),
                    properties.getDescription(),
                    properties.getColor());
            info.setTimezone(properties.getTimeZone());

            boolean isCalendar = false, isTodoList = false;
            if (properties.getSupportedComponents() == null) {
              // no info about supported components, assuming all components are supported
              isCalendar = true;
              isTodoList = true;
            } else {
              // CALDAV:supported-calendar-component-set available
              for (String supportedComponent : properties.getSupportedComponents())
                if ("VEVENT".equalsIgnoreCase(supportedComponent)) isCalendar = true;
                else if ("VTODO".equalsIgnoreCase(supportedComponent)) isTodoList = true;

              if (!isCalendar && !isTodoList) {
                Log.i(TAG, "Ignoring this calendar because it supports neither VEVENT nor VTODO");
                continue;
              }
            }

            // use a copy constructor to allow different "enabled" status for calendars and todo
            // lists
            if (isCalendar) calendars.add(new ServerInfo.ResourceInfo(info));
            if (isTodoList) todoLists.add(new ServerInfo.ResourceInfo(info));
          }
        }

        serverInfo.setCalendars(calendars);
        serverInfo.setTodoLists(todoLists);
      } else Log.w(TAG, "Found calendar home set, but it doesn't advertise CalDAV support");
    }

    if (!serverInfo.isCalDAV() && !serverInfo.isCardDAV())
      throw new DavIncapableException(context.getString(R.string.setup_neither_caldav_nor_carddav));
  }
  /**
   * Detects the current-user-principal for a given WebDavResource. At first, /.well-known/ is
   * tried. Only if no current-user-principal can be detected for the .well-known location, the
   * given location of the resource is tried.
   *
   * @param serverInfo Location that will be queried
   * @param serviceName Well-known service name ("carddav", "caldav")
   * @return WebDavResource of current-user-principal for the given service, or null if it can't be
   *     found
   *     <p>TODO: If a TXT record is given, always use it instead of trying .well-known first
   */
  WebDavResource getCurrentUserPrincipal(ServerInfo serverInfo, String serviceName)
      throws URISyntaxException, IOException, NotAuthorizedException {
    URI initialURL = getInitialContextURL(serverInfo, serviceName);
    if (initialURL != null) {
      Log.i(
          TAG,
          "Looking up principal URL for service "
              + serviceName
              + "; initial context: "
              + initialURL);

      // determine base URL (host name and initial context path)
      WebDavResource base =
          new WebDavResource(
              httpClient,
              initialURL,
              serverInfo.getUserName(),
              serverInfo.getPassword(),
              serverInfo.isAuthPreemptive());

      // look for well-known service (RFC 5785)
      try {
        WebDavResource wellKnown = new WebDavResource(base, "/.well-known/" + serviceName);
        wellKnown.propfind(Mode.CURRENT_USER_PRINCIPAL);
        if (wellKnown.getProperties().getCurrentUserPrincipal() != null) {
          URI principal = wellKnown.getProperties().getCurrentUserPrincipal();
          Log.i(TAG, "Principal URL found from Well-Known URI: " + principal);
          return new WebDavResource(wellKnown, principal);
        }
      } catch (NotAuthorizedException e) {
        Log.w(TAG, "Not authorized for well-known " + serviceName + " service detection", e);
        throw e;
      } catch (URISyntaxException e) {
        Log.e(
            TAG,
            "Well-known" + serviceName + " service detection failed because of invalid URIs",
            e);
      } catch (HttpException e) {
        Log.d(TAG, "Well-known " + serviceName + " service detection failed with HTTP error", e);
      } catch (DavException e) {
        Log.w(
            TAG,
            "Well-known " + serviceName + " service detection failed with unexpected DAV response",
            e);
      } catch (IOException e) {
        Log.e(TAG, "Well-known " + serviceName + " service detection failed with I/O error", e);
      }

      // fall back to user-given initial context path
      Log.d(TAG, "Well-known service detection failed, trying initial context path " + initialURL);
      try {
        base.propfind(Mode.CURRENT_USER_PRINCIPAL);
        if (base.getProperties().getCurrentUserPrincipal() != null) {
          URI principal = base.getProperties().getCurrentUserPrincipal();
          Log.i(TAG, "Principal URL found from initial context path: " + principal);
          return new WebDavResource(base, principal);
        }
      } catch (NotAuthorizedException e) {
        Log.e(TAG, "Not authorized for querying principal", e);
        throw e;
      } catch (HttpException e) {
        Log.e(TAG, "HTTP error when querying principal", e);
      } catch (DavException e) {
        Log.e(TAG, "DAV error when querying principal", e);
      }

      Log.i(
          TAG,
          "Couldn't find current-user-principal for service "
              + serviceName
              + ", assuming initial context path is principal path");
      return base;
    }
    return null;
  }
  /**
   * Finds the initial service URL from a given base URI (HTTP[S] or mailto URI, user name,
   * password)
   *
   * @param serverInfo User-given service information (including base URI, i.e. HTTP[S] URL+user
   *     name+password or mailto URI and password)
   * @param serviceName Service name ("carddav" or "caldav")
   * @return Initial service URL (HTTP/HTTPS), without user credentials
   * @throws URISyntaxException when the user-given URI is invalid
   */
  public URI getInitialContextURL(ServerInfo serverInfo, String serviceName)
      throws URISyntaxException {
    String scheme, domain;
    int port = -1;
    String path = "/";

    URI baseURI = serverInfo.getBaseURI();
    if ("mailto".equalsIgnoreCase(baseURI.getScheme())) {
      // mailto URIs
      String mailbox = serverInfo.getBaseURI().getSchemeSpecificPart();

      // determine service FQDN
      int pos = mailbox.lastIndexOf("@");
      if (pos == -1) throw new URISyntaxException(mailbox, "Missing @ sign");

      scheme = "https";
      domain = mailbox.substring(pos + 1);
      if (domain.isEmpty()) throw new URISyntaxException(mailbox, "Missing domain name");
    } else {
      // HTTP(S) URLs
      scheme = baseURI.getScheme();
      domain = baseURI.getHost();
      port = baseURI.getPort();
      path = baseURI.getPath();
    }

    // try to determine FQDN and port number using SRV records
    try {
      String name = "_" + serviceName + "s._tcp." + domain;
      Log.d(TAG, "Looking up SRV records for " + name);
      Record[] records = new Lookup(name, Type.SRV).run();
      if (records != null && records.length >= 1) {
        SRVRecord srv = selectSRVRecord(records);

        scheme = "https";
        domain = srv.getTarget().toString(true);
        port = srv.getPort();
        Log.d(
            TAG, "Found " + serviceName + "s service for " + domain + " -> " + domain + ":" + port);

        if (port == 443) // no reason to explicitly give the default port
        port = -1;

        // SRV record found, look for TXT record too (for initial context path)
        records = new Lookup(name, Type.TXT).run();
        if (records != null && records.length >= 1) {
          TXTRecord txt = (TXTRecord) records[0];
          for (Object o : txt.getStrings().toArray()) {
            String segment = (String) o;
            if (segment.startsWith("path=")) {
              path = segment.substring(5);
              Log.d(
                  TAG,
                  "Found initial context path for "
                      + serviceName
                      + " at "
                      + domain
                      + " -> "
                      + path);
              break;
            }
          }
        }
      }
    } catch (TextParseException e) {
      throw new URISyntaxException(domain, "Invalid domain name");
    }

    return new URI(scheme, null, domain, port, path, null, null);
  }