Beispiel #1
0
  static {
    // same properties for authZ and authZPolicy
    try {
      ContextConfig cc = ContextConfig.getInstance(ServiceNames.SVC_RM);
      String configFile = cc.getFilePath(ConfigDefaults.CONFIG);
      Map config = ConfigHelper.getConfiguration(configFile);
      assert config != null : "No configuration";
      Map RMconfig = (Map) config.get("resourceManager");
      assert RMconfig != null : "No resourceManager stanza in configuration";
      dbname = (String) RMconfig.get("dbname");
      assert dbname != null : "No dbname in configuration";
      username = (String) RMconfig.get("username");
      assert username != null : "No user name in configuration";
      password = (String) RMconfig.get("password");
      assert password != null : "No password in configuration";
      monitor = (String) RMconfig.get("monitor");
      scanInterval = Integer.valueOf((String) RMconfig.get("scanInterval"));
      lookAhead = Integer.valueOf((String) RMconfig.get("lookAhead"));

      configFile = cc.getFilePath(ServiceNames.SVC_UTILS, cc.getContext(), ConfigDefaults.CONFIG);
      Map utilConfig = (HashMap<String, Object>) ConfigHelper.getConfiguration(configFile);
      Map localDomain = (Map) utilConfig.get("localDomain");
      localDomainId = (String) localDomain.get("id");
      System.out.println("localDomainId is " + localDomainId);
    } catch (ConfigException e) {
      log.error("configurationException " + e.getMessage());
    }
  }
Beispiel #2
0
 @BeforeSuite
 public void setUpTests() {
   OSCARSNetLogger netLogger = OSCARSNetLogger.getTlogger();
   netLogger.init(ModuleName.COORD, "0000");
   System.out.println("starting coordinator tests");
   cc.setContext(context);
   cc.setServiceName(ServiceNames.SVC_COORD);
   try {
     cc.loadManifest(new File("config/" + ConfigDefaults.MANIFEST));
     cc.setLog4j();
     // need to do this after the log4j.properties file has been set
     log = Logger.getLogger(CoordTest.class);
     log.debug(netLogger.start("setupTests"));
   } catch (ConfigException ex) {
     System.out.println("caught ConfigurationException " + ex.getMessage());
     System.exit(-1);
   }
 }
Beispiel #3
0
@Test
public class CoordTest {
  private static boolean coordStarted = false;
  private static ContextConfig cc = ContextConfig.getInstance(ServiceNames.SVC_COORD);
  private static String context = ConfigDefaults.CTX_TESTING;
  private static Logger log = null;

  // TIMEOUT is the time in second for which the tests are going to wait for replies from the
  // coordinator before assuming that it failed. Depending on the performance of the host, this
  // timeout may have to be raised to several minutes
  private static long TIMEOUT = (4 * 60);

  @BeforeSuite
  public void setUpTests() {
    OSCARSNetLogger netLogger = OSCARSNetLogger.getTlogger();
    netLogger.init(ModuleName.COORD, "0000");
    System.out.println("starting coordinator tests");
    cc.setContext(context);
    cc.setServiceName(ServiceNames.SVC_COORD);
    try {
      cc.loadManifest(new File("config/" + ConfigDefaults.MANIFEST));
      cc.setLog4j();
      // need to do this after the log4j.properties file has been set
      log = Logger.getLogger(CoordTest.class);
      log.debug(netLogger.start("setupTests"));
    } catch (ConfigException ex) {
      System.out.println("caught ConfigurationException " + ex.getMessage());
      System.exit(-1);
    }
  }

  public class TestException extends Exception {
    private static final long serialVersionUID = 1439115737928915954L;

    public TestException(String reason) {
      super(reason);
    }

    public TestException(Exception e) {
      super(e);
    }
  }

  public class TestFailureRequest extends CoordRequest<String, String> {
    private static final long serialVersionUID = 1L;
    private boolean failMode = false;

    public TestFailureRequest(String name, boolean failMode) {
      super(name, null);
      this.failMode = failMode;
    }

    public TestFailureRequest(String gri, String name, boolean failMode) {
      super(gri, name);
      this.failMode = failMode;
    }

    public void execute() {
      StubAction action1 = new StubAction("action1", this, this.failMode);
      this.add(action1);

      // CoordRequests must start the processing of the graph of CoordActions.
      super.process();

      // The CoordAction part of this CoordRequest is now executed itself.
      this.executed();
    }
  }

