private void testExpandWildcardUri(String uriPrefix) {
   Kernel.getKernel().restart();
   Kernel.initBootstrap();
   int num = 9;
   for (int i = 0; i < num; i++) {
     Kernel.getJar().putJar(ContextFactory.getKernelUser(), uriPrefix + i, new byte[0]);
   }
   KernelScript ks = new KernelScript();
   ks.setCallingContext(ContextFactory.getKernelUser());
   List<String> ret = JarUtils.expandWildcardUri(ks, uriPrefix + "*");
   assertFalse(ret.isEmpty());
   for (int i = 0; i < num; i++) {
     assertEquals(new RaptureURI(uriPrefix + i, Scheme.JAR).toString(), ret.get(i));
   }
 }
/**
 * @author bardhi
 * @since 4/23/15.
 */
public class StorableRepoCacheTest {
  private static final CallingContext CONTEXT = ContextFactory.getKernelUser();

  private static final String URI = "//someRepo";

  @Before
  public void setUp() throws Exception {
    Kernel.initBootstrap();
    Kernel.getDoc().createDocRepo(CONTEXT, URI, "NREP {} USING MEMORY {}");
    Kernel.getIndex().createIndex(CONTEXT, URI, "field1($0) string, field2(test) string");
  }

  @After
  public void tearDown() throws Exception {
    Kernel.getDoc().deleteDocRepo(CONTEXT, URI);
    Kernel.getIndex().deleteIndex(CONTEXT, URI);
  }

  @Test
  public void testWithIndex() throws Exception {
    Repository repo = Kernel.INSTANCE.getRepo(URI);
    assertTrue(repo.hasIndexProducer());
  }

  @Test
  public void testNoIndex() throws Exception {
    Optional<Repository> repo = Kernel.INSTANCE.getStorableRepo(URI, null);
    assertFalse(repo.get().hasIndexProducer());
  }
}
 public EmailAlerter(String templateName) {
   String templateJson =
       Kernel.getSys()
           .retrieveSystemConfig(
               ContextFactory.getKernelUser(), "CONFIG", TEMPLATE_URI + templateName);
   this.emailTemplate = JacksonUtil.objectFromJson(templateJson, EmailTemplate.class);
 }
Beispiel #4
0
 public static SMTPConfig getSMTPConfig() {
   String configString =
       Kernel.getSys()
           .retrieveSystemConfig(ContextFactory.getKernelUser(), "CONFIG", SMTP_CONFIG_URL);
   if (StringUtils.isBlank(configString)) {
     throw RaptureExceptionFactory.create("No SMTP configured");
   }
   return JacksonUtil.objectFromJson(configString, SMTPConfig.class);
 }
Beispiel #5
0
 public static ILockingHandler getLockHandler(String providerURI) {
   if (lockCache.containsKey(providerURI)) {
     return lockCache.get(providerURI);
   }
   RaptureLockConfig config =
       Kernel.getLock().getLockManagerConfig(ContextFactory.getKernelUser(), providerURI);
   ILockingHandler ret = createLock(config.getConfig());
   lockCache.put(providerURI, ret);
   return ret;
 }
 private RapturePipelineTask createTask() {
   RapturePipelineTask task = new RapturePipelineTask();
   Worker worker = new Worker();
   worker.setPriority(2);
   task.setPriority(worker.getPriority());
   task.setCategoryList(ImmutableList.of("cat"));
   task.addMimeObject(worker);
   task.setContentType(MimeDecisionProcessAdvance.getMimeType());
   task.initTask();
   Kernel.getPipeline().publishMessageToCategory(ContextFactory.getKernelUser(), task);
   return task;
 }
Beispiel #7
0
  @Override
  public Boolean writeLog(String category, int level, String message, String user) {
    StringBuilder logMessage = new StringBuilder();
    logMessage.append(df.print(DateTime.now()));
    logMessage.append(" ");
    logMessage.append(message);
    logMessage.append("\n");

    String docPath = blobPrefix;
    RaptureURI uri = RaptureURI.builder(Scheme.BLOB, blobUri).docPath(docPath).build();
    Kernel.getBlob()
        .getTrusted()
        .appendToBlobLower(
            ContextFactory.getKernelUser(),
            uri.toString(),
            logMessage.toString().getBytes(),
            "text/plain");
    return true;
  }
Beispiel #8
0
  @Override
  public List<AuditLogEntry> getRecentEntries(int count) {
    String docPath = blobPrefix;
    RaptureURI uri = RaptureURI.builder(Scheme.BLOB, blobUri).docPath(docPath).build();
    CallingContext context = ContextFactory.getKernelUser();
    BlobApiImpl blobApi = Kernel.getBlob().getTrusted();

    ArrayList<AuditLogEntry> ret = new ArrayList<AuditLogEntry>();
    BlobContainer content = blobApi.getBlob(context, uri.toString());
    if (content != null) {
      addContentToList(content, ret);
      return (ret.size() > count) ? ret.subList(ret.size() - count, ret.size()) : ret;
    } else {
      // get children blobs, eg. get logs for all steps of a work order
      Map<String, RaptureFolderInfo> childrenMap =
          blobApi.listBlobsByUriPrefix(context, uri.toString(), 1);

      if (childrenMap != null) {
        for (RaptureFolderInfo child : childrenMap.values()) {
          if (child.isFolder()) {
            continue;
          }
          String childUri = uri.getFullPath() + "/" + child.getName();
          content = blobApi.getBlob(context, childUri);
          addContentToList(content, ret, true);
          if (ret.size() >= count) {
            break;
          }
        }
      }
    }
    // sort audit log entries by time
    Collections.sort(
        ret,
        new Comparator<AuditLogEntry>() {
          @Override
          public int compare(AuditLogEntry o1, AuditLogEntry o2) {
            return o1.getWhen().compareTo(o2.getWhen());
          }
        });
    return (ret.size() > count) ? ret.subList(0, count) : ret;
  }
