Search in sources :

Example 81 with Predicate

use of com.google.common.base.Predicate in project aic-expresso by aic-sri-international.

the class SetOfArgumentTuplesForFunctionOccurringInExpression method compute.

public static Expression compute(Expression fName, FunctionType fType, Expression e) {
    List<Expression> unionArgs = new ArrayList<>();
    Predicate<Expression> isF = expr -> expr.equals(fName);
    Predicate<Expression> isFApplication = expr -> expr.hasFunctor(fName) && expr.numberOfArguments() == fType.getArity();
    computeUnionArgs(unionArgs, isF, fType, isFApplication, e);
    Expression result = makeUnion(unionArgs);
    return result;
}
Also used : CountingFormula(com.sri.ai.expresso.api.CountingFormula) LambdaExpression(com.sri.ai.expresso.api.LambdaExpression) SubExpressionsDepthFirstIterator(com.sri.ai.expresso.helper.SubExpressionsDepthFirstIterator) Type(com.sri.ai.expresso.api.Type) ForAll(com.sri.ai.grinder.sgdpllt.library.boole.ForAll) Expressions(com.sri.ai.expresso.helper.Expressions) Expression(com.sri.ai.expresso.api.Expression) ExtensionalSets(com.sri.ai.grinder.sgdpllt.library.set.extensional.ExtensionalSets) IntensionalSet(com.sri.ai.expresso.api.IntensionalSet) Collectors(java.util.stream.Collectors) IfThenElse(com.sri.ai.grinder.sgdpllt.library.controlflow.IfThenElse) QuantifiedExpression(com.sri.ai.expresso.api.QuantifiedExpression) ArrayList(java.util.ArrayList) QuantifiedExpressionWithABody(com.sri.ai.expresso.api.QuantifiedExpressionWithABody) FunctionType(com.sri.ai.expresso.type.FunctionType) List(java.util.List) ThereExists(com.sri.ai.grinder.sgdpllt.library.boole.ThereExists) Predicate(com.google.common.base.Predicate) IndexExpressionsSet(com.sri.ai.expresso.api.IndexExpressionsSet) Util(com.sri.ai.util.Util) FunctorConstants(com.sri.ai.grinder.sgdpllt.library.FunctorConstants) Sets(com.sri.ai.grinder.sgdpllt.library.set.Sets) LambdaExpression(com.sri.ai.expresso.api.LambdaExpression) Expression(com.sri.ai.expresso.api.Expression) QuantifiedExpression(com.sri.ai.expresso.api.QuantifiedExpression) ArrayList(java.util.ArrayList)

Example 82 with Predicate

use of com.google.common.base.Predicate in project cdap by caskdata.

the class ExplodeJarHttpHandler method init.

@Override
public void init(HandlerContext context) {
    super.init(context);
    // Setup program jar for serving
    try {
        File jarFile = new File(jarLocation.toURI());
        baseDir = Files.createTempDir();
        cannonicalBaseDir = baseDir.getCanonicalPath();
        int numFiles = JarExploder.explode(jarFile, baseDir, EXPLODE_FILTER);
        File serveDir = new File(baseDir, Constants.Webapp.WEBAPP_DIR);
        Predicate<String> fileExists = new Predicate<String>() {

            @Override
            public boolean apply(@Nullable String file) {
                return file != null && new File(file).exists();
            }
        };
        servePathGenerator = new ServePathGenerator(serveDir.getAbsolutePath(), fileExists);
        LOG.info("Exploded {} files from jar {}", numFiles, jarFile.getAbsolutePath());
    } catch (Throwable t) {
        LOG.error("Got exception: ", t);
        throw Throwables.propagate(t);
    }
}
Also used : File(java.io.File) Nullable(javax.annotation.Nullable) Predicate(com.google.common.base.Predicate)

Example 83 with Predicate

use of com.google.common.base.Predicate in project cdap by caskdata.

the class IntactJarHttpHandler method init.

@Override
public void init(HandlerContext context) {
    super.init(context);
    try {
        jarFile = new JarFile(new File(jarLocation.toURI()));
        Predicate<String> fileExists = new Predicate<String>() {

            @Override
            public boolean apply(String file) {
                return file != null && jarFile.getJarEntry(file) != null;
            }
        };
        servePathGenerator = new ServePathGenerator(Constants.Webapp.WEBAPP_DIR, fileExists);
    } catch (IOException e) {
        LOG.error("Got exception: ", e);
        throw Throwables.propagate(e);
    }
}
Also used : IOException(java.io.IOException) JarFile(java.util.jar.JarFile) JarFile(java.util.jar.JarFile) File(java.io.File) Predicate(com.google.common.base.Predicate)

