Skip to content

Commit

Permalink
srm: reduce dependency on SrmDCacheConnector
Browse files Browse the repository at this point in the history
The SrmDCacheConnector class allows the Axis classes to discover the 
SRM instance, the Configuration instance, the back-end Storage 
instance.  This works by singleton anti-patterns using static class 
members and reflection.  It also requires that the Storage backend 
starts before the first Axis call, as the backend initialises the SRM, 
so populating the singleton instance.

Such approach is undesirable due to the fragile nature of the 
initialisation process, the use of reflection and the difficulties 
faced when testing classes that implement the singleton pattern.

Since future work will access the SRM instance from the spring 
framework.  The desire is to inject the three necessary objects 
(Configuration, SRM and Storage) directly, rather than via the 
SrmDCacheConnector class.

As a first step to removing SrmDCacheConnector completely, this patch 
refactors the Axis server objects to reduce their usage of 
SrmDCacheConnector.  In doing so, the SrmAuthorizer class was tidied up 
slightly to make it more readable.

Patch: http://rb.dcache.org/r/5076
Acked-by: Dmitry Litvintsev
Target: trunk
Require-notes: no
Require-book:no
  • Loading branch information
paulmillar committed Jan 11, 2013
1 parent 234ea6e commit 1d36f52
Show file tree
Hide file tree
Showing 3 changed files with 214 additions and 286 deletions.
46 changes: 26 additions & 20 deletions modules/srm/src/main/java/org/dcache/srm/server/SRMServerV1.java
Expand Up @@ -7,16 +7,16 @@

package org.dcache.srm.server;
import java.util.Collection;

import javax.naming.Context;
import javax.naming.InitialContext;

