@Override
  public Table showTableDetails(UUID subscriptionId, String serviceName, String tableName)
      throws AzureCmdException {
    String[] cmd =
        new String[] {
          "mobile",
          "table",
          "show",
          "--json",
          "-s",
          subscriptionId.toString(),
          serviceName,
          tableName
        };

    String json = AzureCommandHelper.getInstance().consoleExec(cmd);

    CustomJsonSlurper slurper = new CustomJsonSlurper();
    Map<String, Object> tempRes = (Map<String, Object>) slurper.parseText(json);

    Table t = new Table();

    Map<String, Object> tableData = (Map<String, Object>) tempRes.get("table");
    t.setName(tableData.get("name").toString());
    t.setSelfLink(tableData.get("selflink").toString());

    Map<String, String> per = (Map<String, String>) tempRes.get("permissions");

    TablePermissions tablePermissions = new TablePermissions();
    tablePermissions.setInsert(PermissionItem.getPermitionType(per.get("insert")));
    tablePermissions.setUpdate(PermissionItem.getPermitionType(per.get("update")));
    tablePermissions.setRead(PermissionItem.getPermitionType(per.get("read")));
    tablePermissions.setDelete(PermissionItem.getPermitionType(per.get("delete")));
    t.setTablePermissions(tablePermissions);

    for (Map<String, Object> column : (List<Map<String, Object>>) tempRes.get("columns")) {
      Column c = new Column();
      c.setName(column.get("name").toString());
      c.setType(column.get("type").toString());
      c.setSelfLink(column.get("selflink").toString());
      c.setIndexed((Boolean) column.get("indexed"));
      c.setZumoIndex((Boolean) column.get("zumoIndex"));

      t.getColumns().add(c);
    }

    for (Map<String, Object> script : (List<Map<String, Object>>) tempRes.get("scripts")) {
      Script s = new Script();

      s.setOperation(script.get("operation").toString());
      s.setBytes((Integer) script.get("sizeBytes"));
      s.setSelfLink(script.get("selflink").toString());
      s.setName(String.format("%s.%s", tableData.get("name"), script.get("operation").toString()));

      t.getScripts().add(s);
    }

    return t;
  }
コード例 #2
0
  public static void runShutdownScripts() {
    for (int i = 0, limit = Outliner.scriptsManager.model.getSize(); i < limit; i++) {
      Script script = Outliner.scriptsManager.model.get(i);

      if (script.isShutdownScript()) {
        runScript(script, SHUTDOWN_SCRIPT);
      }
    }
  }
コード例 #3
0
  public int indexOf(String name) {
    for (int i = 0, limit = scripts.size(); i < limit; i++) {
      Script script = get(i);
      if (script.getName().equals(name)) {
        return i;
      }
    }

    return -1;
  }
コード例 #4
0
ファイル: Script.java プロジェクト: ethancedrik/commandhelper
  public static Script GenerateScript(ParseTree tree, String label) {
    Script s = new Script();

    s.hasBeenCompiled = true;
    s.compilerError = false;
    s.cright = new ArrayList<ParseTree>();
    s.cright.add(tree);
    s.label = label;

    return s;
  }
コード例 #5
0
  // Static Methods
  public static void runStartupScripts() {
    if (Outliner.scriptsManager != null) {
      if (Outliner.scriptsManager.model != null) {
        for (int i = 0, limit = Outliner.scriptsManager.model.getSize(); i < limit; i++) {
          Script script = Outliner.scriptsManager.model.get(i);

          if (script.isStartupScript()) {
            runScript(script, STARTUP_SCRIPT);
          }
        }
      } else {
        System.out.println("Error: ScriptsManagerModel was null");
      }
    } else {
      System.out.println("Error: ScriptsManager was null");
    }
  }
コード例 #6
0
  // Add/Insert
  public int add(Script script) {
    // Find the correct spot to add it alphabetically
    int i, limit;
    for (i = 0, limit = scripts.size(); i < limit; i++) {
      Script scriptTemp = (Script) scripts.get(i);
      if (scriptTemp.getName().compareTo(script.getName()) >= 0) {
        break;
      }
    }

    scripts.add(i, script);

    // Update the table
    fireTableRowsInserted(i, i);

    return i;
  }
コード例 #7
0
  private void scanRequest(
      Collection<Script> match, final TransactionListener listener, String requestQueue)
      throws BCSAPIException {
    try (ConnectorSession session = connection.createSession()) {
      ConnectorMessage m = session.createMessage();

      ConnectorProducer exactMatchProducer =
          session.createProducer(session.createQueue(requestQueue));
      BCSAPIMessage.ExactMatchRequest.Builder builder =
          BCSAPIMessage.ExactMatchRequest.newBuilder();
      for (Script d : match) {
        builder.addMatch(ByteString.copyFrom(d.toByteArray()));
      }
      m.setPayload(builder.build().toByteArray());
      final ConnectorTemporaryQueue answerQueue = session.createTemporaryQueue();
      final ConnectorConsumer consumer = session.createConsumer(answerQueue);
      m.setReplyTo(answerQueue);
      final Semaphore ready = new Semaphore(0);
      consumer.setMessageListener(
          message -> {
            try {
              byte[] body = message.getPayload();
              if (body != null) {
                APITransaction t = APITransaction.fromProtobuf(BCSAPIMessage.TX.parseFrom(body));
                listener.process(t);
              } else {
                consumer.close();
                answerQueue.delete();
                ready.release();
              }
            } catch (ConnectorException | HyperLedgerException | InvalidProtocolBufferException e) {
              log.error("Malformed message received for scan matching transactions", e);
            }
          });

      exactMatchProducer.send(m);
      ready.acquireUninterruptibly();
    } catch (ConnectorException e) {
      throw new BCSAPIException(e);
    }
  }