  private static void startCoordinator() {
    if (CoordTest.coordStarted) {
      return;
    }
    OSCARSNetLogger netLogger = OSCARSNetLogger.getTlogger();
    String event = "startCoordinator";
    CoordTest.coordStarted = true;
    log.info(netLogger.start(event));
    Coordinator c;
    try {
      c = Coordinator.getInstance();
      c.start();
    } catch (OSCARSServiceException e) {
      log.error(netLogger.error(event, ErrSev.MAJOR, "Coordinator cannot be started."));
      e.printStackTrace();
    }
  }

  public void testFailure() throws TestException {
    CoordTest.startCoordinator();
    try {
      TestFailureRequest failureRequest1 = new TestFailureRequest("No failure1", false);
      failureRequest1.processAndWait(CoordTest.TIMEOUT);
      if (failureRequest1.getState() != CoordAction.State.PROCESSED) {
        throw new TestException("testFailure without failure has failed.");
      }
      if (!failureRequest1.isFullyCompleted()) {
        throw new TestException("testFailure without failure has failed. not fully completed.");
      }
      TestFailureRequest failureRequest2 = new TestFailureRequest("No failure2", true);
      failureRequest2.processAndWait(CoordTest.TIMEOUT);
      if (failureRequest2.getState() != CoordAction.State.FAILED) {
        throw new TestException(
            "testFailure with failure has failed. Incorrect state: " + failureRequest2.getState());
      }
      List<CoordAction> failedActions = failureRequest2.getFailedCoordActions();
      if ((failedActions == null) || (failedActions.size() == 0)) {
        throw new TestException("testFailure with failure has failed. No action has failed.");
      }
      for (CoordAction<String, String> action : failedActions) {
        if (action.getState() != CoordAction.State.FAILED) {
          throw new TestException(
              "testFailure with failure has failed. action "
                  + action.getName()
                  + " has state "
                  + action.getState());
        }
      }
      if (!failureRequest2.isFullyCompleted()) {
        throw new TestException("testFailure with failure has failed. not fully completed.");
      }

    } catch (Exception e) {
      // e.printStackTrace();
      throw new TestException(e);
    }
  }