import org.dcache.auth.util.GSSUtils;
import org.dcache.commons.stats.RequestCounters;
import org.dcache.commons.stats.RequestExecutionTimeGauges;
import org.dcache.srm.SRM;
import org.dcache.srm.SRMAuthorizationException;
import org.dcache.srm.SRMUser;
import org.dcache.srm.client.ConvertUtil;
import org.dcache.srm.util.Configuration;
import org.dcache.srm.util.JDC;
import org.glite.voms.PKIVerifier;
import org.gridforum.jgss.ExtendedGSSContext;
Expand All @@ -28,9 +28,9 @@
public class SRMServerV1 implements org.dcache.srm.client.axis.ISRM_PortType{

public Logger log;
private SrmDCacheConnector srmConn;
private SrmAuthorizer srmAuth;
private PKIVerifier pkiVerifier;
private final SRM srm;
private final RequestCounters<String> srmServerCounters;
private final RequestExecutionTimeGauges<String> srmServerGauges;

Expand All @@ -56,20 +56,26 @@ public SRMServerV1() throws java.rmi.RemoteException {
log.error(error_details);
throw new java.rmi.RemoteException(error );
}
srmConn = SrmDCacheConnector.getInstance(srmConfigFile);
SrmDCacheConnector srmConn =
SrmDCacheConnector.getInstance(srmConfigFile);
if (srmConn == null) {
throw new java.rmi.RemoteException("Failed to get instance of srm." );
}

log.info(" initialize() got connector ="+srmConn);
// Set up the authorization service
srmAuth = new SrmAuthorizer(srmConn);

srm = srmConn.getSrm();
Configuration config = srm.getConfiguration();

srmAuth = new SrmAuthorizer(config.getAuthorization(),
srm.getRequestCredentialStorage(),
config.isClientDNSLookup());

// use default locations for cacerts and vomdsdir
pkiVerifier
= GSSUtils.getPkiVerifier(null,null, MDC.getCopyOfContextMap());
srmServerCounters = srmConn.getSrm().getSrmServerV1Counters();
srmServerGauges =
srmConn.getSrm().getSrmServerV1Gauges();
srmServerCounters = srm.getSrmServerV1Counters();
srmServerGauges = srm.getSrmServerV1Gauges();
}
catch ( java.rmi.RemoteException re) { throw re; }
catch ( Exception e) {
Expand Down Expand Up @@ -118,7 +124,7 @@ public org.dcache.srm.client.axis.RequestStatus put(java.lang.String[] arg0,
diskCacheV111.srm.RequestStatus requestStatus;
try {

requestStatus = srmConn.getSrm().put(user,requestCredential,arg0,arg1,arg2,arg3,arg4, userCred.clientHost);
requestStatus = srm.put(user,requestCredential,arg0,arg1,arg2,arg3,arg4, userCred.clientHost);
} catch(Exception e) {
log.error(e.toString());
throw new java.rmi.RemoteException("srm put failed", e);
Expand Down Expand Up @@ -162,7 +168,7 @@ public org.dcache.srm.client.axis.RequestStatus get(java.lang.String[] arg0, jav
diskCacheV111.srm.RequestStatus requestStatus;
try {

requestStatus = srmConn.getSrm().get(user,
requestStatus = srm.get(user,
requestCredential,
arg0,
arg1,
Expand Down Expand Up @@ -210,7 +216,7 @@ public org.dcache.srm.client.axis.RequestStatus copy(java.lang.String[] arg0, ja
diskCacheV111.srm.RequestStatus requestStatus;
try {

requestStatus = srmConn.getSrm().copy(user,
requestStatus = srm.copy(user,
requestCredential,
arg0,
arg1,
Expand Down Expand Up @@ -359,7 +365,7 @@ public org.dcache.srm.client.axis.RequestStatus setFileStatus(int arg0, int arg1
diskCacheV111.srm.RequestStatus requestStatus;
try {

requestStatus = srmConn.getSrm().setFileStatus(user,requestCredential,arg0,arg1,arg2);
requestStatus = srm.setFileStatus(user,requestCredential,arg0,arg1,arg2);
} catch(Exception e) {
log.error(e.toString());
throw new java.rmi.RemoteException("srm setFileStatus failed", e);
Expand Down Expand Up @@ -403,7 +409,7 @@ public org.dcache.srm.client.axis.RequestStatus getRequestStatus(int arg0) throw
diskCacheV111.srm.RequestStatus requestStatus;
try {

requestStatus = srmConn.getSrm().getRequestStatus(user,requestCredential,arg0);
requestStatus = srm.getRequestStatus(user,requestCredential,arg0);
} catch(Exception e) {
log.error(e.toString());
throw new java.rmi.RemoteException("srm getRequestStatus failed", e);
Expand Down Expand Up @@ -450,7 +456,7 @@ public org.dcache.srm.client.axis.FileMetaData[] getFileMetaData(
diskCacheV111.srm.FileMetaData[] fmdArray;
try {

fmdArray = srmConn.getSrm().getFileMetaData(user,requestCredential,arg0);
fmdArray = srm.getFileMetaData(user,requestCredential,arg0);
} catch(Exception e) {
log.error(e.toString());
throw new java.rmi.RemoteException("srm getFileMetaData failed", e);
Expand Down Expand Up @@ -495,7 +501,7 @@ public org.dcache.srm.client.axis.RequestStatus mkPermanent(java.lang.String[] a
diskCacheV111.srm.RequestStatus requestStatus;
try {

requestStatus = srmConn.getSrm().mkPermanent(user,requestCredential,arg0);
requestStatus = srm.mkPermanent(user,requestCredential,arg0);
} catch(Exception e) {
log.error(e.toString());
throw new java.rmi.RemoteException("srm mkPermanent failed", e);
Expand Down Expand Up @@ -538,7 +544,7 @@ public org.dcache.srm.client.axis.RequestStatus getEstGetTime(java.lang.String[]
diskCacheV111.srm.RequestStatus requestStatus;
try {

requestStatus = srmConn.getSrm().getEstGetTime(user,requestCredential,arg0,arg1);
requestStatus = srm.getEstGetTime(user,requestCredential,arg0,arg1);
} catch(Exception e) {
log.error(e.toString());
throw new java.rmi.RemoteException("srm getEstGetTime failed", e);
Expand Down Expand Up @@ -581,7 +587,7 @@ public org.dcache.srm.client.axis.RequestStatus getEstPutTime(java.lang.String[]
diskCacheV111.srm.RequestStatus requestStatus;
try {

requestStatus = srmConn.getSrm().getEstPutTime(user,requestCredential,arg0,arg1,arg2,arg3,arg4);
requestStatus = srm.getEstPutTime(user,requestCredential,arg0,arg1,arg2,arg3,arg4);
} catch(Exception e) {
log.error(e.toString());
throw new java.rmi.RemoteException("srm put failed", e);
Expand Down Expand Up @@ -623,7 +629,7 @@ public void advisoryDelete(java.lang.String[] arg0) throws java.rmi.RemoteExcept

try {

srmConn.getSrm().advisoryDelete(user,requestCredential,arg0);
srm.advisoryDelete(user,requestCredential,arg0);
} catch(Exception e) {
log.error(e.toString());
throw new java.rmi.RemoteException("srm advisoryDelete failed", e);
Expand Down Expand Up @@ -663,7 +669,7 @@ public java.lang.String[] getProtocols() throws java.rmi.RemoteException {

try {

return srmConn.getSrm().getProtocols(user,requestCredential);
return srm.getProtocols(user,requestCredential);
} catch(Exception e) {
log.error(e.toString());
throw new java.rmi.RemoteException("srm getProtocols failed", e);
Expand Down
130 changes: 28 additions & 102 deletions modules/srm/src/main/java/org/dcache/srm/server/SRMServerV2.java
Expand Up @@ -70,120 +70,40 @@ LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING

package org.dcache.srm.server;

import java.lang.reflect.Constructor;
import java.lang.reflect.Method;
import java.rmi.RemoteException;
import org.dcache.srm.SRM;
import org.dcache.srm.util.JDC;
import org.dcache.srm.v2_2.SrmAbortFilesRequest;
import org.dcache.srm.v2_2.SrmAbortFilesResponse;
import org.dcache.srm.v2_2.SrmAbortRequestRequest;
import org.dcache.srm.v2_2.SrmAbortRequestResponse;
import org.dcache.srm.v2_2.SrmBringOnlineRequest;
import org.dcache.srm.v2_2.SrmBringOnlineResponse;
import org.dcache.srm.v2_2.SrmChangeSpaceForFilesRequest;
import org.dcache.srm.v2_2.SrmChangeSpaceForFilesResponse;
import org.dcache.srm.v2_2.SrmCheckPermissionRequest;
import org.dcache.srm.v2_2.SrmCheckPermissionResponse;
import org.dcache.srm.v2_2.SrmCopyRequest;
import org.dcache.srm.v2_2.SrmCopyResponse;
import org.dcache.srm.v2_2.SrmExtendFileLifeTimeInSpaceRequest;
import org.dcache.srm.v2_2.SrmExtendFileLifeTimeInSpaceResponse;
import org.dcache.srm.v2_2.SrmExtendFileLifeTimeRequest;
import org.dcache.srm.v2_2.SrmExtendFileLifeTimeResponse;
import org.dcache.srm.v2_2.SrmGetPermissionRequest;
import org.dcache.srm.v2_2.SrmGetPermissionResponse;
import org.dcache.srm.v2_2.SrmGetRequestSummaryRequest;
import org.dcache.srm.v2_2.SrmGetRequestSummaryResponse;
import org.dcache.srm.v2_2.SrmGetRequestTokensRequest;
import org.dcache.srm.v2_2.SrmGetRequestTokensResponse;
import org.dcache.srm.v2_2.SrmGetSpaceMetaDataRequest;
import org.dcache.srm.v2_2.SrmGetSpaceMetaDataResponse;
import org.dcache.srm.v2_2.SrmGetSpaceTokensRequest;
import org.dcache.srm.v2_2.SrmGetSpaceTokensResponse;
import org.dcache.srm.v2_2.SrmGetTransferProtocolsRequest;
import org.dcache.srm.v2_2.SrmGetTransferProtocolsResponse;
import org.dcache.srm.v2_2.SrmLsRequest;
import org.dcache.srm.v2_2.SrmLsResponse;
import org.dcache.srm.v2_2.SrmMvRequest;
import org.dcache.srm.v2_2.SrmMvResponse;
import org.dcache.srm.v2_2.SrmPingRequest;
import org.dcache.srm.v2_2.SrmPingResponse;
import org.dcache.srm.v2_2.SrmPrepareToGetRequest;
import org.dcache.srm.v2_2.SrmPrepareToGetResponse;
import org.dcache.srm.v2_2.SrmPrepareToPutRequest;
import org.dcache.srm.v2_2.SrmPrepareToPutResponse;
import org.dcache.srm.v2_2.SrmPurgeFromSpaceRequest;
import org.dcache.srm.v2_2.SrmPurgeFromSpaceResponse;
import org.dcache.srm.v2_2.SrmPutDoneRequest;
import org.dcache.srm.v2_2.SrmPutDoneResponse;
import org.dcache.srm.v2_2.SrmReleaseFilesRequest;
import org.dcache.srm.v2_2.SrmReleaseFilesResponse;
import org.dcache.srm.v2_2.SrmReleaseSpaceRequest;
import org.dcache.srm.v2_2.SrmReleaseSpaceResponse;
import org.dcache.srm.v2_2.SrmReserveSpaceRequest;
import org.dcache.srm.v2_2.SrmReserveSpaceResponse;
import org.dcache.srm.v2_2.SrmResumeRequestRequest;
import org.dcache.srm.v2_2.SrmResumeRequestResponse;
import org.dcache.srm.v2_2.SrmRmRequest;
import org.dcache.srm.v2_2.SrmRmResponse;
import org.dcache.srm.v2_2.SrmRmdirRequest;
import org.dcache.srm.v2_2.SrmRmdirResponse;
import org.dcache.srm.v2_2.SrmMkdirRequest;
import org.dcache.srm.v2_2.SrmMkdirResponse;
import org.dcache.srm.v2_2.SrmSetPermissionRequest;
import org.dcache.srm.v2_2.SrmSetPermissionResponse;
import org.dcache.srm.v2_2.SrmStatusOfBringOnlineRequestRequest;
import org.dcache.srm.v2_2.SrmStatusOfBringOnlineRequestResponse;
import org.dcache.srm.v2_2.SrmStatusOfChangeSpaceForFilesRequestRequest;
import org.dcache.srm.v2_2.SrmStatusOfChangeSpaceForFilesRequestResponse;
import org.dcache.srm.v2_2.SrmStatusOfCopyRequestRequest;
import org.dcache.srm.v2_2.SrmStatusOfCopyRequestResponse;
import org.dcache.srm.v2_2.SrmStatusOfGetRequestRequest;
import org.dcache.srm.v2_2.SrmStatusOfGetRequestResponse;
import org.dcache.srm.v2_2.SrmStatusOfLsRequestRequest;
import org.dcache.srm.v2_2.SrmStatusOfLsRequestResponse;
import org.dcache.srm.v2_2.SrmStatusOfPutRequestRequest;
import org.dcache.srm.v2_2.SrmStatusOfPutRequestResponse;
import org.dcache.srm.v2_2.SrmStatusOfReserveSpaceRequestRequest;
import org.dcache.srm.v2_2.SrmStatusOfReserveSpaceRequestResponse;
import org.dcache.srm.v2_2.SrmStatusOfUpdateSpaceRequestRequest;
import org.dcache.srm.v2_2.SrmStatusOfUpdateSpaceRequestResponse;
import org.dcache.srm.v2_2.SrmSuspendRequestRequest;
import org.dcache.srm.v2_2.SrmSuspendRequestResponse;
import org.dcache.srm.v2_2.SrmUpdateSpaceRequest;
import org.dcache.srm.v2_2.SrmUpdateSpaceResponse;
import org.dcache.srm.v2_2.TStatusCode;
import org.dcache.srm.v2_2.TReturnStatus;
import java.util.Collection;
import javax.naming.Context;
import javax.naming.InitialContext;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.slf4j.MDC;

import java.lang.reflect.Method;
import java.lang.reflect.Constructor;
import org.dcache.auth.util.GSSUtils;
import org.dcache.commons.stats.RequestCounters;
import org.dcache.commons.stats.RequestExecutionTimeGauges;
import org.dcache.srm.AbstractStorageElement;
import org.dcache.srm.SRM;
import org.dcache.srm.SRMAuthorizationException;
import org.dcache.srm.SRMUser;
import org.dcache.srm.AbstractStorageElement;
import org.dcache.srm.request.RequestCredential;
import java.util.Collection;

import org.dcache.srm.util.Configuration;
import org.dcache.srm.util.JDC;
import org.dcache.srm.v2_2.*;
import org.glite.voms.PKIVerifier;
import org.gridforum.jgss.ExtendedGSSContext;
import org.dcache.auth.util.GSSUtils;
import org.dcache.commons.stats.RequestCounters;
import org.dcache.commons.stats.RequestExecutionTimeGauges;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.slf4j.MDC;


public class SRMServerV2 implements org.dcache.srm.v2_2.ISRM {

public Logger log;
private SrmDCacheConnector srmConn;
private SrmAuthorizer srmAuth;
private PKIVerifier pkiVerifier;
org.dcache.srm.util.Configuration configuration;
private AbstractStorageElement storage;
private final RequestCounters<Class<?>> srmServerCounters;
private final RequestExecutionTimeGauges<Class<?>> srmServerGauges;
private final SRM srm;

public SRMServerV2() throws java.rmi.RemoteException{
try {
Expand All @@ -207,19 +127,25 @@ public SRMServerV2() throws java.rmi.RemoteException{
log.error(error_details);
throw new java.rmi.RemoteException(error );
}
srmConn = SrmDCacheConnector.getInstance(srmConfigFile);
SrmDCacheConnector srmConn = SrmDCacheConnector.getInstance(srmConfigFile);
if (srmConn == null) {
throw new java.rmi.RemoteException("Failed to get instance of srm." );
}
log.info(" initialize() got connector ="+srmConn);
// Set up the authorization service
srmAuth = new SrmAuthorizer(srmConn);

srm = srmConn.getSrm();
Configuration config = srm.getConfiguration();

srmAuth = new SrmAuthorizer(config.getAuthorization(),
srm.getRequestCredentialStorage(),
config.isClientDNSLookup());

// use default locations for cacerts and vomdsdir
pkiVerifier
= GSSUtils.getPkiVerifier(null, null, MDC.getCopyOfContextMap());
storage = srmConn.getSrm().getConfiguration().getStorage();
srmServerCounters = srmConn.getSrm().getSrmServerV2Counters();
srmServerGauges = srmConn.getSrm().getSrmServerV2Gauges();
storage = srm.getConfiguration().getStorage();
srmServerCounters = srm.getSrmServerV2Counters();
srmServerGauges = srm.getSrmServerV2Gauges();

} catch ( java.rmi.RemoteException re) { throw re; } catch ( Exception e) {
throw new java.rmi.RemoteException("exception",e);
Expand Down Expand Up @@ -294,7 +220,7 @@ private Object handleRequest(String requestName, Object request) throws RemoteE
requestCredential,
request,
storage,
srmConn.getSrm(),
srm,
userCred.clientHost);
handleGetResponseMethod = handlerClass.getMethod("getResponse",(Class[])null);
} catch(ClassNotFoundException e) {
Expand Down

0 comments on commit 1d36f52

Please sign in to comment.