コード例 #8
0
  public void loadEventsScript(File eventScript) {
    if (eventScript == null) {
      return;
    }

    GrailsConsole console = GrailsConsole.getInstance();
    try {
      Class<?> scriptClass = classLoader.parseClass(eventScript);
      if (scriptClass == null) {
        console.error("Could not load event script (script may be empty): " + eventScript);
        return;
      }

      Script script = (Script) scriptClass.newInstance();
      script.setBinding(
          new Binding(binding.getVariables()) {
            @SuppressWarnings("rawtypes")
            @Override
            public void setVariable(String var, Object o) {
              final Matcher matcher = EVENT_NAME_PATTERN.matcher(var);
              if (matcher.matches() && (o instanceof Closure)) {
                String eventName = matcher.group(1);
                List<Closure> hooks = globalEventHooks.get(eventName);
                if (hooks == null) {
                  hooks = new ArrayList<Closure>();
                  globalEventHooks.put(eventName, hooks);
                }
                hooks.add((Closure<?>) o);
              }
              super.setVariable(var, o);
            }
          });
      script.run();
    } catch (Throwable e) {
      StackTraceUtils.deepSanitize(e);
      console.error(
          "Error loading event script from file [" + eventScript + "] " + e.getMessage(), e);
    }
  }
コード例 #9
0
  public static void runScript(Script script, int scriptType) {
    if (scriptType == SHUTDOWN_SCRIPT) {
      try {
        script.process();
      } catch (Exception e) {
        System.out.println(e.getMessage());
      }
    } else {
      // Create a new Thread
      ScriptThread scriptThread = new ScriptThread(script, scriptType);

      // Run the Thread
      scriptThread.start();
    }
  }
コード例 #10
0
ファイル: Basic.java プロジェクト: hhuang42/JavaVideoGame
 public void run() {
   super.run();
 }
コード例 #11
0
 private void linkToJavaScript(Composite comp) {
   Script script = new Script("");
   script.attribute("src", "admin.js");
   comp.add(script);
 }
コード例 #12
0
ファイル: SecureShellAction.java プロジェクト: ravan91/EC2Box
  /** creates composite terminals if there are errors or authentication issues. */
  @Action(
      value = "/admin/createTerms",
      results = {@Result(name = "success", location = "/admin/secure_shell.jsp")})
  public String createTerms() {

    Long userId = AuthUtil.getUserId(servletRequest.getSession());
    Long sessionId = AuthUtil.getSessionId(servletRequest.getSession());

    if (pendingSystemStatus != null && pendingSystemStatus.getId() != null) {

      // get status
      currentSystemStatus = SystemStatusDB.getSystemStatus(pendingSystemStatus.getId(), userId);
      // if initial status run script
      if (currentSystemStatus != null
          && (HostSystem.INITIAL_STATUS.equals(currentSystemStatus.getStatusCd())
              || HostSystem.AUTH_FAIL_STATUS.equals(currentSystemStatus.getStatusCd())
              || HostSystem.PUBLIC_KEY_FAIL_STATUS.equals(currentSystemStatus.getStatusCd()))) {

        // set current servletRequest.getSession()
        currentSystemStatus =
            SSHUtil.openSSHTermOnSystem(
                passphrase, password, userId, sessionId, currentSystemStatus, userSchSessionMap);
      }
      if (currentSystemStatus != null
          && (HostSystem.AUTH_FAIL_STATUS.equals(currentSystemStatus.getStatusCd())
              || HostSystem.PUBLIC_KEY_FAIL_STATUS.equals(currentSystemStatus.getStatusCd()))) {

        pendingSystemStatus = currentSystemStatus;

      } else {

        pendingSystemStatus = SystemStatusDB.getNextPendingSystem(userId);
        // if success loop through systems until finished or need password
        while (pendingSystemStatus != null
            && currentSystemStatus != null
            && HostSystem.SUCCESS_STATUS.equals(currentSystemStatus.getStatusCd())) {
          currentSystemStatus =
              SSHUtil.openSSHTermOnSystem(
                  passphrase, password, userId, sessionId, pendingSystemStatus, userSchSessionMap);
          pendingSystemStatus = SystemStatusDB.getNextPendingSystem(userId);
        }
      }
    }
    if (SystemStatusDB.getNextPendingSystem(userId) == null) {
      // check user map
      if (userSchSessionMap != null && !userSchSessionMap.isEmpty()) {

        // get user servletRequest.getSession()s
        Map<Long, SchSession> schSessionMap = userSchSessionMap.get(userId).getSchSessionMap();

        for (SchSession schSession : schSessionMap.values()) {
          // add to host system list
          systemList.add(schSession.getHostSystem());
          // run script it exists
          if (script != null && script.getId() != null && script.getId() > 0) {
            script = ScriptDB.getScript(script.getId(), userId);
            BufferedReader reader = new BufferedReader(new StringReader(script.getScript()));
            String line;
            try {
              while ((line = reader.readLine()) != null) {
                schSession.getCommander().println(line);
              }
            } catch (Exception e) {
              e.printStackTrace();
            }
          }
        }
      }
    }

    return SUCCESS;
  }