use of org.dcache.srm.v2_2.TGroupPermission in project dcache by dCache.
the class LsFileRequest method convertFileMetaDataToTMetaDataPathDetail.
private TMetaDataPathDetail convertFileMetaDataToTMetaDataPathDetail(final URI path, final FileMetaData fmd, final boolean verbose) throws SRMException {
TMetaDataPathDetail metaDataPathDetail = new TMetaDataPathDetail();
metaDataPathDetail.setPath(getPath(path));
metaDataPathDetail.setLifetimeAssigned(-1);
metaDataPathDetail.setLifetimeLeft(-1);
metaDataPathDetail.setSize(new UnsignedLong(fmd.size));
if (fmd.isDirectory) {
metaDataPathDetail.setType(TFileType.DIRECTORY);
} else if (fmd.isLink) {
metaDataPathDetail.setType(TFileType.LINK);
} else if (fmd.isRegular) {
metaDataPathDetail.setType(TFileType.FILE);
} else {
LOGGER.debug("file type is Unknown");
}
if (verbose) {
// TODO: this needs to be rewritten to
// take the ACLs into account.
TUserPermission userPermission = new TUserPermission();
userPermission.setUserID(fmd.owner);
int userPerm = (fmd.permMode >> 6) & 7;
userPermission.setMode(maskToTPermissionMode(userPerm));
metaDataPathDetail.setOwnerPermission(userPermission);
TGroupPermission groupPermission = new TGroupPermission();
groupPermission.setGroupID(fmd.group);
int groupPerm = (fmd.permMode >> 3) & 7;
groupPermission.setMode(maskToTPermissionMode(groupPerm));
metaDataPathDetail.setGroupPermission(groupPermission);
metaDataPathDetail.setOtherPermission(maskToTPermissionMode(fmd.permMode & 7));
GregorianCalendar td = new GregorianCalendar();
td.setTimeInMillis(fmd.creationTime);
metaDataPathDetail.setCreatedAtTime(td);
td = new GregorianCalendar();
td.setTimeInMillis(fmd.lastModificationTime);
metaDataPathDetail.setLastModificationTime(td);
if (fmd.checksumType != null && fmd.checksumValue != null) {
metaDataPathDetail.setCheckSumType(fmd.checksumType);
metaDataPathDetail.setCheckSumValue(fmd.checksumValue);
}
metaDataPathDetail.setFileStorageType(TFileStorageType.PERMANENT);
if (!fmd.isPermanent) {
if (fmd.isPinned) {
metaDataPathDetail.setFileStorageType(TFileStorageType.DURABLE);
} else {
metaDataPathDetail.setFileStorageType(TFileStorageType.VOLATILE);
}
}
metaDataPathDetail.setFileLocality(fmd.locality);
if (fmd.retentionPolicyInfo != null) {
TAccessLatency al = fmd.retentionPolicyInfo.getAccessLatency();
TRetentionPolicy rp = fmd.retentionPolicyInfo.getRetentionPolicy();
metaDataPathDetail.setRetentionPolicyInfo(new TRetentionPolicyInfo(rp, al));
}
if (fmd.spaceTokens != null) {
if (fmd.spaceTokens.length > 0) {
ArrayOfString arrayOfSpaceTokens = new ArrayOfString(new String[fmd.spaceTokens.length]);
for (int st = 0; st < fmd.spaceTokens.length; st++) {
arrayOfSpaceTokens.setStringArray(st, String.valueOf(fmd.spaceTokens[st]));
}
metaDataPathDetail.setArrayOfSpaceTokens(arrayOfSpaceTokens);
}
}
}
metaDataPathDetail.setStatus(new TReturnStatus(TStatusCode.SRM_SUCCESS, null));
return metaDataPathDetail;
}
use of org.dcache.srm.v2_2.TGroupPermission in project dcache by dCache.
the class SRMSetPermissionClientV2 method start.
@Override
public void start() throws Exception {
checkCredentialValid();
URI uri = new URI(surl_string);
SrmSetPermissionRequest req = new SrmSetPermissionRequest();
req.setSURL(uri);
TPermissionType type = TPermissionType.fromString(configuration.getSetPermissionType());
req.setPermissionType(type);
TPermissionMode mode = null;
if (configuration.getSetOwnerPermissionMode() != null) {
mode = TPermissionMode.fromString(configuration.getSetOwnerPermissionMode());
}
req.setOwnerPermission(mode);
ArrayOfTGroupPermission arrayOfGroupPermissions = new ArrayOfTGroupPermission();
TGroupPermission[] grouppermissions = null;
if (configuration.getSetGroupPermissionMode() != null) {
grouppermissions = new TGroupPermission[1];
grouppermissions[0] = new TGroupPermission();
grouppermissions[0].setMode(TPermissionMode.fromString(configuration.getSetGroupPermissionMode()));
grouppermissions[0].setGroupID(DEFAULT_DUMMY_GROUP_ID);
}
arrayOfGroupPermissions.setGroupPermissionArray(grouppermissions);
req.setArrayOfGroupPermissions(arrayOfGroupPermissions);
TPermissionMode other = null;
if (configuration.getSetOtherPermissionMode() != null) {
other = TPermissionMode.fromString(configuration.getSetOtherPermissionMode());
}
req.setOtherPermission(other);
configuration.getStorageSystemInfo().ifPresent(req::setStorageSystemInfo);
SrmSetPermissionResponse resp = srm.srmSetPermission(req);
try {
TReturnStatus rs = resp.getReturnStatus();
if (rs.getStatusCode() != TStatusCode.SRM_SUCCESS) {
TStatusCode rc = rs.getStatusCode();
StringBuilder sb = new StringBuilder();
sb.append("Return code: ").append(rc.toString()).append("\n");
sb.append("Explanation: ").append(rs.getExplanation()).append("\n");
System.out.println(sb.toString());
System.exit(1);
} else {
System.exit(0);
}
} catch (Exception e) {
throw e;
}
}
use of org.dcache.srm.v2_2.TGroupPermission in project dcache by dCache.
the class SrmSetPermission method srmSetPermission.
private SrmSetPermissionResponse srmSetPermission() throws SRMException {
URI surl = URI.create(request.getSURL().toString());
FileMetaData fmd = storage.getFileMetaData(user, surl, false);
TPermissionType permissionType = request.getPermissionType();
if (permissionType == TPermissionType.REMOVE) {
/* [ SRM 2.2, 3.1.2 ]
*
* h) If TPermissionType is REMOVE, then the TPermissionMode must be ignored.
*
* We interpret this requirement to apply to user and group ACLs only. Since
* we don't support these, we don't support REMOVE.
*/
return getFailedResponse(ACL_NOT_SUPPORTED, TStatusCode.SRM_NOT_SUPPORTED);
}
TPermissionMode ownerMode = request.getOwnerPermission();
TPermissionMode otherMode = request.getOtherPermission();
TPermissionMode groupMode = null;
ArrayOfTUserPermission userPermissions = request.getArrayOfUserPermissions();
if (userPermissions != null) {
return getFailedResponse(ACL_NOT_SUPPORTED, TStatusCode.SRM_NOT_SUPPORTED);
}
ArrayOfTGroupPermission groupPermissions = request.getArrayOfGroupPermissions();
if (groupPermissions != null && groupPermissions.getGroupPermissionArray() != null) {
switch(groupPermissions.getGroupPermissionArray().length) {
case 0:
break;
case 1:
TGroupPermission permission = groupPermissions.getGroupPermissionArray()[0];
String group = permission.getGroupID();
if (!group.equals("-") && !group.equals(fmd.group)) {
/* The dash is a special dCache convention used by our own SRM client to
* indicate that the POSIX group permissions should be updated.
*/
return getFailedResponse(ACL_NOT_SUPPORTED, TStatusCode.SRM_NOT_SUPPORTED);
}
groupMode = permission.getMode();
break;
default:
return getFailedResponse(ACL_NOT_SUPPORTED, TStatusCode.SRM_NOT_SUPPORTED);
}
}
fmd.permMode = toNewPermissions(fmd.permMode, permissionType, ownerMode, groupMode, otherMode);
storage.setFileMetaData(user, surl, fmd);
return new SrmSetPermissionResponse(new TReturnStatus(TStatusCode.SRM_SUCCESS, null));
}
use of org.dcache.srm.v2_2.TGroupPermission in project dcache by dCache.
the class SRMGetPermissionClientV2 method start.
@Override
public void start() throws Exception {
checkCredentialValid();
ArrayOfAnyURI surlarray = new ArrayOfAnyURI();
URI[] uriarray = new URI[surl_string.length];
URI uri;
for (int i = 0; i < uriarray.length; i++) {
uri = new URI(surl_string[i]);
uriarray[i] = uri;
}
surlarray.setUrlArray(uriarray);
SrmGetPermissionRequest req = new SrmGetPermissionRequest();
req.setArrayOfSURLs(surlarray);
configuration.getStorageSystemInfo().ifPresent(req::setStorageSystemInfo);
SrmGetPermissionResponse resp = srm.srmGetPermission(req);
TReturnStatus rs = resp.getReturnStatus();
ArrayOfTPermissionReturn permissions = resp.getArrayOfPermissionReturns();
TPermissionReturn[] permissionarray = null;
if (permissions != null) {
permissionarray = permissions.getPermissionArray();
}
if (rs.getStatusCode() != TStatusCode.SRM_SUCCESS) {
TStatusCode rc = rs.getStatusCode();
StringBuilder sb = new StringBuilder();
sb.append("Return code: ").append(rc.toString()).append("\n");
sb.append("Explanation: ").append(rs.getExplanation()).append("\n");
System.out.println(sb.toString());
}
StringBuilder txt = new StringBuilder();
if (permissionarray == null) {
txt.append("permissions array is null\n");
System.out.println(txt.toString());
System.exit(1);
}
for (TPermissionReturn permission : permissionarray) {
txt.append("# file : ").append(permission.getSurl()).append("\n");
if (rs.getStatusCode() != TStatusCode.SRM_SUCCESS) {
txt.append("Return code: ").append(permission.getStatus().getStatusCode().toString()).append("\n");
txt.append("Explanation: ").append(permission.getStatus().getExplanation()).append("\n");
if (permission.getStatus().getStatusCode() != TStatusCode.SRM_SUCCESS) {
continue;
}
}
txt.append("# owner : ").append(permission.getOwner()).append("\n");
txt.append("owner:").append(permission.getOwner()).append(":").append(permission.getOwnerPermission().toString()).append("\n");
ArrayOfTUserPermission arrayOfUserPermissions = permission.getArrayOfUserPermissions();
if (arrayOfUserPermissions != null) {
TUserPermission[] userPermissionArray = arrayOfUserPermissions.getUserPermissionArray();
if (userPermissionArray != null) {
for (TUserPermission upr : userPermissionArray) {
if (upr != null) {
txt.append("user:").append(upr.getUserID()).append(":").append(upr.getMode().toString()).append("\n");
}
}
}
}
ArrayOfTGroupPermission arrayOfGroupPermissions = permission.getArrayOfGroupPermissions();
if (arrayOfGroupPermissions != null) {
TGroupPermission[] groupPermissionArray = arrayOfGroupPermissions.getGroupPermissionArray();
if (groupPermissionArray != null) {
for (TGroupPermission upr : groupPermissionArray) {
if (upr != null) {
txt.append("group:").append(upr.getGroupID()).append(":").append(upr.getMode().toString()).append("\n");
}
}
}
}
txt.append("other:").append(permission.getOtherPermission().toString()).append("\n");
}
System.out.println(txt.toString());
if (rs.getStatusCode() != TStatusCode.SRM_SUCCESS) {
System.exit(1);
} else {
System.exit(0);
}
}
use of org.dcache.srm.v2_2.TGroupPermission in project dcache by dCache.
the class SRMLsClientV2 method printResults.
public static void printResults(StringBuffer sb, TMetaDataPathDetail[] ta, int depth, String depthPrefix, boolean longFormat) {
if (ta != null) {
for (int i = 0; i < ta.length; i++) {
TMetaDataPathDetail metaDataPathDetail = ta[i];
if (metaDataPathDetail != null) {
if (metaDataPathDetail.getStatus().getStatusCode() == TStatusCode.fromString(TStatusCode._SRM_INVALID_PATH)) {
sb.append(TStatusCode._SRM_INVALID_PATH).append(" ").append(depthPrefix).append(" File/directory ").append(i).append(" ").append(metaDataPathDetail.getPath()).append(" does not exist. \n");
} else {
sb.append(depthPrefix);
UnsignedLong size = metaDataPathDetail.getSize();
if (size != null) {
sb.append(" ").append(size.longValue());
}
sb.append(" ").append(metaDataPathDetail.getPath());
if (metaDataPathDetail.getType() == TFileType.DIRECTORY) {
sb.append("/");
}
if (metaDataPathDetail.getStatus().getStatusCode() != TStatusCode.SRM_SUCCESS) {
sb.append(" (").append(metaDataPathDetail.getStatus().getStatusCode()).append(",").append(metaDataPathDetail.getStatus().getExplanation()).append(")");
}
sb.append('\n');
if (longFormat) {
sb.append(" space token(s) :");
if (metaDataPathDetail.getArrayOfSpaceTokens() != null) {
for (int j = 0; j < metaDataPathDetail.getArrayOfSpaceTokens().getStringArray().length; j++) {
if (j == metaDataPathDetail.getArrayOfSpaceTokens().getStringArray().length - 1) {
sb.append(metaDataPathDetail.getArrayOfSpaceTokens().getStringArray()[j]);
} else {
sb.append(metaDataPathDetail.getArrayOfSpaceTokens().getStringArray()[j]).append(",");
}
}
} else {
sb.append("none found");
}
sb.append('\n');
TFileStorageType stortype = metaDataPathDetail.getFileStorageType();
if (stortype != null) {
sb.append(depthPrefix);
sb.append(" storage type:").append(stortype.getValue());
sb.append('\n');
} else {
sb.append(" type: null");
sb.append('\n');
}
TRetentionPolicyInfo rpi = metaDataPathDetail.getRetentionPolicyInfo();
if (rpi != null) {
TRetentionPolicy rt = rpi.getRetentionPolicy();
if (rt != null) {
sb.append(depthPrefix);
sb.append(" retention policy:").append(rt.getValue());
sb.append('\n');
} else {
sb.append(" retention policy: null");
sb.append('\n');
}
TAccessLatency al = rpi.getAccessLatency();
if (al != null) {
sb.append(depthPrefix);
sb.append(" access latency:").append(al.getValue());
sb.append('\n');
} else {
sb.append(" access latency: null");
sb.append('\n');
}
} else {
sb.append(" retentionpolicyinfo : null");
sb.append('\n');
}
TFileLocality locality = metaDataPathDetail.getFileLocality();
if (locality != null) {
sb.append(depthPrefix);
sb.append(" locality:").append(locality.getValue());
sb.append('\n');
} else {
sb.append(" locality: null");
sb.append('\n');
}
if (metaDataPathDetail.getCheckSumValue() != null) {
sb.append(depthPrefix).append(" - Checksum value: ").append(metaDataPathDetail.getCheckSumValue()).append('\n');
}
if (metaDataPathDetail.getCheckSumType() != null) {
sb.append(depthPrefix).append(" - Checksum type: ").append(metaDataPathDetail.getCheckSumType()).append('\n');
}
SimpleDateFormat df = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss");
FieldPosition tfp = new FieldPosition(DateFormat.FULL);
if (metaDataPathDetail.getOwnerPermission() != null) {
TUserPermission up = metaDataPathDetail.getOwnerPermission();
sb.append(depthPrefix).append(" UserPermission:");
sb.append(" uid=").append(up.getUserID());
sb.append(" Permissions");
sb.append(up.getMode().getValue());
sb.append('\n');
}
if (metaDataPathDetail.getGroupPermission() != null) {
TGroupPermission gp = metaDataPathDetail.getGroupPermission();
sb.append(depthPrefix).append(" GroupPermission:");
sb.append(" gid=").append(gp.getGroupID());
sb.append(" Permissions");
sb.append(gp.getMode().getValue());
sb.append('\n');
}
if (metaDataPathDetail.getOtherPermission() != null) {
sb.append(depthPrefix).append(" WorldPermission: ");
sb.append(metaDataPathDetail.getOtherPermission().getValue());
sb.append('\n');
}
if (metaDataPathDetail.getCreatedAtTime() != null) {
Date tdate = metaDataPathDetail.getCreatedAtTime().getTime();
if (tdate != null) {
StringBuffer dsb = new StringBuffer();
df.format(tdate, dsb, tfp);
sb.append(depthPrefix).append("created at:").append(dsb);
sb.append('\n');
}
}
if (metaDataPathDetail.getLastModificationTime() != null) {
Date tdate = metaDataPathDetail.getLastModificationTime().getTime();
if (tdate != null) {
StringBuffer dsb = new StringBuffer();
df.format(tdate, dsb, tfp);
sb.append(depthPrefix);
sb.append("modified at:").append(dsb);
sb.append('\n');
}
}
if (metaDataPathDetail.getLifetimeAssigned() != null) {
sb.append(depthPrefix).append(" - Assigned lifetime (in seconds): ").append(metaDataPathDetail.getLifetimeAssigned()).append('\n');
}
if (metaDataPathDetail.getLifetimeLeft() != null) {
sb.append(depthPrefix).append(" - Lifetime left (in seconds): ").append(metaDataPathDetail.getLifetimeLeft()).append('\n');
}
sb.append(depthPrefix).append(" - Original SURL: ").append(metaDataPathDetail.getPath()).append('\n').append(" - Status: ").append(metaDataPathDetail.getStatus().getExplanation()).append('\n').append(" - Type: ").append(metaDataPathDetail.getType()).append('\n');
}
if (metaDataPathDetail.getArrayOfSubPaths() != null) {
TMetaDataPathDetail[] subpaths = metaDataPathDetail.getArrayOfSubPaths().getPathDetailArray();
if (subpaths == ta) {
sb.append(depthPrefix).append(" circular subpath reference !!!");
} else {
printResults(sb, subpaths, depth + 1, depthPrefix + " ", longFormat);
}
}
}
}
}
}
}
Aggregations