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;
}
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);
}
}
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);
}
}
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);
}
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"));
}
Aggregations