Example 84 with Predicate

use of com.google.common.base.Predicate in project cdap by caskdata.

the class DistributedProgramRuntimeService method list.

@Override
public synchronized Map<RunId, RuntimeInfo> list(ProgramType type) {
    Map<RunId, RuntimeInfo> result = Maps.newHashMap();
    result.putAll(super.list(type));
    // Table holds the Twill RunId and TwillController associated with the program matching the input type
    Table<ProgramId, RunId, TwillController> twillProgramInfo = HashBasedTable.create();
    // Goes through all live application and fill the twillProgramInfo table
    for (TwillRunner.LiveInfo liveInfo : twillRunner.lookupLive()) {
        String appName = liveInfo.getApplicationName();
        ProgramId programId = TwillAppNames.fromTwillAppName(appName, false);
        if (programId == null) {
            continue;
        }
        if (!type.equals(programId.getType())) {
            continue;
        }
        for (TwillController controller : liveInfo.getControllers()) {
            RunId twillRunId = controller.getRunId();
            if (isTwillRunIdCached(twillRunId)) {
                continue;
            }
            twillProgramInfo.put(programId, twillRunId, controller);
        }
    }
    if (twillProgramInfo.isEmpty()) {
        return ImmutableMap.copyOf(result);
    }
    final Set<RunId> twillRunIds = twillProgramInfo.columnKeySet();
    Collection<RunRecordMeta> activeRunRecords = store.getRuns(ProgramRunStatus.RUNNING, new Predicate<RunRecordMeta>() {

        @Override
        public boolean apply(RunRecordMeta record) {
            return record.getTwillRunId() != null && twillRunIds.contains(org.apache.twill.internal.RunIds.fromString(record.getTwillRunId()));
        }
    }).values();
    for (RunRecordMeta record : activeRunRecords) {
        String twillRunId = record.getTwillRunId();
        if (twillRunId == null) {
            // This is unexpected. Just log and ignore the run record
            LOG.warn("No twill runId for in run record {}.", record);
            continue;
        }
        RunId twillRunIdFromRecord = org.apache.twill.internal.RunIds.fromString(twillRunId);
        // Get the CDAP RunId from RunRecord
        RunId runId = RunIds.fromString(record.getPid());
        // Get the Program and TwillController for the current twillRunId
        Map<ProgramId, TwillController> mapForTwillId = twillProgramInfo.columnMap().get(twillRunIdFromRecord);
        Map.Entry<ProgramId, TwillController> entry = mapForTwillId.entrySet().iterator().next();
        // Create RuntimeInfo for the current Twill RunId
        RuntimeInfo runtimeInfo = createRuntimeInfo(entry.getKey(), entry.getValue(), runId);
        if (runtimeInfo != null) {
            result.put(runId, runtimeInfo);
            updateRuntimeInfo(type, runId, runtimeInfo);
        } else {
            LOG.warn("Unable to find program {} {}", type, entry.getKey());
        }
    }
    return ImmutableMap.copyOf(result);
}
Also used : SimpleRuntimeInfo(co.cask.cdap.internal.app.runtime.service.SimpleRuntimeInfo) TwillRunner(org.apache.twill.api.TwillRunner) RunRecordMeta(co.cask.cdap.internal.app.store.RunRecordMeta) ProgramId(co.cask.cdap.proto.id.ProgramId) Predicate(com.google.common.base.Predicate) TwillController(org.apache.twill.api.TwillController) RunId(org.apache.twill.api.RunId) Map(java.util.Map) ImmutableMap(com.google.common.collect.ImmutableMap)

Example 85 with Predicate

use of com.google.common.base.Predicate in project cdap by caskdata.

the class ServePathGeneratorTest method testGetServePath.