  public void testNoCoordRequest() throws TestException {
    CoordTest.startCoordinator();
    try {
      // Single CoordAction
      StubAction action = new StubAction("action", null, false);
      action.processAndWait(CoordTest.TIMEOUT);
      if (action.getState() != CoordAction.State.PROCESSED) {
        throw new TestException("testAction/single action has failed. state= " + action.getState());
      }
      if (!action.isFullyCompleted()) {
        throw new TestException("testAction/single action has failed. not fully completed.");
      }
      // Two CoordAction's
      StubAction action1 = new StubAction("action1", null, false);
      StubAction action2 = new StubAction("action2", null, false);
      action1.add(action2);
      action1.processAndWait(CoordTest.TIMEOUT);
      if (action1.getState() != CoordAction.State.PROCESSED) {
        throw new TestException("testAction/two actions has failed. state= " + action1.getState());
      }
      if (!action1.isFullyCompleted()) {
        throw new TestException("testAction/two actions has failed. not fully completed.");
      }

      // Two CoordAction's with failure
      StubAction action3 = new StubAction("action3", null, false);
      StubAction action4 = new StubAction("action4", null, true);
      action3.add(action4);
      action3.processAndWait(CoordTest.TIMEOUT);
      if (action3.getState() != CoordAction.State.PROCESSED) {
        throw new TestException(
            "testAction/two actions/failure has failed. state= " + action3.getState());
      }
      if (!action3.isFullyCompleted()) {
        throw new TestException("testAction/two actions/failure has failed. not fully completed.");
      }
    } catch (Exception e) {
      // e.printStackTrace();
      throw new TestException(e);
    }
  }
  /* the following method talks to the real ResoueceManager service which changed the
       *  rm data base

      public void testGenerateGRI() throws TestException {
          CoordTest.startCoordinator();
          try {
              RMGenerateGRIAction genGRIAction = new RMGenerateGRIAction ("testGenerateGRI", null);
              genGRIAction.execute();
              String gri = genGRIAction.getResultData();
              System.out.println ("test GRI is: " + gri);
              if (gri == null) {
                  throw new TestException ("Returned GRI is null");
              }
          } catch (Exception e) {
              //e.printStackTrace();
              throw new TestException (e);
          }
      }
  */
  /* the following method talks to the real ResoueceManager service which changed the
   *  rm data base
  public void testCreateReservation() throws TestException {
      CoordTest.startCoordinator();
      try {
          ResCreateContent createResvReq = new ResCreateContent();
          UserRequestConstraintType userConstraint = new UserRequestConstraintType();
          long currentTime = System.currentTimeMillis() / 1000;
          userConstraint.setStartTime(currentTime + 3600); // One hour after now.
          userConstraint.setEndTime(currentTime + 7200); // Two hours after now.
          userConstraint.setBandwidth(1); // in Mbps
          Layer2Info layer2Info = new Layer2Info();
          //layer2Info.setSrcEndpoint("urn:ogf:network:es.net:anl-mr1:TenGigabitEthernet3/3:*");
          //layer2Info.setDestEndpoint("urn:ogf:network:es.net:albu-sdn1:xe-1/3/0:*");
          layer2Info.setSrcEndpoint("urn:ogf:network:testdomain-2:node-2-1:port1:link1");
          layer2Info.setDestEndpoint("urn:ogf:network:testdomain-2:node-2-2:port1:link2");
          PathInfo pathInfo = new PathInfo ();
          pathInfo.setLayer2Info(layer2Info);
          CtrlPlanePathContent pathContent = new CtrlPlanePathContent();
          pathContent.setId("fakeID");
          pathInfo.setPathType("strict");
          pathInfo.setPath(pathContent);
          userConstraint.setPathInfo(pathInfo);
          createResvReq.setDescription("IDCTest");
          createResvReq.setUserRequestConstraint(userConstraint);

          String loginName = "testClient";
          CreateReservationRequest createReservation = new CreateReservationRequest ("testCreateReservation",
                                                                                      loginName,
                                                                                      createResvReq);
          createReservation.processAndWait(40000);

          if ( ! createReservation.isFullyCompleted()) {
              throw new TestException ("createReservation query has not completed.");
          }
          if ( createReservation.getState() == CoordAction.State.FAILED) {
              Exception ex = createReservation.getException();
              String exMsg = null;
              if (ex != null) {
                  exMsg = ex.getMessage();
              }
              throw new TestException ("createReservation query failed. Exception found: " + exMsg);
          }

      } catch (Exception e) {
          //e.printStackTrace();
          throw new TestException (e);
      }
  }
  */
}
Beispiel #4
0
  /**
   * @param args arg[0] -c cmd, [1] -u loginName or -s Subject DN, [2] -p password or -i Issuer DN
   *     [3] -C context
   * @throws Exception
   */
  public static void main(String args[]) throws Exception {

    parseArgs(args);

    cc.setContext(context);
    cc.setServiceName(ServiceNames.SVC_AUTHN);
    try {
      cc.loadManifest(ServiceNames.SVC_AUTHN, ConfigDefaults.MANIFEST); // manifest.yaml
      cc.setLog4j();
    } catch (ConfigException ex) {
      System.out.println("caught ConfigurationException " + ex.getMessage());
      System.exit(-1);
    }

    String configFile = cc.getFilePath(ConfigDefaults.CONFIG);
    Map config = ConfigHelper.getConfiguration(configFile);
    assert config != null : "No configuration";
    Map authN = (Map) config.get("soap");
    URL host = new URL((String) authN.get("publishTo"));
    URL wsdl = cc.getWSDLPath(null);
    System.out.println("host is " + host.toString() + "wsdl is " + wsdl.toString());
    AuthNClient client = AuthNClient.getClient(host, wsdl);

    if (cmd.equals("verifyLogin")) {
      System.out.println("Invoking verifyLogin...");
      if (loginName == null || password == null) {
        parser.printHelpOn(System.out);
        System.exit(0);
      }
      LoginId loginId = new LoginId();
      VerifyLoginReqType verifyLoginReq = new VerifyLoginReqType();
      loginId.setLoginName(loginName);
      loginId.setPassword(password);
      verifyLoginReq.setLoginId(loginId);
      verifyLoginReq.setTransactionId("0000");
      Object[] req = new Object[] {verifyLoginReq};

      try {
        Object[] res = client.invoke("verifyLogin", req);
        VerifyReply reply = (VerifyReply) res[0];
        SubjectAttributes subjectAttrs = reply.getSubjectAttributes();
        List<AttributeType> attrs = subjectAttrs.getSubjectAttribute();
        if (attrs.isEmpty()) {
          System.out.println("verifyLogin result= " + loginName + " has no attributes");
        } else {
          for (AttributeType at : attrs) {
            System.out.println(
                "verifyLogin.result=" + at.getName() + " : " + at.getAttributeValue());
          }
        }
      } catch (OSCARSServiceException ex) {
        System.out.println("OSCARSServiceException thrown; " + ex.getMessage());
        ErrorReport errReport = ex.getErrorReport();
        if (errReport != null) {
          System.out.println(errReport.toString());
        }
      }
    } else if (cmd.equals("verifyDN")) {
      System.out.println("Invoking verifyDN...");
      if (issuer == null || subject == null) {
        parser.printHelpOn(System.out);
        System.exit(0);
      }
      VerifyDNReqType verifyDNReq = new VerifyDNReqType();
      DNType DNReq = new DNType();
      DNReq.setSubjectDN(subject);
      DNReq.setIssuerDN(issuer);
      verifyDNReq.setTransactionId("123");
      verifyDNReq.setDN(DNReq);
      Object[] req = new Object[] {verifyDNReq};
      try {
        Object[] res = client.invoke("verifyDN", req);
        VerifyReply reply = (VerifyReply) res[0];
        SubjectAttributes subjectAttrs = reply.getSubjectAttributes();
        List<AttributeType> attrs = subjectAttrs.getSubjectAttribute();
        if (attrs.isEmpty()) {
          System.out.println("verifyDN result= user has no attributes");
        } else {
          for (AttributeType at : attrs) {
            System.out.println("verifyDN.result=" + at.getName() + " : " + at.getAttributeValue());
          }
        }
      } catch (OSCARSServiceException ex) {
        System.out.println("OSCARSServiceException thrown: " + ex.getMessage());
        ErrorReport errReport = ex.getErrorReport();
        if (errReport != null) {
          System.out.println(errReport.toString());
        }
      }
    } else {
      System.out.println("unrecognized command: " + cmd);
    }

    System.exit(0);
  }
