Search in sources :

Example 1 with TUserPermission

use of org.dcache.srm.v2_2.TUserPermission 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;
}
Also used : TRetentionPolicyInfo(org.dcache.srm.v2_2.TRetentionPolicyInfo) UnsignedLong(org.apache.axis.types.UnsignedLong) TReturnStatus(org.dcache.srm.v2_2.TReturnStatus) ArrayOfTMetaDataPathDetail(org.dcache.srm.v2_2.ArrayOfTMetaDataPathDetail) TMetaDataPathDetail(org.dcache.srm.v2_2.TMetaDataPathDetail) TRetentionPolicy(org.dcache.srm.v2_2.TRetentionPolicy) ArrayOfString(org.dcache.srm.v2_2.ArrayOfString) GregorianCalendar(java.util.GregorianCalendar) TAccessLatency(org.dcache.srm.v2_2.TAccessLatency) TUserPermission(org.dcache.srm.v2_2.TUserPermission) TGroupPermission(org.dcache.srm.v2_2.TGroupPermission)

Example 2 with TUserPermission

use of org.dcache.srm.v2_2.TUserPermission 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);
    }
}
Also used : SrmGetPermissionRequest(org.dcache.srm.v2_2.SrmGetPermissionRequest) SrmGetPermissionResponse(org.dcache.srm.v2_2.SrmGetPermissionResponse) TReturnStatus(org.dcache.srm.v2_2.TReturnStatus) ArrayOfTUserPermission(org.dcache.srm.v2_2.ArrayOfTUserPermission) ArrayOfTUserPermission(org.dcache.srm.v2_2.ArrayOfTUserPermission) TUserPermission(org.dcache.srm.v2_2.TUserPermission) URI(org.apache.axis.types.URI) ArrayOfAnyURI(org.dcache.srm.v2_2.ArrayOfAnyURI) TStatusCode(org.dcache.srm.v2_2.TStatusCode) ArrayOfTPermissionReturn(org.dcache.srm.v2_2.ArrayOfTPermissionReturn) TPermissionReturn(org.dcache.srm.v2_2.TPermissionReturn) ArrayOfTPermissionReturn(org.dcache.srm.v2_2.ArrayOfTPermissionReturn) ArrayOfTGroupPermission(org.dcache.srm.v2_2.ArrayOfTGroupPermission) TGroupPermission(org.dcache.srm.v2_2.TGroupPermission) ArrayOfTGroupPermission(org.dcache.srm.v2_2.ArrayOfTGroupPermission) ArrayOfAnyURI(org.dcache.srm.v2_2.ArrayOfAnyURI)

Example 3 with TUserPermission

use of org.dcache.srm.v2_2.TUserPermission 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);
                        }
                    }
                }
            }
        }
    }
}
Also used : TFileStorageType(org.dcache.srm.v2_2.TFileStorageType) UnsignedLong(org.apache.axis.types.UnsignedLong) TMetaDataPathDetail(org.dcache.srm.v2_2.TMetaDataPathDetail) TRetentionPolicy(org.dcache.srm.v2_2.TRetentionPolicy) TUserPermission(org.dcache.srm.v2_2.TUserPermission) FieldPosition(java.text.FieldPosition) Date(java.util.Date) TRetentionPolicyInfo(org.dcache.srm.v2_2.TRetentionPolicyInfo) TFileLocality(org.dcache.srm.v2_2.TFileLocality) TAccessLatency(org.dcache.srm.v2_2.TAccessLatency) TGroupPermission(org.dcache.srm.v2_2.TGroupPermission) SimpleDateFormat(java.text.SimpleDateFormat)

Example 4 with TUserPermission

use of org.dcache.srm.v2_2.TUserPermission in project dcache by dCache.

the class AxisSrmFileSystem method getPermissions.

