Exemple #1
0
int
rsDataObjRsync( rsComm_t *rsComm, dataObjInp_t *dataObjInp,
                msParamArray_t **outParamArray ) {
    int status;
    char *rsyncMode;
    char *remoteZoneOpr;
    int remoteFlag;
    rodsServerHost_t *rodsServerHost;
    specCollCache_t *specCollCache = NULL;

    *outParamArray = NULL;
    if ( dataObjInp == NULL ) {
        rodsLog( LOG_ERROR, "rsDataObjRsync error. NULL input" );
        return SYS_INTERNAL_NULL_INPUT_ERR;
    }

    rsyncMode = getValByKey( &dataObjInp->condInput, RSYNC_MODE_KW );
    if ( rsyncMode == NULL ) {
        rodsLog( LOG_ERROR,
                 "rsDataObjRsync: RSYNC_MODE_KW input is missing" );
        return USER_RSYNC_NO_MODE_INPUT_ERR;
    }

    if ( strcmp( rsyncMode, LOCAL_TO_IRODS ) == 0 ) {
        remoteZoneOpr = REMOTE_CREATE;
    }
    else {
        remoteZoneOpr = REMOTE_OPEN;
    }

    resolveLinkedPath( rsComm, dataObjInp->objPath, &specCollCache,
                       &dataObjInp->condInput );
    if ( strcmp( rsyncMode, IRODS_TO_IRODS ) == 0 ) {
        if ( isLocalZone( dataObjInp->objPath ) == 0 ) {
            dataObjInp_t myDataObjInp;
            char *destObjPath;
            /* source in a remote zone. try dest */
            destObjPath = getValByKey( &dataObjInp->condInput,
                                       RSYNC_DEST_PATH_KW );
            if ( destObjPath == NULL ) {
                rodsLog( LOG_ERROR,
                         "rsDataObjRsync: RSYNC_DEST_PATH_KW input is missing for %s",
                         dataObjInp->objPath );
                return USER_RSYNC_NO_MODE_INPUT_ERR;
            }
            myDataObjInp = *dataObjInp;
            remoteZoneOpr = REMOTE_CREATE;
            rstrcpy( myDataObjInp.objPath, destObjPath, MAX_NAME_LEN );
            remoteFlag = getAndConnRemoteZone( rsComm, &myDataObjInp,
                                               &rodsServerHost, remoteZoneOpr );
        }
        else {
            remoteFlag = getAndConnRemoteZone( rsComm, dataObjInp,
                                               &rodsServerHost, remoteZoneOpr );
        }
    }
    else {
        remoteFlag = getAndConnRemoteZone( rsComm, dataObjInp, &rodsServerHost,
                                           remoteZoneOpr );
    }

    // =-=-=-=-=-=-=-
    // determine the resource hierarchy if one is not provided
    if ( getValByKey( &dataObjInp->condInput, RESC_HIER_STR_KW ) == NULL ) {
        std::string       hier;
        irods::error ret = irods::resolve_resource_hierarchy( irods::OPEN_OPERATION,
                           rsComm, dataObjInp, hier );
        if ( !ret.ok() ) {
            std::stringstream msg;
            msg << __FUNCTION__;
            msg << " :: failed in irods::resolve_resource_hierarchy for [";
            msg << dataObjInp->objPath << "]";
            irods::log( PASSMSG( msg.str(), ret ) );
            return ret.code();
        }

        // =-=-=-=-=-=-=-
        // we resolved the redirect and have a host, set the hier str for subsequent
        // api calls, etc.
        addKeyVal( &dataObjInp->condInput, RESC_HIER_STR_KW, hier.c_str() );

    } // if keyword




    if ( remoteFlag < 0 ) {
        return remoteFlag;
    }
    else if ( remoteFlag == REMOTE_HOST ) {

        status = _rcDataObjRsync( rodsServerHost->conn, dataObjInp,
                                  outParamArray );
        return status;
    }

    if ( strcmp( rsyncMode, IRODS_TO_LOCAL ) == 0 ) {
        status = rsRsyncFileToData( rsComm, dataObjInp );
    }
    else if ( strcmp( rsyncMode, LOCAL_TO_IRODS ) == 0 ) {
        status = rsRsyncDataToFile( rsComm, dataObjInp );
    }
    else if ( strcmp( rsyncMode, IRODS_TO_IRODS ) == 0 ) {
        status = rsRsyncDataToData( rsComm, dataObjInp );
    }
    else {
        rodsLog( LOG_ERROR,
                 "rsDataObjRsync: rsyncMode %s  not supported" );
        return USER_RSYNC_NO_MODE_INPUT_ERR;
    }

    return status;
}
int
rcDataObjRsync (rcComm_t *conn, dataObjInp_t *dataObjInp) 
{
    int status;
    msParamArray_t *outParamArray = NULL;
    char *locFilePath;

    status = _rcDataObjRsync (conn, dataObjInp, &outParamArray);

    if (status == SYS_SVR_TO_CLI_PUT_ACTION) {
        if ((locFilePath = getValByKey (&dataObjInp->condInput,
          RSYNC_DEST_PATH_KW)) == NULL) {
	    return USER_INPUT_PATH_ERR;
	} else {
	    status = rcDataObjPut (conn, dataObjInp, locFilePath);
	    if (status >= 0) {
		return SYS_RSYNC_TARGET_MODIFIED;
	    } else {
	        return status;
	    }
	}
    } else if (status == SYS_SVR_TO_CLI_GET_ACTION) {
        if ((locFilePath = getValByKey (&dataObjInp->condInput,
          RSYNC_DEST_PATH_KW)) == NULL) {
            return USER_INPUT_PATH_ERR;
        } else {
            status = rcDataObjGet (conn, dataObjInp, locFilePath);
            if (status >= 0) {
                return SYS_RSYNC_TARGET_MODIFIED;
            } else {
                return status;
            }
	}
    }

    /* below is for backward compatibility */
    while (status == SYS_SVR_TO_CLI_MSI_REQUEST) {
	/* it is a server request */
        msParam_t *myMsParam;
        dataObjInp_t *dataObjInp = NULL;
	int l1descInx; 

	myMsParam = getMsParamByLabel (outParamArray, CL_ZONE_OPR_INX);
	if (myMsParam == NULL) {
	    l1descInx = -1;
	} else {
	    l1descInx = *(int*) myMsParam->inOutStruct;
	}

	if ((myMsParam = getMsParamByLabel (outParamArray, CL_PUT_ACTION))
	  != NULL) { 

	    dataObjInp = (dataObjInp_t *) myMsParam->inOutStruct;
	    if ((locFilePath = getValByKey (&dataObjInp->condInput, 
	      RSYNC_DEST_PATH_KW)) == NULL) {
		if (l1descInx >= 0) {
		    rcOprComplete (conn, l1descInx);
		} else {
		        rcOprComplete (conn, USER_FILE_DOES_NOT_EXIST);
		}
	    } else {
	        status = rcDataObjPut (conn, dataObjInp, locFilePath);
                if (l1descInx >= 0) {
                    rcOprComplete (conn, l1descInx);
                } else {
		    rcOprComplete (conn, status);
		}
	    }
	} else if ((myMsParam = getMsParamByLabel (outParamArray, 
	  CL_GET_ACTION)) != NULL) {
            dataObjInp = (dataObjInp_t *) myMsParam->inOutStruct;
            if ((locFilePath = getValByKey (&dataObjInp->condInput,
              RSYNC_DEST_PATH_KW)) == NULL) {
                if (l1descInx >= 0) {
                    rcOprComplete (conn, l1descInx);
                } else {
                    rcOprComplete (conn, USER_FILE_DOES_NOT_EXIST);
		}
            } else {
                status = rcDataObjGet (conn, dataObjInp, locFilePath);
                if (l1descInx >= 0) {
                    rcOprComplete (conn, l1descInx);
                } else {
                    rcOprComplete (conn, status);
		}
            }
	} else {
            if (l1descInx >= 0) {
                rcOprComplete (conn, l1descInx);
            } else {
                rcOprComplete (conn, SYS_SVR_TO_CLI_MSI_NO_EXIST);
	    }
	}
	/* free outParamArray */
	if (dataObjInp != NULL) {
	    clearKeyVal (&dataObjInp->condInput); 
	}
	clearMsParamArray (outParamArray, 1);
	free (outParamArray);

	/* read the reply from the eariler call */

        status = branchReadAndProcApiReply (conn, DATA_OBJ_RSYNC_AN, 
        (void **)&outParamArray, NULL);
        if (status < 0) {
            rodsLogError (LOG_DEBUG, status,
              "rcDataObjRsync: readAndProcApiReply failed. status = %d", 
	      status);
        }
    }

    return (status);
}
Exemple #3
0
int
rsDataObjRsync (rsComm_t *rsComm, dataObjInp_t *dataObjInp,
msParamArray_t **outParamArray)
{
    int status;
    char *rsyncMode;
    char *remoteZoneOpr;
    int remoteFlag;
    rodsServerHost_t *rodsServerHost;
    specCollCache_t *specCollCache = NULL;

    *outParamArray = NULL;
    if (dataObjInp == NULL) { 
       rodsLog(LOG_ERROR, "rsDataObjRsync error. NULL input");
       return (SYS_INTERNAL_NULL_INPUT_ERR);
    }

    rsyncMode = getValByKey (&dataObjInp->condInput, RSYNC_MODE_KW);
    if (rsyncMode == NULL) {
	rodsLog (LOG_ERROR,
	  "rsDataObjRsync: RSYNC_MODE_KW input is missing");
	return (USER_RSYNC_NO_MODE_INPUT_ERR);
    }

    if (strcmp (rsyncMode, LOCAL_TO_IRODS) == 0) {
	remoteZoneOpr = REMOTE_CREATE;
    } else {
	remoteZoneOpr = REMOTE_OPEN;
    }

    resolveLinkedPath (rsComm, dataObjInp->objPath, &specCollCache,
      &dataObjInp->condInput);
    if (strcmp (rsyncMode, IRODS_TO_IRODS) == 0) {
	if (isLocalZone (dataObjInp->objPath) == 0) {
	    dataObjInp_t myDataObjInp;
	    char *destObjPath;
	    /* source in a remote zone. try dest */
            destObjPath = getValByKey (&dataObjInp->condInput, 
	      RSYNC_DEST_PATH_KW);
            if (destObjPath == NULL) {
                rodsLog (LOG_ERROR,
                  "rsDataObjRsync: RSYNC_DEST_PATH_KW input is missing for %s",
                  dataObjInp->objPath);
                return (USER_RSYNC_NO_MODE_INPUT_ERR);
	    }
	    myDataObjInp = *dataObjInp;
	    remoteZoneOpr = REMOTE_CREATE;
	    rstrcpy (myDataObjInp.objPath, destObjPath, MAX_NAME_LEN);
	    remoteFlag = getAndConnRemoteZone (rsComm, &myDataObjInp, 
	      &rodsServerHost, remoteZoneOpr);
	} else {
	    remoteFlag = getAndConnRemoteZone (rsComm, dataObjInp, 
	      &rodsServerHost, remoteZoneOpr);
	}
    } else {
        remoteFlag = getAndConnRemoteZone (rsComm, dataObjInp, &rodsServerHost,
          remoteZoneOpr);
    }

    if (remoteFlag < 0) {
        return (remoteFlag);
    } else if (remoteFlag == REMOTE_HOST) {

        status = _rcDataObjRsync (rodsServerHost->conn, dataObjInp,
          outParamArray);
#if 0
	int l1descInx;
	if (status < 0) {
            return (status);
        }
	
	if (status == SYS_SVR_TO_CLI_MSI_REQUEST) {
	    /* server request to client */
            l1descInx = allocAndSetL1descForZoneOpr (0, dataObjInp,
	      rodsServerHost, NULL);
            if (l1descInx < 0) return l1descInx;
	    if (*outParamArray == NULL) {
	        *outParamArray = malloc (sizeof (msParamArray_t));
	        bzero (*outParamArray, sizeof (msParamArray_t));
	    } 
	    addIntParamToArray (*outParamArray, CL_ZONE_OPR_INX, l1descInx);
	}
#endif
        return status;
    }

    if (strcmp (rsyncMode, IRODS_TO_LOCAL) == 0) {
	status = rsRsyncFileToData (rsComm, dataObjInp);
    } else if (strcmp (rsyncMode, LOCAL_TO_IRODS) == 0) { 
	status = rsRsyncDataToFile (rsComm, dataObjInp);
    } else if (strcmp (rsyncMode, IRODS_TO_IRODS) == 0) {
	status = rsRsyncDataToData (rsComm, dataObjInp);
    } else {
        rodsLog (LOG_ERROR, 
          "rsDataObjRsync: rsyncMode %s  not supported");
        return (USER_RSYNC_NO_MODE_INPUT_ERR);
    }
    
    return (status);
}