@Test
public void testGetServePath() throws Exception {
    URL jarUrl = getClass().getResource("/CountRandomWebapp-localhost.jar");
    Assert.assertNotNull(jarUrl);
    final JarResources jarResources = new JarResources(new LocalLocationFactory().create(jarUrl.toURI()));
    Predicate<String> fileExists = new Predicate<String>() {

        @Override
        public boolean apply(@Nullable String file) {
            return file != null && jarResources.getResource(file) != null;
        }
    };
    ServePathGenerator servePathGenerator = new ServePathGenerator(Constants.Webapp.WEBAPP_DIR, fileExists);
    Assert.assertEquals("/webapp/127.0.0.1:20000/netlens/src/index.html", servePathGenerator.getServePath("127.0.0.1:20000", "/netlens"));
    Assert.assertEquals("/webapp/127.0.0.1:20000/netlens/src/index.html", servePathGenerator.getServePath("127.0.0.1:20000", "/netlens/index.html"));
    Assert.assertEquals("/webapp/127.0.0.1:20000/netlens/src/index.html", servePathGenerator.getServePath("127.0.0.1:20000", "/netlens/"));
    Assert.assertEquals("/webapp/127.0.0.1:20000/netlens/src/index.html", servePathGenerator.getServePath("127.0.0.1:20000", "/netlens/"));
    Assert.assertEquals("/webapp/default/src/index.html", servePathGenerator.getServePath("127.0.0.1:30000", "/"));
    Assert.assertEquals("/webapp/default/src/index.html", servePathGenerator.getServePath("127.0.0.1:30000", "/index.html"));
    Assert.assertEquals("/webapp/127.0.0.1:20000/src/netlens/2.txt", servePathGenerator.getServePath("127.0.0.1:20000", "netlens/2.txt"));
    Assert.assertEquals("/webapp/default/netlens/src/1.txt", servePathGenerator.getServePath("127.0.0.1:80", "/netlens/1.txt?count=100"));
    Assert.assertEquals("/webapp/default/netlens/src/data/data.txt", servePathGenerator.getServePath("127.0.0.1:30000", "/netlens/data/data.txt"));
    Assert.assertEquals("/v3/apps?count=10", servePathGenerator.getServePath("127.0.0.1:30000", "/netlens/v3/apps?count=10"));
    Assert.assertEquals("/v3/apps?count=10", servePathGenerator.getServePath("127.0.0.1:30000", "/v3/apps?count=10"));
    Assert.assertEquals("/status", servePathGenerator.getServePath("127.0.0.1:30000", "/netlens/status"));
    Assert.assertEquals("/status", servePathGenerator.getServePath("127.0.0.1:30000", "/status"));
    servePathGenerator = new ServePathGenerator(Constants.Webapp.WEBAPP_DIR + "/", fileExists);
    Assert.assertEquals("/webapp/www.abc.com:80/geo/src/data/data.txt", servePathGenerator.getServePath("www.abc.com", "/geo/data/data.txt"));
    Assert.assertEquals("/webapp/www.abc.com:80/geo/src/data/data.txt", servePathGenerator.getServePath("www.abc.com:80", "/geo/data/data.txt"));
    Assert.assertEquals("/webapp/default/netlens/src/data/data.txt", servePathGenerator.getServePath("www.abc.com:30000", "/netlens/data/data.txt"));
    Assert.assertEquals("/geo/data/data.txt", servePathGenerator.getServePath("www.abc.com:30000", "/geo/data/data.txt"));
}
Also used : LocalLocationFactory(org.apache.twill.filesystem.LocalLocationFactory) URL(java.net.URL) JarResources(co.cask.cdap.common.lang.jar.JarResources) Nullable(javax.annotation.Nullable) Predicate(com.google.common.base.Predicate) Test(org.junit.Test)

Aggregations

Predicate (com.google.common.base.Predicate)217 List (java.util.List)37 Test (org.junit.Test)37 ArrayList (java.util.ArrayList)34 Nullable (javax.annotation.Nullable)33 Map (java.util.Map)24 UUID (java.util.UUID)21 IOException (java.io.IOException)20 File (java.io.File)18 HashMap (java.util.HashMap)15 Set (java.util.Set)14 Test (org.testng.annotations.Test)14 ImmutableList (com.google.common.collect.ImmutableList)13 Collection (java.util.Collection)11 DateTime (org.joda.time.DateTime)9 BigDecimal (java.math.BigDecimal)8 Path (javax.ws.rs.Path)8 Expression (com.sri.ai.expresso.api.Expression)7 Util (com.sri.ai.util.Util)7 XtextResource (org.eclipse.xtext.resource.XtextResource)7