Beispiel #5
0
/** AuthNTest - class to test calls to the AuthN service */
public final class AuthNTest {

  private static ContextConfig cc = ContextConfig.getInstance(ServiceNames.SVC_AUTHN);
  private static String cmd = null;
  private static String context = ConfigDefaults.CTX_DEVELOPMENT;
  private static String loginName = null;
  private static String password = null;
  private static String issuer = null;
  private static String subject = null;
  private static OptionParser parser = new OptionParser();

  /**
   * @param args arg[0] -c cmd, [1] -u loginName or -s Subject DN, [2] -p password or -i Issuer DN
   *     [3] -C context
   * @throws Exception
   */
  public static void main(String args[]) throws Exception {

    parseArgs(args);

    cc.setContext(context);
    cc.setServiceName(ServiceNames.SVC_AUTHN);
    try {
      cc.loadManifest(ServiceNames.SVC_AUTHN, ConfigDefaults.MANIFEST); // manifest.yaml
      cc.setLog4j();
    } catch (ConfigException ex) {
      System.out.println("caught ConfigurationException " + ex.getMessage());
      System.exit(-1);
    }

    String configFile = cc.getFilePath(ConfigDefaults.CONFIG);
    Map config = ConfigHelper.getConfiguration(configFile);
    assert config != null : "No configuration";
    Map authN = (Map) config.get("soap");
    URL host = new URL((String) authN.get("publishTo"));
    URL wsdl = cc.getWSDLPath(null);
    System.out.println("host is " + host.toString() + "wsdl is " + wsdl.toString());
    AuthNClient client = AuthNClient.getClient(host, wsdl);

    if (cmd.equals("verifyLogin")) {
      System.out.println("Invoking verifyLogin...");
      if (loginName == null || password == null) {
        parser.printHelpOn(System.out);
        System.exit(0);
      }
      LoginId loginId = new LoginId();
      VerifyLoginReqType verifyLoginReq = new VerifyLoginReqType();
      loginId.setLoginName(loginName);
      loginId.setPassword(password);
      verifyLoginReq.setLoginId(loginId);
      verifyLoginReq.setTransactionId("0000");
      Object[] req = new Object[] {verifyLoginReq};

      try {
        Object[] res = client.invoke("verifyLogin", req);
        VerifyReply reply = (VerifyReply) res[0];
        SubjectAttributes subjectAttrs = reply.getSubjectAttributes();
        List<AttributeType> attrs = subjectAttrs.getSubjectAttribute();
        if (attrs.isEmpty()) {
          System.out.println("verifyLogin result= " + loginName + " has no attributes");
        } else {
          for (AttributeType at : attrs) {
            System.out.println(
                "verifyLogin.result=" + at.getName() + " : " + at.getAttributeValue());
          }
        }
      } catch (OSCARSServiceException ex) {
        System.out.println("OSCARSServiceException thrown; " + ex.getMessage());
        ErrorReport errReport = ex.getErrorReport();
        if (errReport != null) {
          System.out.println(errReport.toString());
        }
      }
    } else if (cmd.equals("verifyDN")) {
      System.out.println("Invoking verifyDN...");
      if (issuer == null || subject == null) {
        parser.printHelpOn(System.out);
        System.exit(0);
      }
      VerifyDNReqType verifyDNReq = new VerifyDNReqType();
      DNType DNReq = new DNType();
      DNReq.setSubjectDN(subject);
      DNReq.setIssuerDN(issuer);
      verifyDNReq.setTransactionId("123");
      verifyDNReq.setDN(DNReq);
      Object[] req = new Object[] {verifyDNReq};
      try {
        Object[] res = client.invoke("verifyDN", req);
        VerifyReply reply = (VerifyReply) res[0];
        SubjectAttributes subjectAttrs = reply.getSubjectAttributes();
        List<AttributeType> attrs = subjectAttrs.getSubjectAttribute();
        if (attrs.isEmpty()) {
          System.out.println("verifyDN result= user has no attributes");
        } else {
          for (AttributeType at : attrs) {
            System.out.println("verifyDN.result=" + at.getName() + " : " + at.getAttributeValue());
          }
        }
      } catch (OSCARSServiceException ex) {
        System.out.println("OSCARSServiceException thrown: " + ex.getMessage());
        ErrorReport errReport = ex.getErrorReport();
        if (errReport != null) {
          System.out.println(errReport.toString());
        }
      }
    } else {
      System.out.println("unrecognized command: " + cmd);
    }

    System.exit(0);
  }