@Nonnull
@Override
public TPermissionReturn[] getPermissions(URI... surls) throws RemoteException, SRMException {
    checkArgument(surls.length > 0);
    SrmGetPermissionResponse response = srm.srmGetPermission(new SrmGetPermissionRequest(null, new ArrayOfAnyURI(surls), null));
    TPermissionReturn[] permissionArray = response.getArrayOfPermissionReturns().getPermissionArray();
    if (permissionArray == null || permissionArray.length == 0) {
        checkSuccess(response.getReturnStatus(), TStatusCode.SRM_SUCCESS, TStatusCode.SRM_PARTIAL_SUCCESS);
        throw new SrmProtocolException("Server reply lacks permission array.");
    }
    checkSuccess(response.getReturnStatus(), TStatusCode.SRM_SUCCESS, TStatusCode.SRM_PARTIAL_SUCCESS, TStatusCode.SRM_FAILURE);
    // Simplify things for the caller
    for (TPermissionReturn permission : permissionArray) {
        if (permission.getArrayOfUserPermissions() == null) {
            permission.setArrayOfUserPermissions(new ArrayOfTUserPermission());
        }
        if (permission.getArrayOfUserPermissions().getUserPermissionArray() == null) {
            permission.getArrayOfUserPermissions().setUserPermissionArray(new TUserPermission[0]);
        }
        if (permission.getArrayOfGroupPermissions() == null) {
            permission.setArrayOfGroupPermissions(new ArrayOfTGroupPermission());
        }
        if (permission.getArrayOfGroupPermissions().getGroupPermissionArray() == null) {
            permission.getArrayOfGroupPermissions().setGroupPermissionArray(new TGroupPermission[0]);
        }
    }
    return permissionArray;
}
Also used : SrmGetPermissionRequest(org.dcache.srm.v2_2.SrmGetPermissionRequest) SrmGetPermissionResponse(org.dcache.srm.v2_2.SrmGetPermissionResponse) ArrayOfTUserPermission(org.dcache.srm.v2_2.ArrayOfTUserPermission) ArrayOfTGroupPermission(org.dcache.srm.v2_2.ArrayOfTGroupPermission) ArrayOfAnyURI(org.dcache.srm.v2_2.ArrayOfAnyURI) TPermissionReturn(org.dcache.srm.v2_2.TPermissionReturn) Nonnull(javax.annotation.Nonnull)

Aggregations

TGroupPermission (org.dcache.srm.v2_2.TGroupPermission)3 TUserPermission (org.dcache.srm.v2_2.TUserPermission)3 UnsignedLong (org.apache.axis.types.UnsignedLong)2 ArrayOfAnyURI (org.dcache.srm.v2_2.ArrayOfAnyURI)2 ArrayOfTGroupPermission (org.dcache.srm.v2_2.ArrayOfTGroupPermission)2 ArrayOfTUserPermission (org.dcache.srm.v2_2.ArrayOfTUserPermission)2 SrmGetPermissionRequest (org.dcache.srm.v2_2.SrmGetPermissionRequest)2 SrmGetPermissionResponse (org.dcache.srm.v2_2.SrmGetPermissionResponse)2 TAccessLatency (org.dcache.srm.v2_2.TAccessLatency)2 TMetaDataPathDetail (org.dcache.srm.v2_2.TMetaDataPathDetail)2 TPermissionReturn (org.dcache.srm.v2_2.TPermissionReturn)2 TRetentionPolicy (org.dcache.srm.v2_2.TRetentionPolicy)2 TRetentionPolicyInfo (org.dcache.srm.v2_2.TRetentionPolicyInfo)2 TReturnStatus (org.dcache.srm.v2_2.TReturnStatus)2 FieldPosition (java.text.FieldPosition)1 SimpleDateFormat (java.text.SimpleDateFormat)1 Date (java.util.Date)1 GregorianCalendar (java.util.GregorianCalendar)1 Nonnull (javax.annotation.Nonnull)1 URI (org.apache.axis.types.URI)1