use of org.platformlayer.ops.filesystem.FilesystemInfo in project platformlayer by platformlayer.
the class OpsTargetBase method getFilesystemInfoDir.
@Override
public List<FilesystemInfo> getFilesystemInfoDir(File path) throws OpsException {
List<FilesystemInfo> fsInfoList = doFind(path, 1);
if (fsInfoList == null) {
return Collections.emptyList();
}
List<FilesystemInfo> ret = Lists.newArrayList();
for (FilesystemInfo fsInfo : fsInfoList) {
if (fsInfo.depth == 0) {
continue;
}
ret.add(fsInfo);
}
return ret;
}
use of org.platformlayer.ops.filesystem.FilesystemInfo in project platformlayer by platformlayer.
the class OpsTargetBase method doFind.
protected List<FilesystemInfo> doFind(File path, Integer maxDepth) throws OpsException {
Command command = maybeSudo("find");
String[] fields = new String[] { "T@", "s", "m", "u", "g", "n", "p", "l", "y", "d" };
StringBuilder format = new StringBuilder();
for (int i = 0; i < fields.length; i++) {
if (i != 0) {
format.append("\\t");
}
format.append("%");
format.append(fields[i]);
}
format.append("\\n");
command.addFile(path);
if (maxDepth != null) {
command.addLiteral("-maxdepth");
command.addQuoted(maxDepth.toString());
}
command.addLiteral("-printf");
command.addQuoted(format.toString());
ProcessExecution execution;
try {
execution = executeCommand(command);
} catch (ProcessExecutionException e) {
execution = e.getExecution();
if (execution != null && execution.getExitCode() == 1 && execution.getStdErr().contains("No such file or directory")) {
return null;
}
throw new OpsException("Error executing find command", e);
}
List<FilesystemInfo> filesystemInfos = Lists.newArrayList();
String stdout = execution.getStdOut();
for (String line : stdout.split("\n")) {
String[] fieldValues = line.split("\t");
if (fieldValues.length != fields.length) {
throw new OpsException("Cannot parse line: " + line);
}
FilesystemInfo filesystemInfo = new FilesystemInfo();
for (int i = 0; i < fieldValues.length; i++) {
String field = fields[i];
String fieldValue = fieldValues[i];
if (field.equals("u")) {
filesystemInfo.owner = fieldValue;
} else if (field.equals("g")) {
filesystemInfo.group = fieldValue;
} else if (field.equals("n")) {
filesystemInfo.links = fieldValue;
} else if (field.equals("m")) {
filesystemInfo.mode = fieldValue;
} else if (field.equals("p")) {
filesystemInfo.name = fieldValue;
} else if (field.equals("s")) {
filesystemInfo.size = Long.parseLong(fieldValue);
} else if (field.equals("y")) {
filesystemInfo.type = fieldValue;
} else if (field.equals("l")) {
if (!Strings.isNullOrEmpty(fieldValue)) {
filesystemInfo.symlinkTarget = fieldValue;
}
} else if (field.equals("T@")) {
filesystemInfo.date = fieldValue;
} else if (field.equals("d")) {
filesystemInfo.depth = Integer.parseInt(fieldValue);
} else {
throw new IllegalStateException();
}
}
filesystemInfos.add(filesystemInfo);
}
return filesystemInfos;
}
use of org.platformlayer.ops.filesystem.FilesystemInfo in project platformlayer by platformlayer.
the class FilesystemBackedPool method release.
@Override
public void release(PlatformLayerKey owner, T item) throws OpsException {
File symlink = new File(assignedDir, toKey(item));
FilesystemInfo info = target.getFilesystemInfoFile(symlink);
if (info == null) {
throw new OpsException("Symlink not found");
}
if (!Objects.equal(info.symlinkTarget, toFile(owner).getAbsolutePath())) {
throw new OpsException("Resource not assigned to owner");
}
target.rm(symlink);
}
use of org.platformlayer.ops.filesystem.FilesystemInfo in project platformlayer by platformlayer.
the class MountCgroups method handler.
@Handler
public void handler() throws OpsException, IOException {
// TODO: Only if not installed
OpsTarget target = OpsContext.get().getInstance(OpsTarget.class);
File cgroupsFile = new File("/cgroup");
FilesystemInfo info = target.getFilesystemInfoFile(cgroupsFile);
if (info != null) {
// TODO: Better idempotency
return;
}
String fstabLine = "\ncgroup\t/cgroup\tcgroup\tdefaults\t0\t0";
File fstabFile = new File("/etc/fstab");
String fstab = target.readTextFile(fstabFile);
fstab += fstabLine;
FileUpload.upload(target, fstabFile, fstab);
target.mkdir(cgroupsFile);
Command mountCommand = Command.build("mount cgroup");
target.executeCommand(mountCommand);
// mkdir /cgroup
// echo -e "cgroup\t/cgroup\tcgroup\tdefaults\t0\t0" >> /etc/fstab
// mount cgroup
}
use of org.platformlayer.ops.filesystem.FilesystemInfo in project platformlayer by platformlayer.
the class FilesystemCasStore method checkDirectory.
private File checkDirectory(File base, Md5Hash hash, int splits) throws OpsException {
String relativePath = toRelativePath(hash, splits);
File seedFile = new File(base, relativePath);
FilesystemInfo seedFileInfo = host.getFilesystemInfoFile(seedFile);
if (seedFileInfo != null) {
Md5Hash seedFileHash = host.getFileHash(seedFile);
if (!seedFileHash.equals(hash)) {
log.warn("Hash mismatch on file: " + seedFile);
return null;
}
// For LRU
host.touchFile(seedFile);
return seedFile;
}
return null;
}
Aggregations