  public static void parseArgs(String args[]) throws java.io.IOException {

    parser.acceptsAll(asList("h", "?"), "show help then exit");
    OptionSpec<String> CMD = parser.accepts("c", "command").withRequiredArg().ofType(String.class);
    OptionSpec<String> LOGIN =
        parser.accepts("u", "LoginId").withRequiredArg().ofType(String.class);
    OptionSpec<String> PASSWORD =
        parser.accepts("p", "password").withRequiredArg().ofType(String.class);
    OptionSpec<String> ISSUER =
        parser.accepts("i", "IssuerDN").withRequiredArg().ofType(String.class);
    OptionSpec<String> SUBJECT =
        parser.accepts("s", "SubjectDN").withRequiredArg().ofType(String.class);
    OptionSpec<String> CONTEXT =
        parser
            .accepts("C", "context:UNITTEST,DEVELOPMENT,SDK,PRODUCTION")
            .withRequiredArg()
            .ofType(String.class);

    OptionSet options = parser.parse(args);

    // check for help
    if (options.has("?")) {
      parser.printHelpOn(System.out);
      System.exit(0);
    }
    if (options.has(CMD)) {
      cmd = options.valueOf(CMD);
    } else {
      System.out.println("a -c cmd argument is required");
      parser.printHelpOn(System.out);
      System.exit(0);
    }
    if (options.has(LOGIN)) {
      loginName = options.valueOf(LOGIN);
    }
    if (options.has(PASSWORD)) {
      password = options.valueOf(PASSWORD);
    }
    if (options.has(ISSUER)) {
      issuer = options.valueOf(ISSUER);
    }
    if (options.has(SUBJECT)) {
      subject = options.valueOf(SUBJECT);
    }
    if (options.has(CONTEXT)) {
      context = options.valueOf(CONTEXT);
      if (!context.equals("UNITTEST")
          && !context.equals("SDK")
          && !context.equals("DEVELOPMENT")
          && !context.equals("PRODUCTION")) {
        System.out.println("unrecognized CONTEXT value: " + context);
        System.exit(-1);
      }
    }
  }
}