public class ReflexParamsTest {

  private static CallingContext ctx = ContextFactory.getKernelUser();

  private String uri = "//reflexParamsTest";
  private String scr = "thisDoc1";

  @After
  public void cleanUp() {
    Kernel.getDoc().deleteDocRepo(ctx, uri);
  }

  @Before
  public void setup() {
    Kernel.initBootstrap();
    if (!Kernel.getDoc().docRepoExists(ctx, uri)) {
      Kernel.getDoc().createDocRepo(ctx, uri, "NREP {} USING MEMORY {}");
    }
    if (Kernel.getScript().doesScriptExist(ctx, uri + "/" + scr))
      Kernel.getScript().deleteScript(ctx, uri + "/" + scr);

    Kernel.getScript()
        .createScript(
            ctx,
            uri + "/" + scr,
            RaptureScriptLanguage.REFLEX,
            RaptureScriptPurpose.PROGRAM,
            "if defined(_params) do \n"
                + "  println(\"params is defined \" + _params); return \"def\";\n"
                + "else do \n"
                + "  println(\"params is undefined\"); return \"notdef\";\n"
                + "end");
  }

  @Test
  public void testParamsNotDefined() {
    String retval =
        Kernel.getScript().runScript(ctx, uri + "/" + scr, new HashMap<String, String>());
    assertEquals("notdef", retval);
  }
}
  @Before
  public void setup() {
    sdf.setTimeZone(new SimpleTimeZone(0, "GMT"));
    sdf.applyPattern("dd MMM yyyy HH:mm:ss z");

    CallingContext ctx = ContextFactory.getKernelUser();

    try {
      Kernel.initBootstrap(null, null, true);

      Kernel.getPipeline().getTrusted().registerServerCategory(ctx, "alpha", "Primary servers");
      Kernel.getPipeline().getTrusted().registerServerCategory(ctx, "beta", "Secondary servers");

      Kernel.getPipeline().registerExchangeDomain(ctx, "//main", "EXCHANGE {} USING MEMORY {}");

      RaptureExchange exchange = new RaptureExchange();
      exchange.setName("kernel");
      exchange.setExchangeType(RaptureExchangeType.FANOUT);
      exchange.setDomain("main");

      List<RaptureExchangeQueue> queues = new ArrayList<RaptureExchangeQueue>();
      RaptureExchangeQueue queue = new RaptureExchangeQueue();
      queue.setName("default");
      queue.setRouteBindings(new ArrayList<String>());
      queues.add(queue);

      exchange.setQueueBindings(queues);

      Kernel.getPipeline().getTrusted().registerPipelineExchange(ctx, "kernel", exchange);
      Kernel.getPipeline().getTrusted().bindPipeline(ctx, "alpha", "kernel", "default");
      Kernel.setCategoryMembership("alpha");

    } catch (RaptureException e) {
      e.printStackTrace();
    }
  }
 @BeforeClass
 public static void beforeClass() {
   Kernel.initBootstrap();
   CONTEXT = ContextFactory.getKernelUser();
 }
 private static SMTPConfig getEmailConfig() {
   String configString =
       Kernel.getSys().retrieveSystemConfig(ContextFactory.getKernelUser(), "CONFIG", CONFIG_URI);
   return JacksonUtil.objectFromJson(configString, SMTPConfig.class);
 }
  @Test
  public void testKernelPipeline() {
    CallingContext ctx = ContextFactory.getKernelUser();

    // Create a script to run
    String script =
        "println('Hello from the Reflex script, value is ' + _params['value']);\n"
            + "_params['value'] = _params['value'] + '...';";
    Kernel.getScript()
        .createScript(
            ctx,
            "//test/hello",
            RaptureScriptLanguage.REFLEX,
            RaptureScriptPurpose.PROGRAM,
            script);

    List<String> dependents = new ArrayList<String>();
    dependents.add("testJob2");
    Map<String, String> testParams = new HashMap<String, String>();
    testParams.put("value", "42");
    Kernel.getSchedule().getTrusted().setJobLink(ctx, "//test/testJob", "//test/testJob2");
    Kernel.getSchedule()
        .createJob(
            ctx,
            "//test/testJob",
            "A test Job",
            "hello",
            "* * * * * *",
            "America/New_York",
            testParams,
            true);
    Kernel.getSchedule()
        .createJob(
            ctx,
            "//test/testJob2",
            "A dependent test Job",
            "hello",
            "* * * * * *",
            "America/New_York",
            new HashMap<String, String>(),
            false);
    // At least wait for a minute

    List<RaptureJobExec> execs = Kernel.getSchedule().getUpcomingJobs(ctx);
    for (RaptureJobExec e : execs) {
      System.out.println(
          "Job exec "
              + e.getStoragePath()
              + " will run at "
              + sdf.format(new Date(e.getExecTime())));
    }

    for (int i = 0; i < 6; i++) {
      try {
        // System.out.println("Checking job status");
        ScheduleManager.manageJobExecStatus();
        printStatusInformation();
        Thread.sleep(1000);
      } catch (InterruptedException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
      }
    }

    execs = Kernel.getSchedule().getJobExecs(ctx, "//authority/testJob", 0, 10, false);

    for (RaptureJobExec e : execs) {
      System.out.println(
          "Job exec "
              + e.getStoragePath()
              + " with exec time "
              + sdf.format(new Date(e.getExecTime()))
              + " with status "
              + e.getStatus());
    }
  }