diff --git a/etc/init.d/storm-backend-server b/etc/init.d/storm-backend-server index 41b37984..35dc7700 100644 --- a/etc/init.d/storm-backend-server +++ b/etc/init.d/storm-backend-server @@ -1,22 +1,13 @@ -#!/bin/bash +#!/bin/sh # -# start/stop StoRM BackEnd server. -# -#Copyright (c) 2008 Magnoni Luca , -#Riccardo Zappi +# storm-backend-server init script # -# You may copy, modify and distribute this file under the same terms -# as StoRM itself. +# chkconfig: 2345 90 20 +# description: The StoRM Backend server # # - -# Comments to support chkconfig on RedHat Linux -# chkconfig: 2345 90 20 -# description: StoRM BackEnd server - -# Comments to support LSB init script conventions -### BEGIN INIT INFO -# Provides: storm-backend +#### BEGIN INIT INFO +# Provides: storm-backend # Required-Start: $local_fs $network $remote_fs mysql # Required-Stop: $local_fs $network $remote_fs # Should-Start: $syslog $time @@ -26,65 +17,55 @@ # Short-Description: start/stop the StoRM BackEnd server # Description: The StoRM BackEnd server. # -# StoRM provides an SRM interface to any POSIX filesystem with direct file -# access ("file:" transport protocol), but can take advantage of special -# features of high performance parallel and cluster file systems, as GPFS +# StoRM provides an SRM interface to any POSIX filesystem with direct file +# access ("file:" transport protocol), but can take advantage of special +# features of high performance parallel and cluster file systems, as GPFS # from IBM and Lustre from SUN. # -# -# ### END INIT INFO +# +# set -x -NAME=storm-backend-server -DESC="storm-backend-server" -UMASK="077" -GPFS_PATH=/usr/lpp/mmfs/bin -PIDFILE=/var/run/${NAME}.pid -LOCKFOLDER=/var/lock/subsys -LOCKFILE=${LOCKFOLDER}/${NAME} - -source /etc/sysconfig/$NAME -if [ -z $STORM_BE_USER ]; then - STORM_BE_USER=storm +# Source lsb init functions +if [ ! -e /lib/lsb/init-functions ]; then + echo "This init script requires lsb init functions!" + exit 1 +else + source "/lib/lsb/init-functions" fi +# This service name +prog="storm-backend-server" -## useful functions +# This service configuration +config="/etc/sysconfig/${prog}" +# The lockfile +lockfile="/var/lock/subsys/${prog}" -# RH defines LSB functions as shell aliases, -# and bash will not expand shell aliases unless -# in POSIXLY_CORRECT mode... -set -o posix +# The pidfile +pidfile="/var/run/${prog}.pid" -# RH init script functions (*before* LSB functions) -if test -e /etc/init.d/functions; then - source /etc/init.d/functions -else - # no RH, no 'status' function - status () { die 1 "status query not supported on this system."; } -fi +# Delay (in seconds) for killproc +killproc_delay=5 -# LSB init script functions (*after* RH functions...) -if [ -f /lib/lsb/init-functions ]; then - source /lib/lsb/init-functions -else - alias log_success_msg="echo SUCCESS! '$@'" - alias log_failure_msg="echo FAILURE! '$@'" - alias log_warning_msg="echo WARNING! '$@'" +if [ -r "${config}" ]; then + # Auto-export variables + set -a + source "${config}" fi function die () { rc="$1" shift - echo -n "${NAME}: " 1>&2 + echo -n "${prog}: " 1>&2 if [ $# -gt 0 ]; then echo "$@" 1>&2 else cat 1>&2 fi - log_failure_msg "$DESC" + log_failure_msg "${prog}" exit $rc } @@ -98,31 +79,10 @@ setenv_if_not_set () { fi } - -# check if a program can be executed given the current path (does not work with builtin commands) -function command_in_path () { - type -p "$1" >&/dev/null; -} - -function require_command () { - local cmd="$1" - - command_in_path "$cmd" \ - || die 1 "Cannot find command - $cmd - in the current PATH - aborting." -} - function user_exists () { getent passwd "$1" >/dev/null } -function group_exists () { - getent group "$1" >/dev/null -} - -function normalize_dirpath () { - cd "$1" && pwd -P && cd - > /dev/null -} - ## execution environment setup if test -e "/etc/profile.d/grid-env.sh"; then @@ -145,24 +105,6 @@ do fi done -# retrieve architecture BITs -platform=`uname -m` -case $platform in -"i686") - ARCH="" - #echo "32-bit OS" - ;; -"x86_64") - ARCH="64" - #echo "64-bit OS" - ;; -*) - echo "Unknown platform" - # Don't install any packages - ;; -esac - - # some Java parameters if [ -z $JAVA_HOME ]; then if [ ! -z $JAVA_LOCATION ]; then @@ -174,37 +116,32 @@ fi JAVA=$JAVA_HOME/bin/java -# LCMAPS modules library setenv_if_not_set STORM_BE_CONFIG_FILE "/etc/storm/backend-server/storm.properties" setenv_if_not_set STORM_BE_CONFIG_REFRESH 0 setenv_if_not_set STORM_BE_CONFIGDIR "`dirname $STORM_BE_CONFIG_FILE`" setenv_if_not_set STORM_BE_LOGDIR "/var/log/storm" -setenv_if_not_set STORM_BE_USER "`id -u -n`" -setenv_if_not_set STORM_BE_JARDIR "/usr/share/java/${NAME}" -setenv_if_not_set STORM_BE_JAR "${STORM_BE_JARDIR}/${NAME}.jar" - - -####################### -## make Java classpath without Native Lib -####################### - -#classpath="$STORM_BE_JAR" -for jar in "$STORM_BE_JARDIR"/*.jar; do - if [ -z $classpath ] ; then - classpath="$jar" - else - classpath="$classpath:$jar" - fi -done +setenv_if_not_set STORM_BE_USER "storm" +setenv_if_not_set STORM_BE_JARDIR "/usr/share/java/${prog}" +setenv_if_not_set STORM_BE_JAR "${STORM_BE_JARDIR}/${prog}.jar" +setenv_if_not_set STORM_BE_SUSPEND "n" +setenv_if_not_set STORM_BE_DEBUG_PORT "1044" +setenv_if_not_set STORM_BE_JVM_OPTS "-server -Xms512m -Xmx512m" + +if [ ! -z "${STORM_BE_DEBUG}" ]; then + setenv_if_not_set STORM_BE_DEBUG_OPTS "-Xdebug -Xrunjdwp:server=y,transport=dt_socket,address=${STORM_BE_DEBUG_PORT},suspend=${STORM_BE_SUSPEND}" +fi + +if [ ! -z "${STORM_BE_JMX}" ]; then + setenv_if_not_set STORM_BE_JMX_OPTS "-Dcom.sun.management.jmxremote.port=8501 -Dcom.sun.management.jmxremote.ssl=false -Dcom.sun.management.jmxremote.authenticate=false"; +fi +# Java classpath +classpath="${STORM_BE_JARDIR}/*" # log4j looks for its config file in the classpath... classpath="$classpath:$STORM_BE_CONFIGDIR" -setenv_if_not_set STORM_BE_LIBDIR "/usr/lib$ARCH/" -export LD_LIBRARY_PATH="/usr/lib$ARCH/modules":$STORM_BE_LIBDIR:$LD_LIBRARY_PATH - -# port for the command server (FIXME: should read from conf. file) -setenv_if_not_set STORM_COMMAND_PORT 4444 +setenv_if_not_set STORM_BE_LIBDIR "/usr/lib64/" +export LD_LIBRARY_PATH="/usr/lib64/modules":$STORM_BE_LIBDIR:$LD_LIBRARY_PATH # LCMAPS config file setenv_if_not_set LCMAPS_DB_FILE "$STORM_BE_CONFIGDIR/lcmaps.db" @@ -271,377 +208,151 @@ if ! su "$STORM_BE_USER" -s /bin/sh -c "test -w '$STORM_BE_LOGDIR'"; then # echo 1>&2 "Log files directory '$STORM_BE_LOGDIR' is not writable by user '$STORM_BE_USER' - StoRM might not be able to *create* log files." fi -## command server interaction - -send_command(){ - if [ $# -ne 2 ]; then - echo -n "INTERNAL ERROR: missing parameters '$'@=$@ required COMMAND , RETURN_VARIABLE" 1>&2 - return -1 - fi - COMMAND=$1 - nc -z localhost $STORM_COMMAND_PORT > /dev/null -# lsof -i tcp:$STORM_COMMAND_PORT > /dev/null - if [ ! $? -eq 0 ]; then - log_failure_msg "StoRMCommandServer on localhost:$STORM_COMMAND_PORT is closed" - return 1 - fi - LOCAL_OUTPUT=$({ (echo $COMMAND; echo exit) | nc localhost $STORM_COMMAND_PORT; }) - if [ ! $? -eq 0 ]; then - log_failure_msg "Error sending $COMMAND to StoRMCommandServer on localhost:$STORM_COMMAND_PORT" - return 2 + +# _current_status(): +# tests if the storm-webdav-server process is running. +# takes care of ensuring pid and lock files are in good shape +# +# returns 0 if the process is running. +# returns 1 if the process is running, and the function restored pid or lock files. +# returns 2 if the process is NOT running. +_current_status(){ + + local pid=$(pgrep -f it.grid.storm.Main) + local restored_pid_or_lock=0 + + if [ -z ${pid} ]; then + rm -f ${pidfile} + if [ -f "${lockfile}" ]; then + rm -f ${lockfile} fi - export $2="$LOCAL_OUTPUT" - return 0 -} + return 2 + fi -getRunningPids(){ - if [ $# -ne 1 ]; then - echo -n "INTERNAL ERROR: missing parameters '$'@=$@ required RETURN_PIDS" 1>&2 - return 1 - fi - pslist=$( ps -ef | grep java | grep $NAME | awk '{print $2}' | tr '\n' ' ' | sed -e s/\ $// ) - export $1="$pslist" - return 0 + ## We have a running process, ensure + ## pid and lockfiles are there + if [ ! -f "${pidfile}" ]; then + restored_pid_or_lock=1 + touch ${pidfile} 2>&1 + echo ${pid} > ${pidfile} + fi + + if [ ! -f "${lockfile}" ]; then + restored_pid_or_lock=1 + touch ${lockfile} 2>&1 + fi + + return ${restored_pid_or_lock} } stop () { - send_command "STOP" "OUTPUT" - if [ ! $? -eq 0 ]; then - return 3 - fi - case "$OUTPUT" in - "SUCCESS") #stop OK - log_success_msg "StoRM backend: sent command STOP" - return 0 - ;; - "FAILURE") - log_failure_msg "$NAME stop failure." - return 1 - ;; - *) - # error - log_failure_msg "$NAME stop unknown response '$OUTPUT'." - return 2 - ;; - esac -} -start () { - send_command "START" "OUTPUT" - if [ ! $? -eq 0 ]; then - return 3 - fi - case "$OUTPUT" in - "SUCCESS") #start OK - log_success_msg "Starting $DESC" - return 0 - ;; - "FAILURE") - log_failure_msg "$NAME start failure." - return 1 - ;; - *) - # error - log_failure_msg "$NAME start unknown response '$OUTPUT'." - return 2 - ;; - esac + echo -n $"Stopping ${prog}: " + _current_status + _status=$? + + if [ ${_status} -eq 2 ]; then + echo "not running." + return 1 + fi + + killproc -p ${pidfile} -d ${killproc_delay} ${prog} + retval=$? + if [ ${retval} -eq 0 ]; then + rm -f ${lockfile} + log_success_msg + else + log_failure_msg "failed to kill process." + fi + + return ${retval} } +start () { -## bootstrap + local jvm_options="${STORM_BE_JVM_OPTS} ${STORM_BE_DEBUG_OPTS} ${STORM_BE_JMX_OPTS}" + local system_opts="-Djava.library.path='$STORM_BE_LIBDIR' -Djna.library.path='$LD_LIBRARY_PATH' -Dstorm.configuration.file='$STORM_BE_CONFIG_FILE' -Dstorm.configuration.refresh='$STORM_BE_CONFIG_REFRESH'" + local startcmd="nohup java ${jvm_options} -cp '$classpath' ${system_opts} it.grid.storm.Main 1>$STORM_BE_LOGDIR/storm-backend.stdout 2>$STORM_BE_LOGDIR/storm-backend.stderr &" + echo -n $"Starting ${prog}: " -bootstrap () { - ulimit -n 4096 + _current_status + _status=$? - local pid - local ppid - run () { "$@" 1> /dev/null 2>&1 & : ; } + if [ ${_status} -eq 0 ] || [ ${_status} -eq 1 ]; then + log_success_msg "already running." + return 0 + fi - #cd "$STORM_HOME" - #probably this is the directory where the dump file are created in case of JVM crash - cd "$HOME" - getRunningPids "PIDS" - if [ $? -ne 0 ]; then - return -1 - fi - if [ -n "$PIDS" ]; then - local old_pid=`cat ${PIDFILE}` - echo $PIDS | grep $old_pid >> /dev/null - if [ $? -eq 0 ]; then - log_success_msg "$DESC already running" - return 0 - else - log_warning_msg "$NAME running but wrong pid '$old_pid' in pidfile" - return 1 - fi - fi - export PATH=$GPFS_PATH:$JAVA_HOME/bin:$PATH - - run su "$STORM_BE_USER" -m -s /bin/sh -c "umask $UMASK ; - java \ - $STORM_BE_JVM_OPTS \ - -cp '$classpath' \ - $STORM_DEBUG_OPTION \ - $STORM_JMX_OPTION \ - -Djava.library.path='$STORM_BE_LIBDIR' \ - -Djna.library.path='$LD_LIBRARY_PATH' \ - -Daxis.client.connect.timeout=30000 \ - -Djava.protocol.handler.pkgs=org.globus.net.protocol \ - -Dnetworkaddress.cache.negative.ttl=0 \ - -Dnetworkaddress.cache.ttl=0 \ - -Dstorm.log.dir='$STORM_BE_LOGDIR' \ - -Dstorm.user='$STORM_BE_USER' \ - -Dsun.net.client.defaultConnectTimeout=30000 \ - -Dsun.net.client.defaultReadTimeout=30000 \ - $STORM_SSL_OPTIONS \ - it.grid.storm.StoRMCommandServer \ - '$STORM_BE_CONFIG_FILE' '$STORM_BE_CONFIG_REFRESH' \ - 1>$STORM_BE_LOGDIR/storm-backend.stdout \ - 2>$STORM_BE_LOGDIR/storm-backend.stderr " - - # XXX: kludge to test if server is up - # (we need to rewrite main class using commons-daemon!) - sleep 20 - ppid="$!" - pid=`ps --ppid $ppid -o pid | grep -v PID | xargs ps --ppid 2> /dev/null | grep -v PID | awk '{print $1}'` - if [[ "x" == "x"$pid || ! -d /proc/$pid ]]; then - log_failure_msg "The storm-backend-server process unexpectedly died" - return 1 - fi + start_daemon -p ${pidfile} -u ${STORM_BE_USER} ${startcmd} + retval=$? - - # lock subsys (see http://www.redhat.com/magazine/008jun05/departments/tips_tricks/ ) - if test -w ${LOCKFOLDER}; then - echo $pid > ${LOCKFILE} + if [ ${retval} -eq 0 ]; then + sleep 5 + _current_status + _status=$? + if [ ${_status} -eq 0 ] || [ ${_status} -eq 1 ]; then + log_success_msg + else + log_failure_msg "failed to start daemon." + retval=1 fi + fi - # save pid - echo $pid > ${PIDFILE} - - # LSB compliant logging - log_success_msg "Bootstrapping $DESC" + return $retval } +rh_status() { -## shutdown - -shutdown () { + # run checks to determine if the service is running or use generic status + _current_status + _status=$? + if [ ${_status} -eq 0 ] || [ ${_status} -eq 1 ]; then + local pid=$(cat $pidfile) + echo "${prog} (pid $pid) is running..." + else + echo "${prog} is stopped." + fi - local pid - - # shutdown via command server... - getRunningPids "PIDS" - if [ $? -ne 0 ]; then - return -1 - fi - if [ -n "$PIDS" ]; then - send_command "SHUTDOWN" "OUTPUT" - if [ ! $? -eq 0 ]; then - kill_zombie - return 1 - fi - case "$OUTPUT" in - "SUCCESS") #shutdown OK - ;; - "FAILURE") - log_warning_msg "shutdown error. Forcing off" - kill_zombie - return 0 - ;; - *) - # error - log_warning_msg "shutdown unknown response '$OUTPUT'. Forcing off" - kill_zombie - return 0 - ;; - esac - # trick to test if server is still up; - sleep 2 - if [ -f ${PIDFILE} ]; then - pid=`cat ${PIDFILE}` - - if test -n "$pid"; then - # do not sleep, stop call is synchronous - #sleep 5 - if [ -d /proc/$pid ]; then - log_warning_msg "$NAME still running after SHUDOWN. Forcing off" - kill_zombie - return 0 - fi - fi - fi - # LSB compliant logging - log_success_msg "Stopping $DESC" - else - log_success_msg "$DESC already stopped" - fi - # remove pidfile - rm -f ${PIDFILE} - # remove subsys lock (see http://www.redhat.com/magazine/008jun05/departments/tips_tricks/ ) - rm -f ${LOCKFILE} - return 0 + return ${_status} } -kill_zombie(){ - local pid=`cat ${PIDFILE}` - kill -9 $pid - rm -f ${PIDFILE} - # remove subsys lock (see http://www.redhat.com/magazine/008jun05/departments/tips_tricks/ ) - rm -f ${LOCKFILE} - log_success_msg "Roughly killing $DESC" - return 0 +restart() { + stop + start } -## status ----------------------------------- +reload() { + restart +} -status(){ - - local PIDS - getRunningPids "PIDS" - if [ $? -ne 0 ]; then - return -1 - fi - if [ -n "$PIDS" ]; then - if [ ! -f ${PIDFILE} ]; then - log_warning_msg "$NAME running but pid file exists" - return 1 - fi - if [ ! -f ${LOCKFILE} ]; then - log_warning_msg "$NAME running but subsys locked" - return 2 - fi - local pid=`cat ${PIDFILE}` - echo ${PIDS} | grep ${pid} > /dev/null - if [ $? -ne 0 ]; then - log_warning_msg "$NAME running but wrong pid in PIDFILE" - return 3 - fi - send_command "STATUS" "OUTPUT" - if [ ! $? -eq 0 ]; then - return -2 - fi - case "$OUTPUT" in - "STARTING") - ;; - "STOPPED") - ;; - "RUNNING") - ;; - "STOPPING") - ;; - "SHUTTING_DOWN") - ;; - *) - log_warning_msg "$NAME unknown status '$OUTPUT'." - return 4 - ;; - esac - log_success_msg "$NAME (pid ${pid}) is $OUTPUT" - return 0 - fi - if [ -f ${PIDFILE} ]; then - log_warning_msg "$NAME dead but pid file exists" - return 1 - fi - if [ -f ${LOCKFILE} ]; then - log_warning_msg "$NAME dead but subsys locked" - return 2 - fi - log_success_msg "$NAME is stopped" - return 0 +force_reload() { + restart } ## main -#set -e # removed! do not exit if a command fails! - case "$1" in - start) - if [ $# -gt 1 ]; then - if [ $2 = "debug" ]; then - STORM_DEBUG_OPTION="-Xdebug -Xrunjdwp:transport=dt_socket,address=1044,server=y,suspend=n"; - elif [ $2 = "jmx" ]; then - STORM_JMX_OPTION="-Dcom.sun.management.jmxremote.port=8501 -Dcom.sun.management.jmxremote.ssl=false -Dcom.sun.management.jmxremote.authenticate=false"; - else - bootstrap && start; - fi - if [ $# -gt 2 ]; then - if [ $3 = "debug" ]; then - STORM_DEBUG_OPTION="-Xdebug -Xrunjdwp:transport=dt_socket,address=1044,server=y,suspend=n" ; - bootstrap && start; - elif [ $3 = "jmx" ]; then - STORM_JMX_OPTION="-Dcom.sun.management.jmxremote.port=8501 -Dcom.sun.management.jmxremote.ssl=false -Dcom.sun.management.jmxremote.authenticate=false" ; - bootstrap && start; - else - bootstrap && start; - fi - else - bootstrap && start; - fi ; - else - bootstrap && start; - fi ;; - stop) shutdown ;; - #reload - # - # If the daemon can reload its config files on the fly - # for example by sending it SIGHUP, do it here. - # - # If the daemon responds to changes in its config file - # directly anyway, make this a do-nothing entry. - # - # echo "Reloading $DESC configuration files." - # start-stop-daemon --stop --signal 1 --quiet --pidfile \ - # /var/run/$NAME.pid --exec $DAEMON - #;; - restart|force-reload) - # - # If the "reload" option is implemented, move the "force-reload" - # option to the "reload" entry above. If not, "force-reload" is - # just the same as "restart". - # - shutdown; - sleep 1; - if [ $# -gt 1 ]; then - if [ $2 = "debug" ]; then - STORM_DEBUG_OPTION="-Xdebug -Xrunjdwp:transport=dt_socket,address=1044,server=y,suspend=n"; - elif [ $2 = "jmx" ]; then - STORM_JMX_OPTION="-Dcom.sun.management.jmxremote.port=8501 -Dcom.sun.management.jmxremote.ssl=false -Dcom.sun.management.jmxremote.authenticate=false"; - else - bootstrap && start; - fi - if [ $# -gt 2 ]; then - if [ $3 = "debug" ]; then - STORM_DEBUG_OPTION="-Xdebug -Xrunjdwp:transport=dt_socket,address=1044,server=y,suspend=n" ; - bootstrap && start; - elif [ $3 = "jmx" ]; then - STORM_JMX_OPTION="-Dcom.sun.management.jmxremote.port=8501 -Dcom.sun.management.jmxremote.ssl=false -Dcom.sun.management.jmxremote.authenticate=false" ; - bootstrap && start; - else - bootstrap && start; - fi - else - bootstrap && start; - fi ; - else - bootstrap && start; - fi ;; - # stop Picker - suspend) stop ;; - - # start Picker and XmlRpcServer - resume) start ;; - # query status (only RH systems) - # FIXME: this cannot work until the BE has a proper UNIX startup... - # the 'status' function uses 'pidof' to search, and our process has - # has process name 'java'... - status) status;; - - *) - die 2 "Usage: $0 {start|stop|restart|force-reload|status}" - ;; + start) + $1 + ;; + stop) + $1 + ;; + restart) + $1 + ;; + reload) + $1 + ;; + force-reload) + force_reload + ;; + status) + rh_status + ;; + *) + echo $"Usage: $0 {start|stop|status|restart|reload|force-reload}" + exit 2 esac -exit 0 - +exit $? diff --git a/etc/logging.xml b/etc/logging.xml index 3c6f35da..7f6b0bbb 100644 --- a/etc/logging.xml +++ b/etc/logging.xml @@ -3,10 +3,10 @@ - ${storm.log.dir}/storm-backend-metrics.log + /var/log/storm/storm-backend-metrics.log - ${storm.log.dir}/storm-backend-metrics-%d{yyyy-MM-dd}.log.gz + /var/log/storm/storm-backend-metrics-%d{yyyy-MM-dd}.log.gz 90 @@ -18,10 +18,10 @@ - ${storm.log.dir}/storm-backend.log + /var/log/storm/storm-backend.log - ${storm.log.dir}/storm-backend-%d{yyyy-MM-dd}.log.gz + /var/log/storm/storm-backend-%d{yyyy-MM-dd}.log.gz 90 @@ -34,10 +34,10 @@ - ${storm.log.dir}/heartbeat.log + /var/log/storm/heartbeat.log - ${storm.log.dir}/heartbeat-%d{yyyy-MM-dd}.log.gz + /var/log/storm/heartbeat-%d{yyyy-MM-dd}.log.gz @@ -50,10 +50,10 @@ - ${storm.log.dir}/bookkeeping.log + /var/log/storm/bookkeeping.log - ${storm.log.dir}/bookkeeping-%d{yyyy-MM-dd}.log.gz + /var/log/storm/bookkeeping-%d{yyyy-MM-dd}.log.gz diff --git a/etc/storm.properties.template b/etc/storm.properties.template index b617d487..2055809e 100644 --- a/etc/storm.properties.template +++ b/etc/storm.properties.template @@ -1,34 +1,32 @@ -# ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ -# storm.properties -# version 1.0 -# ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +########################### +# storm.properties +########################### # # This file contains properties that govern the operation of StoRM. -# The file is read at startup of the service. +# The file is read at startup of the service. # Your changes will be applied when the service will be restarted. # -# ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - +############################ ############################ ### SERVICE PARAMETERS ### ############################ -## -## NOTE: +## +## NOTE: ## The SERVICE PARAMETERS are managed also by YAIM. ## So, if you install and configure the service with YAIM, please ## remember that the parameters tagged as YAIM will be overwrite at every ## reconfiguration done with YAIM, so if you want change some parameters ## you should use the YAIM configuration files: ## /services/ig-se_storm_backend (or equivalent) -## +## # ============================ # StoRM Service DNS -# ============================ +# ============================ # hostname with which the service is published # -storm.service.FE-public.hostname = +storm.service.FE-public.hostname = # ============================ @@ -78,16 +76,6 @@ storm.service.request-db.host = storm.service.request-db.username = storm.service.request-db.passwd = - -# =========================== -# Gridhttps plugin parameters -# =========================== - -# If the GridHTTPS is enabled StoRM provides access to files via http and https protocol -gridhttps.enabled=false -#The complete classname of the class implementing the http(s) plugin interface -gridhttps.plugin.classname=it.grid.storm.httpsHTTPSPluginInterfaceStub - ############################################# ############ PROFILE PARAMETERS ############ ############################################# @@ -194,7 +182,7 @@ synchcall.directoryManager.maxLsEntry=2000 # ============================ # REST Services parameter # ============================ -storm.rest.services.port= +storm.rest.services.port=9998 storm.rest.services.maxthreads=100 storm.rest.services.max_queue_size=1000 @@ -276,3 +264,21 @@ transit.delay = 10 # Skip ACL setup for PtG requests ptg.skip-acl-setup = false + +# The caching policy for successful name lookups from the name service. +# The value is specified as integer to indicate the number of seconds to cache the successful lookup. +# A value of -1 indicates "cache forever". The default behavior is to cache forever when a security +# manager is installed, and to cache for an implementation specific period of time, when a security +# manager is not installed. +# +# Default value: 0 +# +#networkaddress.cache.ttl=0 + +# The caching policy for un-successful name lookups from the name service. +# The value is specified as integer to indicate the number of seconds to cache the failure for un-successful lookups. +# A value of 0 indicates "never cache". A value of -1 indicates "cache forever". +# +# Default value: 0 +# +#networkaddress.cache.negative.ttl=0 diff --git a/etc/sysconfig/storm-backend-server b/etc/sysconfig/storm-backend-server index 8114e555..24d8135c 100644 --- a/etc/sysconfig/storm-backend-server +++ b/etc/sysconfig/storm-backend-server @@ -37,12 +37,26 @@ STORM_BE_USER=storm # BUG: maybe code reads this from storm.properties, not from here... #STORM_BE_TMPDIR="$STORM_HOME/var/tmp" +# StoRM Backend server debug option. Uncomment this (and restart the service) +# if you want to attach a java debugger to the running server process +# STORM_BE_DEBUG="y" + +# JVM debug port. Used together with STORM_BE_DEBUG to specify on which +# port the JVM should listen for incoming debugger. +# STORM_BE_DEBUG_PORT=1044 + +# JVM debug suspend option. Uncomment this to block the process JVM until a remote +# debugger connects to the debugging port specified with the STORM_BE_DEBUG_PORT +# option +# STORM_BE_DEBUG_SUSPEND="y" + +# StoRM Backend server jmx option. Uncomment this (and restart the service) +# if you want to attach a java jmx monitor to the running server process +# STORM_BE_JMX="y" + # options for the JVM running the StoRM BE server STORM_BE_JVM_OPTS='-server -Xms512m -Xmx512m' -# port for the command server (FIXME: should read from conf. file) -#export STORM_COMMAND_PORT=4444 - # LCMAPS config file #export LCMAPS_DB_FILE="$STORM_BE_CONFIGDIR/lcmaps.db" diff --git a/pom.xml b/pom.xml index 5ecf21e0..90dc3a3f 100644 --- a/pom.xml +++ b/pom.xml @@ -5,7 +5,7 @@ StoRM Backend server org.italiangrid.storm storm-backend-server - 1.11.15-SNAPSHOT + 1.11.15 @@ -21,12 +21,9 @@ 1.2.1 2.0.1 0.5.2 - 1.4 - 1.3 3.0 1.1 20080701 - 1.4 4.8.1 1.0 0.2 @@ -394,17 +391,6 @@ ${ini4jVersion} - - org.apache.axis - axis - ${axisVersion} - - - axis - axis-schema - ${axisSchemaVersion} - - org.apache.xmlrpc xmlrpc-server @@ -428,64 +414,6 @@ ${jsonVersion} - - - org.globus - cog-axis - ${cogGlobusVersion} - - - org.globus - cog-jglobus - ${cogGlobusVersion} - - - org.globus - cog-jobmanager - ${cogGlobusVersion} - - - org.globus - cog-url - ${cogGlobusVersion} - - - org.globus - cryptix-asn1 - ${cogGlobusVersion} - - - org.globus - cryptix32 - ${cogGlobusVersion} - - - org.globus - puretls - ${cogGlobusVersion} - - - org.globus - jgss - ${cogGlobusVersion} - - - org.globus - jce-jdk13-131 - ${cogGlobusVersion} - - - - - srm22client - srm22client - 0 - - junit junit diff --git a/src/main/java/it/grid/storm/Main.java b/src/main/java/it/grid/storm/Main.java new file mode 100644 index 00000000..30e30d1b --- /dev/null +++ b/src/main/java/it/grid/storm/Main.java @@ -0,0 +1,33 @@ +package it.grid.storm; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +public class Main { + + private static final Logger log = LoggerFactory.getLogger(Main.class); + + private Main() {} + + public static void main(String[] args) { + + Thread.setDefaultUncaughtExceptionHandler(new StoRMDefaultUncaughtExceptionHandler()); + + StoRM storm = new StoRM(); + + Runtime.getRuntime().addShutdownHook(new ShutdownHook(storm)); + + if (storm.startServices()) { + + log.info("StoRM: Backend services successfully started."); + + } else { + + log.error("StoRM: error starting storm services."); + + storm.stopServices(); + + Runtime.getRuntime().exit(1); + } + } +} diff --git a/src/main/java/it/grid/storm/ShutdownHook.java b/src/main/java/it/grid/storm/ShutdownHook.java new file mode 100644 index 00000000..a5db5227 --- /dev/null +++ b/src/main/java/it/grid/storm/ShutdownHook.java @@ -0,0 +1,42 @@ +package it.grid.storm; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import it.grid.storm.space.gpfsquota.GPFSQuotaManager; + +public class ShutdownHook extends Thread { + + private static final Logger log = LoggerFactory.getLogger(ShutdownHook.class); + + private StoRM storm; + + public ShutdownHook(StoRM storm) { + this.storm = storm; + } + + @Override + public void run() { + + log.info("StoRM: Backend shutdown..."); + log.info("StoRM: stopping Backend services..."); + + try { + storm.stopPicker(); + storm.stopXmlRpcServer(); + storm.stopRestServer(); + storm.stopSpaceGC(); + storm.stopExpiredAgent(); + GPFSQuotaManager.INSTANCE.shutdown(); + + log.info("StoRM: Backend successfully stopped."); + + } catch (Throwable e) { + + log.error(e.getMessage(), e); + log.error("StoRM: error stopping storm services."); + } + + log.info("StoRM: Backend shutdown complete."); + } +} diff --git a/src/main/java/it/grid/storm/StoRM.java b/src/main/java/it/grid/storm/StoRM.java index da21182a..d967d889 100644 --- a/src/main/java/it/grid/storm/StoRM.java +++ b/src/main/java/it/grid/storm/StoRM.java @@ -18,6 +18,8 @@ import static it.grid.storm.metrics.StormMetricRegistry.METRIC_REGISTRY; import static it.grid.storm.rest.RestService.startServer; import static it.grid.storm.rest.RestService.stop; +import static java.lang.String.valueOf; +import static java.security.Security.setProperty; import java.util.Timer; import java.util.TimerTask; @@ -34,11 +36,11 @@ import it.grid.storm.check.CheckResponse; import it.grid.storm.check.CheckStatus; import it.grid.storm.check.SimpleCheckManager; -import it.grid.storm.config.ConfigReader; import it.grid.storm.config.Configuration; import it.grid.storm.health.HealthDirector; import it.grid.storm.metrics.StormMetricsReporter; import it.grid.storm.namespace.NamespaceDirector; +import it.grid.storm.space.gpfsquota.GPFSQuotaManager; import it.grid.storm.startup.Bootstrap; import it.grid.storm.startup.BootstrapException; import it.grid.storm.synchcall.SimpleSynchcallDispatcher; @@ -61,9 +63,6 @@ public class StoRM { private static final Logger log = LoggerFactory.getLogger(StoRM.class); - public static final String DEFAULT_CONFIGURATION_FILE_PATH = - "/etc/storm/backend-server/storm.properties"; - // Timer object in charge to call periodically the Space Garbage Collector private final Timer gc = new Timer(); private TimerTask cleaningTask = null; @@ -92,12 +91,12 @@ public class StoRM { * fail! In any case, failure to read the configuration file causes StoRM to use hard-coded * default values. */ - public StoRM(String configurationPathname, int refresh) { - - loadConfiguration(configurationPathname, refresh); + public StoRM() { configureLogging(); + configureSecurity(); + configureMetricsReporting(); configureStoRMDataSource(); @@ -123,19 +122,6 @@ public StoRM(String configurationPathname, int refresh) { } - private void loadConfiguration(String configurationPathname, int refresh) { - - if ((configurationPathname == null) || (configurationPathname.isEmpty())) { - configurationPathname = DEFAULT_CONFIGURATION_FILE_PATH; - } - - log.info("Loading backend configuration from '{}'", configurationPathname); - log.info("Configuration refresh rate (in secs): {}", refresh); - - Configuration.getInstance().setConfigReader(new ConfigReader(configurationPathname, refresh)); - - } - private void configureLogging() { String configurationDir = Configuration.getInstance().configurationDir(); @@ -143,6 +129,17 @@ private void configureLogging() { Bootstrap.configureLogging(logFile); } + private void configureSecurity() { + + int cacheTtl = Configuration.getInstance().getNetworkAddressCacheTtl(); + log.debug("Setting networkaddress.cache.ttl to {}", cacheTtl); + setProperty("networkaddress.cache.ttl", valueOf(cacheTtl)); + + int cacheNegativeTtl = Configuration.getInstance().getNetworkAddressCacheNegativeTtl(); + log.debug("Setting networkaddress.cache.negative.ttl to {}", cacheNegativeTtl); + setProperty("networkaddress.cache.negative.ttl", valueOf(cacheNegativeTtl)); + } + private void configureMetricsReporting() { METRIC_REGISTRY.getRegistry().timer(SimpleSynchcallDispatcher.SYNCH_CALL_TIMER_NAME); @@ -156,9 +153,7 @@ private void configureMetricsReporting() { private void loadNamespaceConfiguration() { - boolean verboseMode = false; // true generates verbose logging - boolean testingMode = false; // True if you wants testing namespace - NamespaceDirector.initializeDirector(verboseMode, testingMode); + NamespaceDirector.initializeDirector(); } @@ -230,6 +225,10 @@ private void configureStoRMDataSource() { */ public synchronized void startPicker() { + if (isPickerRunning) { + log.debug("Picker is already running"); + return; + } picker.startIt(); isPickerRunning = true; } @@ -239,6 +238,10 @@ public synchronized void startPicker() { */ public synchronized void stopPicker() { + if (!isPickerRunning) { + log.debug("Picker is not running"); + return; + } picker.stopIt(); isPickerRunning = false; } @@ -258,6 +261,10 @@ public synchronized boolean pickerIsRunning() { */ public synchronized void startXmlRpcServer() { + if (isXmlrpcServerRunning) { + log.debug("XMLRPC server is already running"); + return; + } xmlrpcServer.start(); isXmlrpcServerRunning = true; } @@ -267,6 +274,11 @@ public synchronized void startXmlRpcServer() { */ public synchronized void stopXmlRpcServer() { + if (!isXmlrpcServerRunning) { + log.debug("XMLRPC server is not running"); + return; + } + xmlrpcServer.stop(); isXmlrpcServerRunning = false; } @@ -284,6 +296,11 @@ public synchronized boolean xmlRpcServerIsRunning() { */ public synchronized void startRestServer() throws Exception { + if (isRestServerRunning) { + log.debug("Rest Server is already running"); + return; + } + startServer(); isRestServerRunning = true; } @@ -293,17 +310,21 @@ public synchronized void startRestServer() throws Exception { */ public synchronized void stopRestServer() { + if (!isRestServerRunning) { + log.debug("Rest Server is not running."); + return; + } + try { stop(); + isRestServerRunning = false; } catch (Exception e) { - log.error("Unable to stop internal HTTP Server listening for RESTFul " + "services: {}", + log.error("Unable to stop internal HTTP Server listening for RESTFul services: {}", e.getMessage(), e); } - - isRestServerRunning = false; } /** @@ -319,7 +340,12 @@ public synchronized boolean restServerIsRunning() { */ public synchronized void startSpaceGC() { - log.debug("Starting Space GC."); + if (isSpaceGCRunning) { + log.debug("Space Garbage Collector is already running"); + return; + } + + log.debug("Starting Space Garbage Collector ..."); // Delay time before starting long delay = Configuration.getInstance().getCleaningInitialDelay() * 1000; @@ -338,7 +364,7 @@ public void run() { }; gc.scheduleAtFixedRate(cleaningTask, delay, period); isSpaceGCRunning = true; - log.debug("Space GC started."); + log.debug("Space Garbage Collector started."); } /** @@ -346,12 +372,17 @@ public void run() { */ public synchronized void stopSpaceGC() { - log.debug("Stopping Space GC."); + if (!isSpaceGCRunning) { + log.debug("Space Garbage Collector is not running."); + return; + } + + log.debug("Stopping Space Garbage Collector."); if (cleaningTask != null) { cleaningTask.cancel(); gc.purge(); } - log.debug("Space GC stopped."); + log.debug("Space Garbage Collector stopped."); isSpaceGCRunning = false; } @@ -373,6 +404,11 @@ public synchronized boolean spaceGCIsRunning() { */ public synchronized void startExpiredAgent() { + if (isExpiredAgentRunning) { + log.debug("Expired Agent is already running."); + return; + } + /* Delay time before starting cleaning thread! Set to 1 minute */ final long delay = Configuration.getInstance().getTransitInitialDelay() * 1000L; /* Period of execution of cleaning! Set to 1 hour */ @@ -390,6 +426,11 @@ public synchronized void startExpiredAgent() { public synchronized void stopExpiredAgent() { + if (!isExpiredAgentRunning) { + log.debug("Expired Agent is not running."); + return; + } + log.debug("Stopping Expired Agent."); if (expiredAgent != null) { expiredAgent.cancel(); @@ -402,4 +443,30 @@ public synchronized boolean isExpiredAgentRunning() { return isExpiredAgentRunning; } + + public boolean startServices() { + + try { + startPicker(); + startXmlRpcServer(); + startRestServer(); + startSpaceGC(); + startExpiredAgent(); + } catch (Exception e) { + log.error(e.getMessage(), e); + return false; + } + return true; + } + + public void stopServices() { + + stopPicker(); + stopXmlRpcServer(); + stopRestServer(); + stopSpaceGC(); + stopExpiredAgent(); + + GPFSQuotaManager.INSTANCE.shutdown(); + } } diff --git a/src/main/java/it/grid/storm/StoRMCommandServer.java b/src/main/java/it/grid/storm/StoRMCommandServer.java deleted file mode 100644 index ec6fad64..00000000 --- a/src/main/java/it/grid/storm/StoRMCommandServer.java +++ /dev/null @@ -1,532 +0,0 @@ -/* - * - * Copyright (c) Istituto Nazionale di Fisica Nucleare (INFN). 2006-2010. - * - * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except - * in compliance with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software distributed under the License - * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express - * or implied. See the License for the specific language governing permissions and limitations under - * the License. - */ - -package it.grid.storm; - -import it.grid.storm.config.Configuration; -import it.grid.storm.space.gpfsquota.GPFSQuotaManager; - -import java.io.BufferedReader; -import java.io.BufferedWriter; -import java.io.IOException; -import java.io.InputStreamReader; -import java.io.OutputStreamWriter; -import java.net.InetAddress; -import java.net.ServerSocket; -import java.net.Socket; - -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -/** - * Class that represents a Multithreaded Server listening for administration commands to be sent to - * StoRM. - * - * If it receives the string START, the picker, the spaceReservationServer and the xmlrpcServer get - * started; if it receives the string STOP, the picker stops; any other string interrupts the - * connection to this command server leaving StoRM in whatever state is was on. - * - * @author EGRID - ICTP Trieste; INFN - CNAF Bologna - * @version 3.0 - * @Date July 2005 - */ -public class StoRMCommandServer { - - private enum Command { - START("START"), STOP("STOP"), SHUTDOWN("SHUTDOWN"), STATUS("STATUS"), EXIT("EXIT"), UNKNOW( - "UNKNOW"); - - private final String name; - - private Command(String name) { - - this.name = name; - } - - public static Command getCommand(String name) { - - if (name != null) { - for (Command command : Command.values()) { - if (command.getName().equals(name.trim().toUpperCase())) { - return command; - } - } - } - return UNKNOW; - } - - private String getName() { - - return name; - } - - @Override - public String toString() { - - return this.name; - } - } - - private enum StormStatus { - BOOTSTRAPPING("BOOTSTRAPPING"), RUNNING("RUNNING"), STOPPED("STOPPED"), STARTING( - "STARTING"), STOPPING("STOPPING"), SHUTTING_DOWN("SHUTTING_DOWN"), UNKNOW("UNKNOW"); - - private final String statusMessage; - - private StormStatus(String name) { - - this.statusMessage = name; - } - - private String getStatusMessage() { - - return statusMessage; - } - - @Override - public String toString() { - - return this.statusMessage; - } - } - - private StoRM storm; // only StoRM object that the command server administers! - private int listeningPort; // command server binding port - private ServerSocket server = null; // server socket of command server! - private static Logger log = LoggerFactory.getLogger(StoRMCommandServer.class); - private boolean shutdownInProgress = false; - - /** - * Default constructor. - * - * @param storm the storm instance. that should be initialized before anything else, as is where - * configuration is loaded. - * - */ - public StoRMCommandServer(StoRM storm) { - - this.storm = storm; - - this.listeningPort = Configuration.getInstance().getCommandServerBindingPort(); - - startCommandServer(); - } - - /** - * Private method that starts a listening ServerSocket, and handles multiple requests by - * spawning different CommandExecuterThreads! - * - * @param storm - */ - private void startCommandServer() { - - try { - - InetAddress loopbackAddress = InetAddress.getByName("localhost"); - server = new ServerSocket(listeningPort, 0, loopbackAddress); - - } catch (IOException e) { - - log.error("Could not bind to port {}: {}", listeningPort, e.getMessage(), e); - - System.exit(1); - } - - - new Thread() { - - @Override - public void run() { - - try { - while (true) { - - new CommandExecuterThread(server.accept(), storm).start(); - } - } catch (IOException e) { - - log.error( - "UNEXPECTED ERROR! Something went wrong with " + "server.accept(): {}", - e.getMessage(), e); - - System.exit(1); - } - } - }.start(); - } - - /** - * Private class that represents a thread that gets started when a new connection to this - * CommandServer is made: each client connecting to this CommandServer gets its own thread for - * processing the commands sent to StoRM - */ - private class CommandExecuterThread extends Thread { - - private static final String REQUEST_SUCCESS_RESPONSE = "SUCCESS"; - private static final String REQUEST_FAILURE_RESPONSE = "FAILURE"; - private static final String REQUEST_WARNING_RESPONSE = "WARNING"; - private Socket socket; // socket receiving the communication with the client! - - /** - * Constructor that requires the StoRM object to command, and the socket through which the - * client sends the commands to execute. - */ - private CommandExecuterThread(Socket socket, StoRM storm) { - - this.socket = socket; - } - - @Override - public void run() { - - BufferedReader in; - try { - // input stream from client - in = new BufferedReader(new InputStreamReader(socket.getInputStream())); - } catch (IOException e) { - - log.error("UNEXPECTED ERROR! Unable to get a reader for the client " - + "socket. IOException: {}", e.getMessage(), e); - return; - } - BufferedWriter out; - try { - // output stream to the client - out = new BufferedWriter(new OutputStreamWriter(socket.getOutputStream())); - } catch (IOException e) { - - log.error("UNEXPECTED ERROR! Unable to get a writer for the client " - + "socket. IOException: {}", e.getMessage(), e); - return; - } - String response = REQUEST_FAILURE_RESPONSE; - boolean acceptCommands = true; - String inputLine; - try { - inputLine = in.readLine(); - } catch (IOException e) { - - log.error("UNEXPECTED ERROR! Unable to read from the client socket. " - + "IOException: {}", e.getMessage(), e); - return; - } - if (inputLine != null) { - do { - switch (Command.getCommand(inputLine)) { - case START: - // manage START command! - log.info("StoRM: starting Backend services..."); - if (startServices()) { - response = REQUEST_SUCCESS_RESPONSE; - log.info("StoRM: Backend services successfully started."); - } else { - log.error("StoRM: error starting storm services."); - } - break; - case STOP: - // manage STOP command! - log.info("StoRM: stopping Backend services..."); - if (stopServices()) { - response = REQUEST_SUCCESS_RESPONSE; - log.info("StoRM: Backend successfully stopped."); - } else { - log.error("StoRM: error stopping storm services."); - } - break; - case SHUTDOWN: - if (!shutdownInProgress) { - shutdownInProgress = true; - log.info("StoRM: Backend shutdown..."); - log.info("StoRM: stopping Backend services..."); - stopServices(); - response = REQUEST_SUCCESS_RESPONSE; - sendOutputAndClose(response, out, in, socket); - log.info("StoRM: Backend shutdown complete."); - System.exit(0); - } - log.info("StoRM: Backend shutdown already in progress"); - break; - case STATUS: - switch (getCurrentStatus()) { - case RUNNING: - response = StormStatus.RUNNING.getStatusMessage(); - break; - case STOPPED: - response = StormStatus.STOPPED.getStatusMessage(); - break; - case STARTING: - response = StormStatus.STARTING.getStatusMessage(); - break; - case STOPPING: - response = StormStatus.STOPPING.getStatusMessage(); - break; - case SHUTTING_DOWN: - response = StormStatus.SHUTTING_DOWN.getStatusMessage(); - break; - case UNKNOW: - response = REQUEST_WARNING_RESPONSE; - break; - default: - response = REQUEST_WARNING_RESPONSE; - break; - } - break; - case EXIT: - // sequence of commands completed - break; - case UNKNOW: - log.warn("Received an unknown command: {}", inputLine); - acceptCommands = false; - // any other command breaks the connection, but the command server - // remains on! - break; - default: - // any other command breaks the connection, but the command server - // remains on! - acceptCommands = false; - log.warn("Received an unknown command: {}", inputLine); - break; - } - try { - inputLine = in.readLine(); - } catch (IOException e) { - - log.error("UNEXPECTED ERROR! Unable to read from the client socket. " - + "IOException : {}", e.getMessage(), e); - return; - } - } while (inputLine != null && acceptCommands); - } - sendOutputAndClose(response, out, in, socket); - } - - /** - * @return - */ - private boolean startServices() { - - boolean response = true; - if (!storm.pickerIsRunning()) { - storm.startPicker(); - } - try { - if (!storm.xmlRpcServerIsRunning()) { - storm.startXmlRpcServer(); - } - } catch (Exception e) { - - log.error("Unable to start the xmlrpc server. Exception: {}", e.getMessage(), e); - - stopServices(); - return false; - } - try { - if (!storm.restServerIsRunning()) { - storm.startRestServer(); - } - } catch (Exception e) { - - log.error("Unable to start the Rest server. Exception: {}", e.getMessage(), e); - - stopServices(); - return false; - } - if (!storm.spaceGCIsRunning()) { - storm.startSpaceGC(); - } - if (!storm.isExpiredAgentRunning()) { - storm.startExpiredAgent(); - } - return response; - } - - /** - * @return - */ - private boolean stopServices() { - - - storm.stopPicker(); - storm.stopXmlRpcServer(); - storm.stopRestServer(); - storm.stopSpaceGC(); - storm.stopExpiredAgent(); - - GPFSQuotaManager.INSTANCE.shutdown(); - - return true; - } - - /** - * @param response - * @param out - * @param in - * @param socket - */ - private void sendOutputAndClose(String response, BufferedWriter out, BufferedReader in, - Socket socket) { - - try { - try { - out.write(response, 0, response.length()); - out.newLine(); - } catch (IOException e) { - - log.error("UNEXPECTED ERROR! Unable to write on the client socket. " - + "IOException : {}", e.getMessage(), e); - - } - try { - out.close(); - in.close(); - } catch (IOException e) { - - log.error("UNEXPECTED ERROR! Unable to close client socket streams. " - + "IOException : {}", e.getMessage(), e); - - } - } finally { - try { - socket.close(); - } catch (IOException e) { - - log.error("UNEXPECTED ERROR! Unable to close client socket. " - + "IOException : {}", e.getMessage(), e); - - } - } - } - - /** - * @return - */ - private StormStatus getCurrentStatus() { - - if (bootstrapInProgress()) { - return StormStatus.BOOTSTRAPPING; - } - if (shutdownInProgress()) { - return StormStatus.SHUTTING_DOWN; - } - if (servicesRunning()) { - return StormStatus.RUNNING; - } - if (servicesStopped()) { - return StormStatus.STOPPED; - } - if (servicesStarting()) { - return StormStatus.STARTING; - } - if (servicesStopping()) { - return StormStatus.STOPPING; - } - return StormStatus.UNKNOW; - } - - private boolean bootstrapInProgress() { - - return false; - } - - /** - * @return - */ - private boolean shutdownInProgress() { - - return shutdownInProgress; - } - - private boolean servicesRunning() { - - return storm.pickerIsRunning() && storm.xmlRpcServerIsRunning() - && storm.restServerIsRunning() && storm.spaceGCIsRunning() - && storm.isExpiredAgentRunning(); - } - - private boolean servicesStopped() { - - return !storm.pickerIsRunning() && !storm.xmlRpcServerIsRunning() - && !storm.restServerIsRunning() && !storm.spaceGCIsRunning() - && !storm.isExpiredAgentRunning(); - } - - private boolean servicesStarting() { - - return false; - } - - private boolean servicesStopping() { - - return false; - } - } - - /** - * Method that automatically starts a CommandServer listening on the port specified in the - * configuration file. - * - * The command line accepts two parameters, both of which must be specified or else the command - * line is completely ignored: - * - * StoRMCommandServer pathname_of_configuration_file refresh_rate_in_seconds - * - * For example: StoRMCommandServer /home/storm/backend/etc/storm.properties 5 - * - * It starts the command server with configuration file found in - * /home/storm/backend/etc/storm.properties, and refresh rate for checking changes in the - * configuration file of 5 seconds. A value of 0 disables refresh. - * - * If no command line parameters are specified, the behaviour is dictated by the StoRM Class. - * Please refer there for further information. - */ - public static void main(String[] args) { - - Thread.setDefaultUncaughtExceptionHandler(new StoRMDefaultUncaughtExceptionHandler()); - - String configurationPathname = ""; - int refresh = 0; - - if (args.length == 0) { - - log.info("StoRMCommandServer invoked without any command line parameter."); - - } else if (args.length == 2) { - - configurationPathname = args[0]; - - log.info("StoRMCommandServer invoked with two parameters."); - log.info("Configuration file: {}", configurationPathname); - - try { - - refresh = Integer.parseInt(args[1]); - log.info("Configuration file refresh rate: {} seconds", refresh); - - } catch (NumberFormatException e) { - - log.error("Configuration file refresh rate: NOT an integer! " - + "Disabling refresh by default! {}", e.getMessage(), e); - } - } else { - - log.warn("StoRMCommandServer invoked with an invalid number of parameters. "); - log.warn("Ignoring all: continuing as though as none were present."); - } - - log.info("Now booting StoRM..."); - - new StoRMCommandServer(new StoRM(configurationPathname, refresh)); - } -} diff --git a/src/main/java/it/grid/storm/asynch/AdvancedPicker.java b/src/main/java/it/grid/storm/asynch/AdvancedPicker.java index 6731f1ac..4f3898de 100644 --- a/src/main/java/it/grid/storm/asynch/AdvancedPicker.java +++ b/src/main/java/it/grid/storm/asynch/AdvancedPicker.java @@ -208,7 +208,7 @@ public void retrieve() { } else if (rtype == TRequestType.COPY) { - s.schedule(new CopyFeeder(rsd)); + s.schedule(new UnsupportedOperationFeeder()); } else if (rtype == TRequestType.BRING_ON_LINE) { @@ -249,16 +249,6 @@ public void retrieve() { RequestSummaryCatalog.getInstance().failRequest(rsd, "Internal error does not allow request to be fed to scheduler."); - } catch (InvalidCopyFeederAttributesException e) { - - log.error("ADVANCED PICKER ERROR! CopyFeeder could not be created " - + "because of invalid attributes: {}", e.getMessage(),e); - - log.error("Copy Request is being dropped: {}", rsd.requestToken()); - - RequestSummaryCatalog.getInstance().failRequest(rsd, - "Internal error does not allow request to be fed to scheduler."); - } catch (InvalidBoLFeederAttributesException e) { log.error("ADVANCED PICKER ERROR! BoLFeeder could not be created " @@ -269,7 +259,7 @@ public void retrieve() { RequestSummaryCatalog.getInstance().failRequest(rsd, "Internal error does not allow request to be fed to scheduler."); - } catch (SchedulerException e) { + } catch (SchedulerException | UnsupportedOperationException e) { log.error("ADVANCED PICKER ERROR! The request could not be scheduled" + "because of scheduler errors: {}", e.getMessage(), e); diff --git a/src/main/java/it/grid/storm/asynch/Copy.java b/src/main/java/it/grid/storm/asynch/Copy.java deleted file mode 100644 index 791a8454..00000000 --- a/src/main/java/it/grid/storm/asynch/Copy.java +++ /dev/null @@ -1,547 +0,0 @@ -/* - * - * Copyright (c) Istituto Nazionale di Fisica Nucleare (INFN). 2006-2010. - * - * Licensed under the Apache License, Version 2.0 (the "License"); you may not - * use this file except in compliance with the License. You may obtain a copy of - * the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations under - * the License. - */ - -package it.grid.storm.asynch; - -import java.util.Calendar; -import java.util.UUID; -import it.grid.storm.catalogs.CopyData; -import it.grid.storm.griduser.GridUserInterface; -import it.grid.storm.scheduler.Chooser; -import it.grid.storm.scheduler.Delegable; -import it.grid.storm.scheduler.Streets; -import it.grid.storm.srm.types.InvalidTRequestTokenAttributesException; -import it.grid.storm.srm.types.TRequestToken; -import it.grid.storm.srm.types.TReturnStatus; -import it.grid.storm.srm.types.TSizeInBytes; -import it.grid.storm.srm.types.TStatusCode; -import it.grid.storm.srm.types.TTURL; - -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -/** - * Public super class from which both the PushCopyChunk and the PullCopyChunk - * are derived. - * - * @author EGRID - ICTP Trieste - * @version 2.0 - * @date september, 2005 - */ -public abstract class Copy implements Delegable, Chooser, Request { - - // private GetOperationResult getResult = null; //Results of the GET operation - // private PutOperationResult putResult = null; //Results of the PUT operation - // private TransferResult transferResult = null; //Results of the transfer - // operation - - private final String COPY_PREFIX = "COPY-"; - /** - * TRequestToken used to identify the local GET/PUT - */ - protected final TRequestToken localrt; - - /** - * Integer representing a progressive counter of the chunks being handled. - */ - protected final int n; - - /** - * CopyData that holds the specific info for this chunk - */ - protected final CopyData requestData; - - /** - * GridUser that made the request - */ - protected final GridUserInterface gu; - - /** - * boolean that indicates if this chunks state is failure - */ - protected boolean failure = false; - - private static Logger log = LoggerFactory.getLogger(Copy.class); - - /** - * Constructor requiring the GridUser, the RequestSummaryData, the - * CopyChunkData about this chunk, and the integer representing the progessive - * number of the chunk being handled, and the GlobalStatusManager. If the - * supplied attributes are null or the counter is negative, an - * InvalidCopyChunkAttributesException is thrown. - */ - public Copy(GridUserInterface gu, CopyData requestData, int n) - throws InvalidCopyAttributesException { - - if (gu == null || n < 0 || requestData == null) { - throw new InvalidCopyAttributesException(gu, requestData, n); - } - this.gu = gu; - this.requestData = requestData; - this.n = n; - try { - this.localrt = new TRequestToken(COPY_PREFIX.concat(UUID.randomUUID() - .toString().substring(COPY_PREFIX.length())), Calendar.getInstance() - .getTime()); - } catch (InvalidTRequestTokenAttributesException e) { - // never thrown - log.error("Unexpected InvalidTRequestTokenAttributesException: {}", - e.getMessage(), e); - throw new IllegalStateException( - "Unexpected InvalidTRequestTokenAttributesException"); - } - } - - /** - * Method used in a callback fashion in the scheduler for separately handling - * PtG, PtP and Copy chunks. - */ - public void choose(Streets s) { - - s.copyStreet(this); - } - - /** - * Method that handles a chunk. It is invoked by the scheduler to carry out - * the task. - * - * It creates the appropriate TRequestToken for the srmPrepareToGet/Put that - * takes place locally, it executes the getOperation, then the putOperation, - * and finally executes the transferOperation. The new requestToken is created - * by concatenating the one of this srmCopy request with the string "-copy-" - * and the supplied integer n, which is the counter of a multifile srmCopy - * request. - * - * The local get/put operation may fail because it could not start, or because - * the SRM status is not SRM_DONE: then the copyChunk fails with SRM_ABORT and - * appropriate explanation string which reports the local SRM STATUS. - * - * The remote get/put operation may fail because it could not start, the - * SRMClient failed, the operation timed-out, or a state other than SRM_DONE - * is returned. The srmCopy request fails with SRM_ABORT and appropriate - * explanation strings may include the remote SRM STATUS. - * - * The Transfer could fail, and in that case the status of the srmCopy changes - * to SRM_ABORT and explanation string reporting the GridFTP client error. - */ - public void doIt() { - - log.debug("Handling Copy chunk for user DN: {}; fromSURL: {}; toSURL: {}", - gu.getDn(), requestData.getSURL(), requestData.getDestinationSURL()); - - log.debug("RequestToken used for local operation: {}", localrt); - GetOperationResult getResult = executeGetOperation(); - log.debug("Result from get: {}", getResult); - - if (getResult.successful() - && TStatusCode.SRM_FILE_PINNED.equals(getResult.status().getStatusCode())) { - - PutOperationResult putResult = executePutOperation(getResult.filesize()); - log.debug("Result from put: {}", putResult); - /* - * ATTENTION! the following check for SRM_SUCCESS is done to keep - * compatibility between StoRM servers which use a hack thereby switching - * to state SRM_SUCCESS instead of transiting to SRM_SPACE_AVAILABLE!!! - * But for any other SRM2.2 compliant server, SRM_SPACE_AVAILABLE - * suffices!!! - */ - if (putResult.successful() - && ((putResult.status().getStatusCode() - .equals(TStatusCode.SRM_SPACE_AVAILABLE)) || (putResult.status() - .getStatusCode().equals(TStatusCode.SRM_SUCCESS)))) { - - TransferResult transferResult = executeTransfer(getResult, putResult); - log.debug("Result from transfer: {}", transferResult); - if (transferResult.successful()) { - requestData.changeStatusSRM_SUCCESS("srmCopy successfully handled!"); - log.debug("SRM Copy successful!"); - this.failure = false; // gsm.successfulChunk(chunkData); - } else { - String message = String.format("GSIFTP transfer failed! %s", - transferResult.failureExplanation()); - log.error(message); - requestData.changeStatusSRM_FAILURE(message); - this.failure = true; // gsm.failedChunk(chunkData); - } - } else { - // The put operation was problematic! - String message = "PUT part of srmCopy failed! "; - log.error(message); - requestData.changeStatusSRM_FAILURE(message); - this.failure = true; - } - } else { - // the get operation was problematic! - String message = "GET part of srmCopy failed! "; - log.error(message); - requestData.changeStatusSRM_FAILURE(message); - this.failure = true; - } - log.info("Finished handling Copy chunk for user DN: {}; fromSURL: {}; " - + "toSURL: {} result is: {}", gu.getDn(), requestData.getSURL(), - requestData.getDestinationSURL(), requestData.getStatus()); - } - - /** - * Method that supplies a String describing this PushCopyChunk - for scheduler - * Log purposes! It returns the request token of This request. - */ - public String getName() { - - return String.format("Copy for SURL %s to SURL %s", requestData.getSURL(), - requestData.getDestinationSURL()); - } - - @Override - public String getUserDN() { - - return gu.getDn(); - } - - @Override - public String getSURL() { - - return requestData.getSURL().toString(); - } - - @Override - public boolean isResultSuccess() { - - return requestData.getStatus().isSRM_SUCCESS(); - } - - abstract protected GetOperationResult executeGetOperation(); - - abstract protected PutOperationResult executePutOperation( - TSizeInBytes getFileSize); - - abstract protected TransferResult executeTransfer(GetOperationResult get, - PutOperationResult put); - - public interface Result { - - /** - * Method that returns a boolean indicating the result of the transfer. - */ - public boolean successful(); - - /** - * Method that returns a String explaining the failure of the transfer: an - * empty String is returned in cawe of successful transfer. - */ - public String failureExplanation(); - } - - public enum ResultType { - PUT, GET, TRANSFER - } - - /** - * Protected auxiliary class holding the results from a Transfer. It contains - * a boolean indicating whether the operation completed normally or could not - * proceed; in this case it also contains an explanation string of the - * failure. - * - * @author EGRID - ICTP Trieste - * @verson 1.0 - * @date September, 2005 - */ - protected class TransferResult implements Result { - - private boolean successful = false; - private String failureExplanation = ""; - - /** - * Constructor used to indicate a failed transfer: it requires a String - * explaining the failure. - */ - public TransferResult(String failureExplanation) { - - if (failureExplanation == null) { - failureExplanation = ""; - } - this.successful = false; - this.failureExplanation = failureExplanation; - } - - /** - * Constructor used to indicate a succesful transfer. - */ - public TransferResult() { - - this.successful = true; - this.failureExplanation = ""; - } - - /** - * Method that returns a boolean indicating the result of the transfer. - */ - public boolean successful() { - - return successful; - } - - /** - * Method that returns a String explaining the failure of the transfer: an - * empty String is returned in cawe of successful transfer. - */ - public String failureExplanation() { - - return failureExplanation; - } - } - - /** - * Protected auxiliary class holding the results from a GetOperation. It - * contains a boolean indicating whether the GetOperation was successful or - * could not complete normally: beware that it does _not_ consider the SRM - * status. It only indicates whether the internal steps were all completed - * normally. - * - * It also contains the TReturnStatus, the TTURL and the TFileSize, as well as - * a failureExplanation String. - */ - protected class GetOperationResult implements Result { - - /** - * boolean indicating if the operation was successful - */ - private boolean successful = false; - - /** - * TReturnStatus from srmPrepareToGet - */ - private TReturnStatus status; - - /** - * TURL from srmPrepareToGet - */ - private TTURL getTURL = TTURL.makeEmpty(); - - /** - * filesize from srmPrepareToGet - */ - private TSizeInBytes filesize = TSizeInBytes.makeEmpty(); - - /** - * String containing an explanation of failure - */ - private String failureExplanation = ""; - - /** - * request token assigned to PtG request - */ - private TRequestToken rt = null; - - /** - * Constructor that returns a successful GetOperationResult containing the - * TReturnStatus, TTURL, filesize and TRequestToken. If any of the supplied - * parameters is null, a failed GetOperationResult is returned containing - * the empty String as error explanation. - */ - public GetOperationResult(TReturnStatus status, TTURL getTURL, - TSizeInBytes filesize, TRequestToken rt) { - - if ((status != null) && (getTURL != null) && (filesize != null) - && (rt != null)) { - this.successful = true; - this.status = status; - this.getTURL = getTURL; - this.filesize = filesize; - this.rt = rt; - } else { - this.successful = false; - this.status = new TReturnStatus(TStatusCode.SRM_CUSTOM_STATUS); - } - } - - /** - * Constructor that returns a failed GetOperationResult containing a - * failureExplanation String; if it is null, an empty String is used - * instead. - */ - public GetOperationResult(String failureExplanation) { - - if (failureExplanation == null) { - failureExplanation = ""; - } - this.successful = false; - this.failureExplanation = failureExplanation; - this.status = new TReturnStatus(TStatusCode.SRM_CUSTOM_STATUS); - } - - /** - * Method that returns true if the GetOperation completed successfully. - */ - public boolean successful() { - - return this.successful; - } - - /** - * Method that returns the final status of the request - */ - public TReturnStatus status() { - - return status; - } - - /** - * Method that returns the String with the explanation of the failure. - */ - public String failureExplanation() { - - return failureExplanation; - } - - /** - * Method that returns the TURL. - */ - public TTURL getTURL() { - - return getTURL; - } - - /** - * Method that returns the filesize. - */ - public TSizeInBytes filesize() { - - return filesize; - } - - /** - * Method that returns the TRequestToken associated with the PtG. - */ - public TRequestToken requetToken() { - - return rt; - } - - @Override - public String toString() { - - return String.format("GetOperationResult: successful=%b; status=%s; " - + "getTURL=%s; filesize=%s; requestToken=%s", successful, status, - getTURL, filesize, rt); - } - } - - /** - * Private auxiliary class holding the results from a PutOperation. It - * contains a boolean indicating whether the PutOperation was successful or - * could not complete normally: beware that it does _not_ consider the SRM - * status. It only indicates whether the internal steps were all completed - * normally. - * - * It also contains the TReturnStatus and the TURL, as well as a - * failureExplanation String and the TRequestToken associated with that - * request. - */ - protected class PutOperationResult implements Result { - - private boolean successful = false; - private TReturnStatus status; - private TTURL putTURL = TTURL.makeEmpty(); - private String failureExplanation = ""; - private TRequestToken rt = null; - - /** - * Constructor to make a successful PutOperationResult containing the - * TReturnStatus and the TURL. If any of the supplied parameters is null, a - * failed PutOperationResult is returned containing the empty String as - * error explanation. - */ - public PutOperationResult(TReturnStatus status, TTURL putTURL, - TRequestToken rt) { - - if ((status != null) && (putTURL != null) && (rt != null)) { - this.successful = true; - this.status = status; - this.putTURL = putTURL; - this.rt = rt; - } else { - this.successful = false; - this.status = new TReturnStatus(TStatusCode.SRM_CUSTOM_STATUS); - } - } - - /** - * Constructor to make a failed PutOperationResult containing a - * failureExplanation String; if it is null, an empty String is used - * instead. - */ - public PutOperationResult(String failureExplanation) { - - if (failureExplanation == null) { - failureExplanation = ""; - } - this.successful = false; - this.failureExplanation = failureExplanation; - this.status = new TReturnStatus(TStatusCode.SRM_CUSTOM_STATUS); - } - - /** - * Method that returns true if the PutOperation completed all its internal - * steps. - */ - public boolean successful() { - - return this.successful; - } - - /** - * Method that returns the final status reached by the request - */ - public TReturnStatus status() { - - return this.status; - } - - /** - * Method that returns the String with the explanation of the failure. - */ - public String failureExplanation() { - - return failureExplanation; - } - - /** - * Method that returns the TURL. - */ - public TTURL putTURL() { - - return putTURL; - } - - /** - * Method that returns the TRequestToken associated to the PtP - */ - public TRequestToken requestToken() { - - return this.rt; - } - - @Override - public String toString() { - - return String.format("PutOperationResult: successful=%b; status=%s; " - + "putTURL=%s; failureExplanation=%s", successful, status, putTURL, - failureExplanation); - } - } -} diff --git a/src/main/java/it/grid/storm/asynch/CopyFeeder.java b/src/main/java/it/grid/storm/asynch/CopyFeeder.java deleted file mode 100644 index ac29379f..00000000 --- a/src/main/java/it/grid/storm/asynch/CopyFeeder.java +++ /dev/null @@ -1,268 +0,0 @@ -/* - * - * Copyright (c) Istituto Nazionale di Fisica Nucleare (INFN). 2006-2010. - * - * Licensed under the Apache License, Version 2.0 (the "License"); you may not - * use this file except in compliance with the License. You may obtain a copy of - * the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations under - * the License. - */ - -package it.grid.storm.asynch; - -import it.grid.storm.catalogs.CopyChunkCatalog; -import it.grid.storm.catalogs.CopyPersistentChunkData; -import it.grid.storm.catalogs.RequestSummaryCatalog; -import it.grid.storm.catalogs.RequestSummaryData; -import it.grid.storm.griduser.GridUserInterface; -import it.grid.storm.scheduler.Delegable; -import it.grid.storm.scheduler.SchedulerException; -import it.grid.storm.srm.types.TSURL; - -import java.util.Collection; - -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -/** - * This class represents a Copy Feeder: the Feeder that will handle the srmCopy - * statements. It chops a multifile request into its constituent parts. - * Recursive chunks will also get expanded. - * - * If the request contains nothing to process, an error message gets logged, the - * number of queued requests is decreased, and the number of finished requests - * is increased. - * - * Each single part of the request is handled as follows: the number of queued - * requests is decreased, the number of progressing requests is increased, the - * status of that chunk is changed to SRM_REQUEST_INPROGRESS; the chunk is given - * to the scheduler for handling. In case the scheduler cannot accept the chunk - * for any reason, a messagge with the requestToken and the chunk s data is - * logged, status of the chunk passes to SRM_ABORTED, and at the end the - * counters are such that the queued-requests is decreased while the - * finished-requests is increased. - * - * FOR NOW RECURSIVE REQUESTS ARE *NOT* HANDLED! The chunk fails with SRM_ABORT - * and an appropriate error string. - * - * @author EGRID - ICTP Trieste - * @date September, 2005 - * @version 2.0 - */ -public final class CopyFeeder implements Delegable { - - private static Logger log = LoggerFactory.getLogger(CopyFeeder.class); - /* RequestSummaryData this CopyFeeder refers to. */ - private RequestSummaryData rsd = null; - /* GridUser for this PtPFeeder. */ - private GridUserInterface gu = null; - /* Overall request status. */ - private GlobalStatusManager gsm = null; - - /** - * Public constructor requiring the RequestSummaryData to which this - * CopyFeeder refers to, as well as the GridUser. In case of null objects, an - * InvalidCopyFeederAttributesException is thrown. - */ - public CopyFeeder(RequestSummaryData rsd) - throws InvalidCopyFeederAttributesException { - - if (rsd == null) { - throw new InvalidCopyFeederAttributesException(null, null, null); - } - if (rsd.gridUser() == null) { - throw new InvalidCopyFeederAttributesException(rsd, null, null); - } - try { - gu = rsd.gridUser(); - this.rsd = rsd; - gsm = new GlobalStatusManager(rsd.requestToken()); - } catch (InvalidOverallRequestAttributeException e) { - log.error("ATTENTION in CopyFeeder! " - + "Programming bug when creating GlobalStatusManager! {}", e); - throw new InvalidCopyFeederAttributesException(rsd, gu, gsm); - } - } - - /** - * This method splits a multifile request; it then creates the necessary tasks - * and loads them into the Copy chunk scheduler. - */ - public void doIt() { - - log.debug("CopyFeeder: pre-processing " + rsd.requestToken()); - /* Get all parts in request */ - Collection chunks = CopyChunkCatalog.getInstance() - .lookup(rsd.requestToken()); - if (chunks.isEmpty()) { - log.warn("ATTENTION in CopyFeeder! This SRM Copy request contained " - + "nothing to process! {}", rsd.requestToken()); - RequestSummaryCatalog.getInstance().failRequest(rsd, - "This SRM Copy request contained nothing to process!"); - } else { - manageChunks(chunks); - log.debug("CopyFeeder: finished pre-processing {}", rsd.requestToken()); - } - } - - /** - * Private method that handles the Collection of chunks associated with the - * srm command! - */ - private void manageChunks(Collection chunksData) { - - log.debug("CopyFeeder: number of chunks in request {}", chunksData.size()); - int counter = 0; // counter of the number of chunk retrieved - for (CopyPersistentChunkData chunkData : chunksData) { - /* Add chunk for global status consideration */ - gsm.addChunk(chunkData); - manage(chunkData, counter++); - } - /* - * no more chunks need to be cosidered for the overall status computation - */ - gsm.finishedAdding(); - } - - /** - * Private method that handles the chunk! - */ - private void manage(CopyPersistentChunkData chunkData, int counter) { - - log.debug("CopyFeeder: scheduling chunk... "); - try { - /* change status of this chunk to being processed! */ - chunkData - .changeStatusSRM_REQUEST_INPROGRESS("srmCopy chunk is being processed!"); - CopyChunkCatalog.getInstance().update(chunkData); - boolean validFromSurl = TSURL.isValid(chunkData.getSURL()); - boolean validToSurl = TSURL.isValid(chunkData.getDestinationSURL()); - if (validFromSurl) { - if (validToSurl) { - /* - * source and destination are the same physical machine! make a local - * copy! - */ - /* - * For now it is being handled as a special case of ush copy! MUST BE - * CHANGED SOON!!! ONLY FOR DEBUG PURPOSES!!! - */ - log.info("CopyFeeder: chunk is localCopy."); - log.debug("Request: {}", rsd.requestToken()); - log.debug("Chunk: {]", chunkData); - - SchedulerFacade - .getInstance() - .chunkScheduler() - .schedule( - new PushCopyPersistentChunk(gu, rsd, chunkData, counter, gsm)); - - log.info("CopyFeeder: chunk scheduled."); - } else { - - /* - * source is this machine, but destination is elsewhere! make a push - * copy to destination! - */ - log.info("CopyFeeder: chunk is pushCopy."); - log.debug("Request: {}", rsd.requestToken()); - log.debug("Chunk: {}", chunkData); - - SchedulerFacade - .getInstance() - .chunkScheduler() - .schedule( - new PushCopyPersistentChunk(gu, rsd, chunkData, counter, gsm)); - - log.info("CopyFeeder: chunk scheduled."); - } - } else { - if (validToSurl) { - /* - * destination is this machine, but _source_ is elsewhere! make a pull - * copy from the source! - */ - /* - * WARNING!!! OPERATION NOT SUPPORTED!!! MUST BE CHANGED SOON!!! - */ - log.warn("CopyFeeder: srmCopy in pull mode NOT supported yet!"); - log.debug("Request: {}", rsd.requestToken()); - log.debug("Chunk: {}", chunkData); - - chunkData - .changeStatusSRM_NOT_SUPPORTED("srmCopy in pull mode NOT supported yet!"); - - CopyChunkCatalog.getInstance().update(chunkData); - /* - * inform global status computation of the chunk s failure - */ - gsm.failedChunk(chunkData); - } else { - /* - * boolean condition is (!names.contains(from) && !names.contains(to)) - * operation between two foreign machines! it is forbidden! - */ - log.warn("CopyFeeder: srmCopy contract violation! Neither fromSURL" - + " nor toSURL are this machine! Cannot do a third party SRM" - + " transfer as per protocol!"); - log.warn("Request: {}", rsd.requestToken()); - log.warn("Chunk: {}", chunkData); - - chunkData - .changeStatusSRM_FAILURE("SRM protocol violation! Cannot do an srmCopy between third parties!"); - - CopyChunkCatalog.getInstance().update(chunkData); - /* - * inform global status computation of the chunk s failure - */ - gsm.failedChunk(chunkData); - } - } - } catch (InvalidCopyAttributesException e) { - /* - * for some reason gu, rsd or auxChunkData may be null! This should not be - * so! - */ - log.error("UNEXPECTED ERROR in CopyFeeder! Chunk could not be created!\n" - + e); - log.error("Request: {}", rsd.requestToken()); - log.error("Chunk: {}", chunkData); - - chunkData - .changeStatusSRM_FAILURE("StoRM internal error does not allow this chunk to be processed!"); - - CopyChunkCatalog.getInstance().update(chunkData); - /* inform global status computation of the chunk s failure */ - gsm.failedChunk(chunkData); - } catch (SchedulerException e) { - /* Internal error of scheduler! */ - log.error("UNEXPECTED ERROR in ChunkScheduler! Chunk could not be " - + "scheduled!\n{}", e); - log.error("Request: {}", rsd.requestToken()); - log.error("Chunk: {}", chunkData); - - chunkData - .changeStatusSRM_FAILURE("StoRM internal scheduler error prevented this chunk from being processed!"); - - CopyChunkCatalog.getInstance().update(chunkData); - /* inform global status computation of the chunk s failure */ - gsm.failedChunk(chunkData); - } - } - - /** - * Method used by chunk scheduler for internal logging; it returns the request - * token! - */ - public String getName() { - - return "CopyFeeder of request: " + rsd.requestToken(); - } -} diff --git a/src/main/java/it/grid/storm/asynch/CopyPersistentChunk.java b/src/main/java/it/grid/storm/asynch/CopyPersistentChunk.java deleted file mode 100644 index 36c3ce1d..00000000 --- a/src/main/java/it/grid/storm/asynch/CopyPersistentChunk.java +++ /dev/null @@ -1,93 +0,0 @@ -/* - * - * Copyright (c) Istituto Nazionale di Fisica Nucleare (INFN). 2006-2010. - * - * Licensed under the Apache License, Version 2.0 (the "License"); you may not - * use this file except in compliance with the License. You may obtain a copy of - * the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations under - * the License. - */ - -package it.grid.storm.asynch; - -import it.grid.storm.catalogs.CopyChunkCatalog; -import it.grid.storm.catalogs.CopyPersistentChunkData; -import it.grid.storm.catalogs.RequestSummaryData; -import it.grid.storm.griduser.GridUserInterface; -import it.grid.storm.scheduler.PersistentRequestChunk; - -/** - * Public super class from which both the PushCopyChunk and the PullCopyChunk - * are derived. - * - * @author EGRID - ICTP Trieste - * @version 2.0 - * @date september, 2005 - */ -public abstract class CopyPersistentChunk extends Copy implements - PersistentRequestChunk { - - protected RequestSummaryData rsd = null; - protected GlobalStatusManager gsm = null; - - /** - * Constructor requiring the GridUser, the RequestSummaryData, the - * CopyChunkData about this chunk, and the integer representing the progessive - * number of the chunk being handled, and the GlobalStatusManager. If the - * supplied attributes are null or the counter is negative, an - * InvalidCopyChunkAttributesException is thrown. - */ - public CopyPersistentChunk(GridUserInterface gu, RequestSummaryData rsd, - CopyPersistentChunkData requestData, int n, GlobalStatusManager gsm) - throws InvalidCopyAttributesException, - InvalidCopyPersistentChunkAttributesException { - - super(gu, requestData, n); - if (rsd == null || gsm == null) { - throw new InvalidCopyPersistentChunkAttributesException(gu, rsd, - requestData, n, gsm); - } - this.rsd = rsd; - this.gsm = gsm; - } - - /** - * Method that supplies a String describing this PushCopyChunk - for scheduler - * Log purposes! It returns the request token of This request. - */ - public String getName() { - - return "RequestToken of srmCopy: " - + ((CopyPersistentChunkData) requestData).getRequestToken(); - } - - @Override - public void persistStatus() { - - CopyChunkCatalog.getInstance() - .update((CopyPersistentChunkData) requestData); - } - - @Override - public String getRequestToken() { - - return ((CopyPersistentChunkData) requestData).getRequestToken().getValue(); - } - - @Override - public void updateGlobalStatus() { - - if (this.failure) { - gsm.failedChunk((CopyPersistentChunkData) requestData); - } else { - gsm.successfulChunk((CopyPersistentChunkData) requestData); - } - } -} diff --git a/src/main/java/it/grid/storm/asynch/CopyVisitor.java b/src/main/java/it/grid/storm/asynch/CopyVisitor.java deleted file mode 100644 index 08e3a912..00000000 --- a/src/main/java/it/grid/storm/asynch/CopyVisitor.java +++ /dev/null @@ -1,6 +0,0 @@ -package it.grid.storm.asynch; - -public interface CopyVisitor { - - public Copy.Result visit(VisitableCopy copy); -} diff --git a/src/main/java/it/grid/storm/asynch/GridFTPTransferClient.java b/src/main/java/it/grid/storm/asynch/GridFTPTransferClient.java deleted file mode 100644 index 0caebfd5..00000000 --- a/src/main/java/it/grid/storm/asynch/GridFTPTransferClient.java +++ /dev/null @@ -1,45 +0,0 @@ -/* - * - * Copyright (c) Istituto Nazionale di Fisica Nucleare (INFN). 2006-2010. - * - * Licensed under the Apache License, Version 2.0 (the "License"); you may not - * use this file except in compliance with the License. You may obtain a copy of - * the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations under - * the License. - */ - -package it.grid.storm.asynch; - -import it.grid.storm.srm.types.TTURL; -import it.grid.storm.griduser.GridUserInterface; - -/** - * Interface that represents a GridFTP client: it supplies functionality to - * execute a file transfer through the GSIFTP protocol. - * - * @author EGRID - ICTP Trieste - * @version 1.0 - * @date September 2005 - */ -public interface GridFTPTransferClient { - - /** - * Method used to transfer a local file to a remote location; it needs the - * GridUser whose credentails (proxy) will be used forthe transfer, a local - * TURL that designates a file and so must have file as protocol, a remote - * TURL that designates the destination and so must have gsiftp as protocol. - * - * If any problem does not allow the transfer to proceed, a - * GridFTPTransferClientException is thrown containing a String that explains - * what went wrong. - */ - public void putFile(GridUserInterface gu, TTURL local, TTURL remote) - throws GridFTPTransferClientException; -} diff --git a/src/main/java/it/grid/storm/asynch/GridFTPTransferClientException.java b/src/main/java/it/grid/storm/asynch/GridFTPTransferClientException.java deleted file mode 100644 index a41f9a01..00000000 --- a/src/main/java/it/grid/storm/asynch/GridFTPTransferClientException.java +++ /dev/null @@ -1,46 +0,0 @@ -/* - * - * Copyright (c) Istituto Nazionale di Fisica Nucleare (INFN). 2006-2010. - * - * Licensed under the Apache License, Version 2.0 (the "License"); you may not - * use this file except in compliance with the License. You may obtain a copy of - * the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations under - * the License. - */ - -package it.grid.storm.asynch; - -/** - * Class that represents an exception thrown by a GridFTPTransferClient, in case - * for any reason the operation could not be carried out. - * - * @author EGRID - ICTP Trieste - * @version 1.0 - * @date September, 2005 - */ -public class GridFTPTransferClientException extends Exception { - - private String explanation = ""; // String containing an explanation of what - // went wrong - - /** - * Constructor that requires a String with an explanation of what went wrong. - */ - public GridFTPTransferClientException(String explanation) { - - if (explanation != null) - this.explanation = explanation; - } - - public String toString() { - - return explanation; - } -} diff --git a/src/main/java/it/grid/storm/asynch/GridFTPTransferClientFactory.java b/src/main/java/it/grid/storm/asynch/GridFTPTransferClientFactory.java deleted file mode 100644 index 6ab48c40..00000000 --- a/src/main/java/it/grid/storm/asynch/GridFTPTransferClientFactory.java +++ /dev/null @@ -1,68 +0,0 @@ -/* - * - * Copyright (c) Istituto Nazionale di Fisica Nucleare (INFN). 2006-2010. - * - * Licensed under the Apache License, Version 2.0 (the "License"); you may not - * use this file except in compliance with the License. You may obtain a copy of - * the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations under - * the License. - */ - -package it.grid.storm.asynch; - -import it.grid.storm.config.Configuration; - -/** - * Class that represents a factory of GridFTPTransferClients. It allows for the - * creation of clients from classes specified in the configuration file. - * - * @author EGRID - ICTP Trieste - * @version 1.0 - * @date September 2005 - */ -public class GridFTPTransferClientFactory { - - final private static GridFTPTransferClientFactory factory = new GridFTPTransferClientFactory(); // only - // instance - // of - // GridFTPTraqnsferClientFactory! - - private GridFTPTransferClientFactory() { - - } - - /** - * Methos that returns the only instance of the factory. - */ - public static GridFTPTransferClientFactory getInstance() { - - return factory; - } - - /** - * Method that returns a new instance of a GridFTPTransferClient. If the - * configured class cannot be supplied, a - * NoGridFTPTransferClientFoundException is thrown. - */ - synchronized public GridFTPTransferClient client() - throws NoGridFTPTransferClientFoundException { - - try { - String client = Configuration.getInstance().getGridFTPTransferClient(); - return (GridFTPTransferClient) Class.forName(client).newInstance(); - } catch (ClassNotFoundException e) { - throw new NoGridFTPTransferClientFoundException(e.toString()); - } catch (InstantiationException e) { - throw new NoGridFTPTransferClientFoundException(e.toString()); - } catch (IllegalAccessException e) { - throw new NoGridFTPTransferClientFoundException(e.toString()); - } - } -} diff --git a/src/main/java/it/grid/storm/asynch/GridFTPTransferClientStub.java b/src/main/java/it/grid/storm/asynch/GridFTPTransferClientStub.java deleted file mode 100644 index cd3c4694..00000000 --- a/src/main/java/it/grid/storm/asynch/GridFTPTransferClientStub.java +++ /dev/null @@ -1,43 +0,0 @@ -/* - * - * Copyright (c) Istituto Nazionale di Fisica Nucleare (INFN). 2006-2010. - * - * Licensed under the Apache License, Version 2.0 (the "License"); you may not - * use this file except in compliance with the License. You may obtain a copy of - * the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations under - * the License. - */ - -package it.grid.storm.asynch; - -import it.grid.storm.srm.types.TTURL; -import it.grid.storm.griduser.GridUserInterface; - -/** - * Class that represents a Stub for the GridFTPTransferClient. The methods - * implemeted do not carry out any action. - * - * @author EGRID - ICTP Trieste - * @version 2.0 - * @date September, 2005 - */ -public class GridFTPTransferClientStub implements GridFTPTransferClient { - - /** - * This is a stub implementation that does nothing. - */ - public void putFile(GridUserInterface gu, TTURL local, TTURL remote) - throws GridFTPTransferClientException { - - if (false) - throw new GridFTPTransferClientException( - "Exception in stub! Should not occur!"); - } -} diff --git a/src/main/java/it/grid/storm/asynch/InvalidCopyAttributesException.java b/src/main/java/it/grid/storm/asynch/InvalidCopyAttributesException.java deleted file mode 100644 index 03b4d43b..00000000 --- a/src/main/java/it/grid/storm/asynch/InvalidCopyAttributesException.java +++ /dev/null @@ -1,62 +0,0 @@ -/* - * - * Copyright (c) Istituto Nazionale di Fisica Nucleare (INFN). 2006-2010. - * - * Licensed under the Apache License, Version 2.0 (the "License"); you may not - * use this file except in compliance with the License. You may obtain a copy of - * the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations under - * the License. - */ - -package it.grid.storm.asynch; - -import it.grid.storm.catalogs.CopyData; -import it.grid.storm.griduser.GridUserInterface; - -/** - * This class represents an Exceptin thrown when a copyChunk is created with any - * null attribute: GridUser, RequestSummaryData, CopyChunkData, - * GlobalStatusManager or with a negative counter n. - * - * @author: EGRID - ICTP Trieste - * @version: 2.0 - * @date: September, 2005 - */ -public class InvalidCopyAttributesException extends - InvalidRequestAttributesException { - - private static final long serialVersionUID = -4447773252958307986L; - protected boolean negativeN = true; - - /** - * Constructor that requires the GridUser, RequestSummaryData and - * CopyChunkData, as well as the int counter, that caused the exception to be - * thrown. - */ - public InvalidCopyAttributesException(GridUserInterface gu, - CopyData chunkData, int n) { - - super(gu, chunkData); - negativeN = (n < 0); - } - - /* - * (non-Javadoc) - * - * @see java.lang.Object#toString() - */ - @Override - public String toString() { - - return String.format("InvalidCopyAttributesException [negativeN=%b, " - + "nullGu=%b, nullChunkData=%b]", negativeN, nullGu, nullChunkData); - - } -} diff --git a/src/main/java/it/grid/storm/asynch/InvalidCopyFeederAttributesException.java b/src/main/java/it/grid/storm/asynch/InvalidCopyFeederAttributesException.java deleted file mode 100644 index 71982752..00000000 --- a/src/main/java/it/grid/storm/asynch/InvalidCopyFeederAttributesException.java +++ /dev/null @@ -1,56 +0,0 @@ -/* - * - * Copyright (c) Istituto Nazionale di Fisica Nucleare (INFN). 2006-2010. - * - * Licensed under the Apache License, Version 2.0 (the "License"); you may not - * use this file except in compliance with the License. You may obtain a copy of - * the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations under - * the License. - */ - -package it.grid.storm.asynch; - -import it.grid.storm.catalogs.RequestSummaryData; -import it.grid.storm.griduser.GridUserInterface; - -/** - * Class that represents an Exception thrown when a copyFeeder could not be - * created because the supplied RequestSummayData or GridUser or - * GlobalStatusManager were null. - * - * @author EGRID ICTP - * @version 3.0 - * @date September, 2005 - */ -public class InvalidCopyFeederAttributesException extends Exception { - - private boolean nullRequestSummaryData = false; - private boolean nullGridUser = false; - private boolean nullGlobalStatusManager = false; - - /** - * Public constructor that requires the RequestSummaryData and the GridUser - * that caused the exception to be thrown. - */ - public InvalidCopyFeederAttributesException(RequestSummaryData rsd, - GridUserInterface gu, GlobalStatusManager gsm) { - - nullRequestSummaryData = (rsd == null); - nullGridUser = (gu == null); - nullGlobalStatusManager = (gsm == null); - } - - public String toString() { - - return String.format("null-RequestSummaryData=%b; null-GridUser=%b; " - + "null-GlobalStatusManager=%b", nullRequestSummaryData, nullGridUser, - nullGlobalStatusManager); - } -} diff --git a/src/main/java/it/grid/storm/asynch/InvalidCopyPersistentChunkAttributesException.java b/src/main/java/it/grid/storm/asynch/InvalidCopyPersistentChunkAttributesException.java deleted file mode 100644 index 46131f6f..00000000 --- a/src/main/java/it/grid/storm/asynch/InvalidCopyPersistentChunkAttributesException.java +++ /dev/null @@ -1,55 +0,0 @@ -/* - * Copyright (c) Istituto Nazionale di Fisica Nucleare (INFN). 2006-2010. - * Licensed under the Apache License, Version 2.0 (the "License"); you may not - * use this file except in compliance with the License. You may obtain a copy of - * the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by - * applicable law or agreed to in writing, software distributed under the - * License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS - * OF ANY KIND, either express or implied. See the License for the specific - * language governing permissions and limitations under the License. - */ - -package it.grid.storm.asynch; - -import it.grid.storm.catalogs.CopyPersistentChunkData; -import it.grid.storm.catalogs.RequestSummaryData; -import it.grid.storm.griduser.GridUserInterface; - -/** - * @author Michele Dibenedetto - * - */ -public class InvalidCopyPersistentChunkAttributesException extends - InvalidCopyAttributesException { - - private static final long serialVersionUID = -474846490237202316L; - protected boolean nullrsd = true; - protected boolean nullgsm = true; - - /** - * Constructor that requires the GridUser, RequestSummaryData and - * CopyChunkData, as well as the int counter, that caused the exception to be - * thrown. - */ - public InvalidCopyPersistentChunkAttributesException(GridUserInterface gu, - RequestSummaryData rsd, CopyPersistentChunkData requestData, int n, - GlobalStatusManager gsm) { - - super(gu, requestData, n); - nullrsd = (rsd == null); - nullgsm = (gsm == null); - } - - /* - * (non-Javadoc) - * - * @see java.lang.Object#toString() - */ - @Override - public String toString() { - - return String.format("InvalidCopyPersistentChunkAttributesException " - + "[nullrsd=%b, nullgsm=%b, negativeN=%b, nullGu=%b, nullChunkData=%b]", - nullrsd, nullgsm, negativeN, nullGu, nullChunkData); - } -} diff --git a/src/main/java/it/grid/storm/asynch/NaiveGridFTPTransferClient.java b/src/main/java/it/grid/storm/asynch/NaiveGridFTPTransferClient.java deleted file mode 100644 index 7a45faef..00000000 --- a/src/main/java/it/grid/storm/asynch/NaiveGridFTPTransferClient.java +++ /dev/null @@ -1,126 +0,0 @@ -/* - * - * Copyright (c) Istituto Nazionale di Fisica Nucleare (INFN). 2006-2010. - * - * Licensed under the Apache License, Version 2.0 (the "License"); you may not - * use this file except in compliance with the License. You may obtain a copy of - * the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations under - * the License. - */ - -package it.grid.storm.asynch; - -import it.grid.storm.common.types.TransferProtocol; -import it.grid.storm.config.Configuration; -import it.grid.storm.griduser.AbstractGridUser; -import it.grid.storm.griduser.GridUserInterface; -import it.grid.storm.srm.types.TTURL; - -import java.io.ByteArrayInputStream; -import java.io.File; -import java.io.IOException; -import java.io.InputStream; - -import org.globus.ftp.FeatureList; -import org.globus.ftp.GridFTPClient; -import org.globus.ftp.Session; -import org.globus.ftp.exception.ClientException; -import org.globus.ftp.exception.ServerException; -import org.globus.gsi.GlobusCredential; -import org.globus.gsi.GlobusCredentialException; -import org.globus.gsi.gssapi.GlobusGSSCredentialImpl; -import org.ietf.jgss.GSSCredential; -import org.ietf.jgss.GSSException; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -/** - * This class represents a GridFTP client; it is naive in that it makes no use - * of extended features of GridFTP such as parallel streams and transfers - * between third parties. Moreover, it does not share a data channel for - * multiple file transfers. The performance, therefore, can be greatly improved - * upon! - * - * Moreover, to maintain compatibility with old GSIFTP servers, it sets - * DataChannelAuthentication to none. - * - * @author EGRID - ICTP Trieste - * @version 2.0 - * @date September, 2005 - */ -public class NaiveGridFTPTransferClient implements GridFTPTransferClient { - - private static final Logger log = LoggerFactory - .getLogger(NaiveGridFTPTransferClient.class); - - /** - * Implementation of inherited put method: it executes a put of a file as per - * contract specified in the interface. In particular - * GridFTPTransferClientException is thrown if: the local TURL does not have - * file as protocol, or the remote one does not have gsiftp as protocol; no - * credentials (proxy) were found, there were problems with the proxy itself, - * or there were problems with the security framework that handles the proxy; - * a generic input/output problem occured; the GridFTP server reported some - * problems; there were client side problems. - */ - public void putFile(GridUserInterface gu, TTURL local, TTURL remote) - throws GridFTPTransferClientException { - - boolean localIsFile = (local.protocol() == TransferProtocol.FILE); - boolean remoteIsGSIFTP = (remote.protocol() == TransferProtocol.GSIFTP); - if (!localIsFile || !remoteIsGSIFTP) { - throw new GridFTPTransferClientException( - "Unsupported local/remote protocol: local-is-file=" + localIsFile - + ", remote-is-GSIFTP=" + remoteIsGSIFTP); - } - String fullLocalFile = "/" + local.tfn().pfn().getValue(); - String fullRemoteFile = "/" + remote.tfn().pfn().getValue(); - try { - InputStream proxy = new ByteArrayInputStream(((AbstractGridUser) gu) - .getUserCredentials().getBytes()); - int remotePort = 2811; - if (!remote.tfn().port().isEmpty()) { - remotePort = remote.tfn().port().toInt(); - } - GridFTPClient client = new GridFTPClient(remote.tfn().machine() - .getValue(), remotePort); - client.authenticate(new GlobusGSSCredentialImpl(new GlobusCredential( - proxy), GSSCredential.INITIATE_AND_ACCEPT)); - client.setType(Session.TYPE_IMAGE); - FeatureList fl = client.getFeatureList(); - log.debug("NAIVE GSIFTP CLIENT: Remote server supports {}", fl.toString()); - if (!fl.contains(FeatureList.DCAU)) { - log.debug("NAIVE GSIFTP CLIENT: disabling DCAU"); - client.setLocalNoDataChannelAuthentication(); // compatibility with old - // GSIFTP server! - } - client.setClientWaitParams(Configuration.getInstance() - .getGridFTPTimeOut(), Session.DEFAULT_WAIT_DELAY); - client.put(new File(fullLocalFile), fullRemoteFile, false); - client.close(); - // } catch (InvalidTUserIDAttributeException e) { - // throw new GridFTPTransferClientException("No proxy found!"); - } catch (IOException e) { - throw new GridFTPTransferClientException(e.toString()); - } catch (ServerException e) { - throw new GridFTPTransferClientException(e.toString()); - } catch (ClientException e) { - throw new GridFTPTransferClientException(e.toString()); - } catch (GlobusCredentialException e) { - throw new GridFTPTransferClientException(e.toString()); - } catch (GSSException e) { - throw new GridFTPTransferClientException(e.toString()); - } catch (Exception e) { - // Catch any runtime exception! - throw new GridFTPTransferClientException( - "Unexpected runtime error in NaiveGridFTPTransferClient! " + e); - } - } -} diff --git a/src/main/java/it/grid/storm/asynch/NaiveSRMClient.java b/src/main/java/it/grid/storm/asynch/NaiveSRMClient.java deleted file mode 100644 index 9466c6b6..00000000 --- a/src/main/java/it/grid/storm/asynch/NaiveSRMClient.java +++ /dev/null @@ -1,380 +0,0 @@ -/* - * - * Copyright (c) Istituto Nazionale di Fisica Nucleare (INFN). 2006-2010. - * - * Licensed under the Apache License, Version 2.0 (the "License"); you may not - * use this file except in compliance with the License. You may obtain a copy of - * the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations under - * the License. - */ - -package it.grid.storm.asynch; - -import it.grid.storm.common.types.TransferProtocol; -import it.grid.storm.griduser.AbstractGridUser; -import it.grid.storm.griduser.GridUserInterface; -import it.grid.storm.srm.types.TFileStorageType; -import it.grid.storm.srm.types.TLifeTimeInSeconds; -import it.grid.storm.srm.types.TOverwriteMode; -import it.grid.storm.srm.types.TRequestToken; -import it.grid.storm.srm.types.TSURL; -import it.grid.storm.srm.types.TSizeInBytes; -import it.grid.storm.srm.types.TSpaceToken; - -import java.io.ByteArrayInputStream; -import java.io.InputStream; - -import javax.xml.rpc.Stub; -import javax.xml.rpc.soap.SOAPFaultException; - -import org.apache.axis.SimpleTargetedChain; -import org.apache.axis.configuration.SimpleProvider; -import org.apache.axis.transport.http.HTTPSender; -import org.globus.axis.transport.GSIHTTPSender; -import org.globus.axis.transport.GSIHTTPTransport; -import org.globus.axis.util.Util; -import org.globus.gsi.GlobusCredential; -import org.globus.gsi.GlobusCredentialException; -import org.globus.gsi.gssapi.GlobusGSSCredentialImpl; -import org.globus.gsi.gssapi.auth.NoAuthorization; -import org.ietf.jgss.GSSCredential; -import org.ietf.jgss.GSSException; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -/** - * Class that represents a first implementation of an SRMClient. - * - * @author EGRID - ICTP Trieste - * @version 2.0 - * @date October, 2005 - */ -public class NaiveSRMClient implements SRMClient { - - private static Logger log = LoggerFactory.getLogger(NaiveSRMClient.class); - - /** - * Method used to execute an srmPrepareToPut. - * - * It will connect to the webservice derived from the toSURL using the - * credentials available in GridUser. It requires the lifetime, the - * fileStorageType, the spaceToken, the fileSize, the protocol, a description, - * the overwriteOption, the retryTime. The method returns an - * SRMPrepareToPutReply containing the result of the operation, and throws an - * SRMClient exception in case the operation cannot be completed. - * - * This client is said to be naive, because given the reply from an - * SRMPrepareToPut, the client checks the srm field of the whole request to - * obtain the request token which the remote srm server associated to the - * request; it _ignores_ the return status of the whole request; it _ignores_ - * the status for the specific file requested. - * - * This is important to keep in mind, because there can be remote servers that - * have specific ways of behaving such as leaving the specific file status - * blank until a status for the whole request is completed, etc. - */ - public SRMPrepareToPutReply prepareToPut(GridUserInterface gu, TSURL toSURL, - TLifeTimeInSeconds lifetime, TFileStorageType fileStorageType, - TSpaceToken spaceToken, TSizeInBytes filesize, TransferProtocol protocol, - String description, TOverwriteMode overwriteOption, - TLifeTimeInSeconds retryTime) throws SRMClientException { - - try { - srmClientStubs.ISRM _srm = setUpGSI(gu, toSURL); - - // prepare srm request and execute it - srmClientStubs.SrmPrepareToPutRequest req = new srmClientStubs.SrmPrepareToPutRequest(); - // set authorization ID - String stubuid = gu.getDn(); - req.setAuthorizationID(stubuid); - // set description - req.setUserRequestDescription(description); - // set array of transfer protocols - String[] protocolArray = new String[1]; - protocolArray[0] = protocol.toString(); - srmClientStubs.ArrayOfString protocolArrayString = new srmClientStubs.ArrayOfString(); - protocolArrayString.setStringArray(protocolArray); - srmClientStubs.TTransferParameters stubtp = new srmClientStubs.TTransferParameters(); - stubtp.setArrayOfTransferProtocols(protocolArrayString); - req.setTransferParameters(stubtp); - // set Overwrite Option - req.setOverwriteOption(new WSOverwriteModeConverter() - .fromStoRM(overwriteOption)); - // set retry time - req.setDesiredTotalRequestTime(new Integer(new Long(retryTime.value()) - .intValue())); - - // set storage type - srmClientStubs.TFileStorageType stubfst = new WSFileStorageTypeConverter() - .fromStoRM(fileStorageType); // ws file storage type! - req.setDesiredFileStorageType(stubfst); - // set space token - req.setTargetSpaceToken(spaceToken.toString()); - // set lifetime - req.setDesiredFileLifeTime(new Integer(new Long(lifetime.value()) - .intValue())); - - // set request specific info - // ws put file request! - srmClientStubs.TPutFileRequest stubpfr = new srmClientStubs.TPutFileRequest(); - // set file size - org.apache.axis.types.UnsignedLong ulFileSize = new org.apache.axis.types.UnsignedLong( - filesize.value()); - stubpfr.setExpectedFileSize(ulFileSize); - // set target SURL - stubpfr.setTargetSURL(new org.apache.axis.types.URI(toSURL.toString())); - - // set array of requests ws array of put file request! - srmClientStubs.TPutFileRequest[] stubpfrArray = new srmClientStubs.TPutFileRequest[1]; - stubpfrArray[0] = stubpfr; - srmClientStubs.ArrayOfTPutFileRequest arrayOfPut = new srmClientStubs.ArrayOfTPutFileRequest( - stubpfrArray); - req.setArrayOfFileRequests(arrayOfPut); - - // execute request! - log.debug("NAIVE SRM CLIENT: sending request {}", arrayOfPut); - srmClientStubs.SrmPrepareToPutResponse response = _srm - .srmPrepareToPut(req); - log.debug("NAIVE SRM CLIENT: received reply {}", response); - - // get TRequestToken - it.grid.storm.srm.types.TRequestToken requestToken = new WSRequestTokenConverter() - .fromWS(response.getRequestToken()); - // get ArrayOfTPutRequestFileStatus - srmClientStubs.ArrayOfTPutRequestFileStatus arrayOfPutFileStatuses = response - .getArrayOfFileStatuses(); - srmClientStubs.TPutRequestFileStatus[] stubFileStatusArray = arrayOfPutFileStatuses - .getStatusArray(); - // get specific request - srmClientStubs.TPutRequestFileStatus stubFileStatus = stubFileStatusArray[0]; - srmClientStubs.TReturnStatus stubStatus = stubFileStatus.getStatus(); - it.grid.storm.srm.types.TReturnStatus retStat = WSReturnStatusConverter - .getInstance().fromWS(stubStatus); - return new SRMPrepareToPutReply(requestToken); - - } catch (it.grid.storm.srm.types.InvalidTUserIDAttributeException e) { - // GridUser threw an exception! Cannot get credentials! - throw new SRMClientException( - "Unexpected error in NaiveSRMClient! Cannot get gredentials from GridUser! " - + e); - } catch (GlobusCredentialException e) { - // Globus credentials cannot be created! - throw new SRMClientException( - "Unexpected error in NaiveSRMClient! Cannot create GlobusCredentials from GridUser! " - + e); - } catch (GSSException e) { - // GSS credentials cannot be created! - throw new SRMClientException( - "Unexpected error in NaiveSRMClient! Cannot create GSSCredentials from GlobusCredential! " - + e); - } catch (org.apache.axis.types.URI.MalformedURIException ex) { - // This is a programming bug and should not occur! The URI is malformed! - throw new SRMClientException( - "Unexpected error in NaiveSRMClient! Cannot create URI! " + ex); - } catch (javax.xml.rpc.ServiceException ex) { - // Something went wrong with the web service! - throw new SRMClientException("Web Service problem! " + ex); - } catch (java.rmi.RemoteException ex) { - // something went wrong at low level communication with web service! - throw new SRMClientException("Web Service Communication problem! " + ex); - } catch (SOAPFaultException e) { - // The remote service launched an exception! This is a programmatic - // exception remotely thrown, _not_ an error! - throw new SRMClientException( - "The remote web service launched an exception! " + e); - } catch (WSConversionException e) { - // The data received from the web service could not be translated into - // StoRM object model equivalents! - throw new SRMClientException( - "There were problems translating between WebService and StoRM object model! " - + e); - } catch (InvalidPutReplyAttributeException e) { - // This is a programming bug and should not occur! For some reason, - // correctly translated WebService attributes - // did not allow the correct creation of an SRMPrepareToPutReply! - throw new SRMClientException( - "Unexpected error in NaiveSRMClient! Cannot create a reply to return! " - + e); - } catch (Exception e) { - // Unexpected runtime exception! For example, a time out when connectin to - // the web service! - throw new SRMClientException( - "Unexpected runtime error in NaiveSRMClient! " + e); - } // end synchronized! - } - - /** - * Method used to execute an srmStatusOfPutRequest: it requires the request - * token returned durign an srmPrepareToPut operation, the GridUser that - * issued the command, and the toSURL of the request. An - * SRMStatusOfPutRequestReply is returned, but in case the operation fails an - * SRMClientException is thrown containing an explanation String. - * - * This client is said to be naive, because given the reply from an - * SRMStatusOfPutRequest, the client checks the srm field of the specific file - * to obtain both the TURL and the status of the request, _ignoring_ the - * overall request status. - * - * This is important to keep in mind, because there can be remote servers that - * have specific ways of behaving such as leaving the specific file status - * blank until a status for the whole request is completed, etc. - */ - public SRMStatusOfPutRequestReply statusOfPutRequest( - it.grid.storm.srm.types.TRequestToken rt, GridUserInterface gu, - it.grid.storm.srm.types.TSURL toSURL) throws SRMClientException { - - try { - srmClientStubs.ISRM _srm = setUpGSI(gu, toSURL); - - // prepare srm request and execute it - srmClientStubs.SrmStatusOfPutRequestRequest req = new srmClientStubs.SrmStatusOfPutRequestRequest(); - // set TRequestToken - req.setRequestToken(rt.toString()); - // set Authorization ID - req.setAuthorizationID(gu.getDn()); - // set SURL array - org.apache.axis.types.URI[] stubSurlArray = new org.apache.axis.types.URI[1]; - org.apache.axis.types.URI stubSurl = new org.apache.axis.types.URI( - toSURL.toString()); - stubSurlArray[0] = stubSurl; - srmClientStubs.ArrayOfAnyURI arrayOfTSURL = new srmClientStubs.ArrayOfAnyURI( - stubSurlArray); - req.setArrayOfTargetSURLs(arrayOfTSURL); - - log.debug("NAIVE SRM CLIENT: invoking status of put with {}", req); - srmClientStubs.SrmStatusOfPutRequestResponse response = _srm - .srmStatusOfPutRequest(req); - log.debug("NAIVE SRM CLIENT: received response {}", response); - - // process response - srmClientStubs.ArrayOfTPutRequestFileStatus arrayOfPutStatuses = response - .getArrayOfFileStatuses(); - srmClientStubs.TPutRequestFileStatus[] stubFileStatusArray = arrayOfPutStatuses - .getStatusArray(); - srmClientStubs.TPutRequestFileStatus stubFileStatus = stubFileStatusArray[0]; - org.apache.axis.types.URI stubTurl = stubFileStatus.getTransferURL(); - srmClientStubs.TReturnStatus stubStatus = stubFileStatus.getStatus(); - - it.grid.storm.srm.types.TTURL turl = new WSTurlConverter() - .fromWS(stubTurl); - it.grid.storm.srm.types.TReturnStatus retStat = WSReturnStatusConverter - .getInstance().fromWS(stubStatus); - return new SRMStatusOfPutRequestReply(turl, retStat); - } catch (it.grid.storm.srm.types.InvalidTUserIDAttributeException e) { - // GridUser threw an exception! Cannot get credentials! - throw new SRMClientException( - "Unexpected error in NaiveSRMClient! Cannot get gredentials from GridUser! " - + e); - } catch (GlobusCredentialException e) { - // Globus credentials cannot be created! - throw new SRMClientException( - "Unexpected error in NaiveSRMClient! Cannot create GlobusCredentials from GridUser! " - + e); - } catch (GSSException e) { - // GSS credentials cannot be created! - throw new SRMClientException( - "Unexpected error in NaiveSRMClient! Cannot create GSSCredentials from GlobusCredential! " - + e); - } catch (org.apache.axis.types.URI.MalformedURIException ex) { - // This is a programming bug and should not occur! The URI is malformed! - throw new SRMClientException( - "Unexpected error in NaiveSRMClient! Cannot create URI! " + ex); - } catch (javax.xml.rpc.ServiceException ex) { - // Something went wrong with the web service! - throw new SRMClientException("Web Service problem! " + ex); - } catch (java.rmi.RemoteException ex) { - // something went wrong at low level communication with web service! - throw new SRMClientException("Communication problem! " + ex); - } catch (SOAPFaultException e) { - // the remote service launched an exception! This is a programmatic - // exception remotely thrown, _not_ an error! - throw new SRMClientException( - "The remote web service launched an exception! " + e); - } catch (WSConversionException e) { - // the data received fro mthe web service could not be translated into - // StoRM object model equivalents! - throw new SRMClientException( - "The answer received from the WebService cannot be converted to StoRM object model! " - + e); - } catch (InvalidPutStatusAttributesException e) { - // This is a programming bug and should not occur! For some reason, - // correctly translated WebService attributes - // did not allow the correct creation of an SRMStatusOfPutRequestReply! - throw new SRMClientException( - "Unexpected error in NaiveSRMClient! Cannot create a reply to return! " - + e); - } catch (Exception e) { - // Catch any runtime exceptions, such as a time out! - throw new SRMClientException( - "Unexpected runtime error in NaiveSRMClient! " + e); - } // end synchronized! - } - - /** - * Method that returns an SRMPutDoneReply containing TReturnStatus with - * TStatusCode.SRM_SUCCESS, and explanation string "DUMMY SUCCESS". - */ - public SRMPutDoneReply srmPutDone(TRequestToken rt, GridUserInterface gu, - TSURL toSURL) throws SRMClientException { - - return null; - } - - /** - * Private auxiliary method that sets up a secure GSI connection for the given - * GridUser to the specfied toSURL. The method returns the service interface. - */ - private srmClientStubs.ISRM setUpGSI(GridUserInterface gu, - it.grid.storm.srm.types.TSURL toSURL) - throws javax.xml.rpc.ServiceException, GlobusCredentialException, - GSSException, it.grid.storm.srm.types.InvalidTUserIDAttributeException { - - // get web service, setting HTTP and HTTPG as transport! - Util.registerTransport(); - SimpleProvider provider = new SimpleProvider(); - SimpleTargetedChain c = null; - c = new SimpleTargetedChain(new GSIHTTPSender()); - provider.deployTransport("httpg", c); - c = new SimpleTargetedChain(new HTTPSender()); - provider.deployTransport("http", c); - srmClientStubs.SRMService sRMService = new srmClientStubs.SRMServiceLocator( - provider); - srmClientStubs.ISRM _srm = sRMService.getsrm(); - - // set proxy in stub - if (((AbstractGridUser) gu).getUserCredentials() == null) { - log.error("ERROR in NaiveSRMClient! No proxy present for {}", gu.getDn()); - } - // String containing the proxy seen as an input stream! - InputStream proxy = new ByteArrayInputStream(((AbstractGridUser) gu) - .getUserCredentials().getBytes()); - // GSSCredential containing the proxy! - GSSCredential globusProxy = new GlobusGSSCredentialImpl( - new GlobusCredential(proxy), GSSCredential.INITIATE_AND_ACCEPT); - // set the proxy to be used during GSI connection! - ((Stub) _srm)._setProperty(GSIHTTPTransport.GSI_CREDENTIALS, globusProxy); - // set the authorization that will be performed by the web service for the - // supplied credentails! - ((Stub) _srm)._setProperty(GSIHTTPTransport.GSI_AUTHORIZATION, - NoAuthorization.getInstance()); - // set the supply of both private and public key of credentials - ((Stub) _srm)._setProperty(GSIHTTPTransport.GSI_MODE, - GSIHTTPTransport.GSI_MODE_NO_DELEG); - - // set service endpoint address - String sea = String.format("httpg://%s:%s/", toSURL.sfn().machine(), toSURL - .sfn().port()); - ((Stub) _srm)._setProperty(Stub.ENDPOINT_ADDRESS_PROPERTY, sea); - - // return the interface - return _srm; - } - -} diff --git a/src/main/java/it/grid/storm/asynch/NoGridFTPTransferClientFoundException.java b/src/main/java/it/grid/storm/asynch/NoGridFTPTransferClientFoundException.java deleted file mode 100644 index a04c73da..00000000 --- a/src/main/java/it/grid/storm/asynch/NoGridFTPTransferClientFoundException.java +++ /dev/null @@ -1,45 +0,0 @@ -/* - * - * Copyright (c) Istituto Nazionale di Fisica Nucleare (INFN). 2006-2010. - * - * Licensed under the Apache License, Version 2.0 (the "License"); you may not - * use this file except in compliance with the License. You may obtain a copy of - * the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations under - * the License. - */ - -package it.grid.storm.asynch; - -/** - * Class that represents an exception thrown if the class specified in the - * config file for the GridFTPTransferClient, cannot be instantiated. - * - * @author EGRID - ICTP Trieste - * @version 1.0 - * @date September 2005 - */ -public class NoGridFTPTransferClientFoundException extends Exception { - - private String explanation = ""; - - /** - * Constructor that requires a String explaining the error. - */ - public NoGridFTPTransferClientFoundException(String explanation) { - - if (explanation != null) - this.explanation = explanation; - } - - public String toString() { - - return explanation; - } -} diff --git a/src/main/java/it/grid/storm/asynch/NoSRMClientFoundException.java b/src/main/java/it/grid/storm/asynch/NoSRMClientFoundException.java deleted file mode 100644 index 05f8be6c..00000000 --- a/src/main/java/it/grid/storm/asynch/NoSRMClientFoundException.java +++ /dev/null @@ -1,45 +0,0 @@ -/* - * - * Copyright (c) Istituto Nazionale di Fisica Nucleare (INFN). 2006-2010. - * - * Licensed under the Apache License, Version 2.0 (the "License"); you may not - * use this file except in compliance with the License. You may obtain a copy of - * the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations under - * the License. - */ - -package it.grid.storm.asynch; - -/** - * Class that represents an exception thrown if the class specified in the - * config file for the SRMClient, cannot be instantiated. - * - * @author EGRID - ICTP Trieste - * @version 1.0 - * @date September 2005 - */ -public class NoSRMClientFoundException extends Exception { - - private String explanation = ""; - - /** - * Constructor that requires a String explaining the error. - */ - public NoSRMClientFoundException(String explanation) { - - if (explanation != null) - this.explanation = explanation; - } - - public String toString() { - - return explanation; - } -} diff --git a/src/main/java/it/grid/storm/asynch/OperationResultBuilder.java b/src/main/java/it/grid/storm/asynch/OperationResultBuilder.java deleted file mode 100644 index d9b8a0d3..00000000 --- a/src/main/java/it/grid/storm/asynch/OperationResultBuilder.java +++ /dev/null @@ -1,100 +0,0 @@ -package it.grid.storm.asynch; - -import it.grid.storm.asynch.Copy.Result; -import it.grid.storm.asynch.Copy.ResultType; -import it.grid.storm.srm.types.TRequestToken; -import it.grid.storm.srm.types.TReturnStatus; -import it.grid.storm.srm.types.TSizeInBytes; -import it.grid.storm.srm.types.TTURL; -import java.util.List; - -public class OperationResultBuilder { - - public static Result build(Copy copy, List arguments, ResultType type) { - - switch (type) { - case GET: - if (arguments.size() != 4) { - throw new IllegalArgumentException( - "Unable to create GetOperationResult, requierd 4 parameters, provides \'" - + arguments.size() + "\'"); - } - if (arguments.get(1) != null - && !(arguments.get(1) instanceof TReturnStatus)) { - throw new IllegalArgumentException( - "Unable to create GetOperationResult, parameter 1 must be a TReturnStatus, provided \'" - + arguments.get(1).getClass() + "\'"); - } - if (arguments.get(2) != null && !(arguments.get(2) instanceof TTURL)) { - throw new IllegalArgumentException( - "Unable to create GetOperationResult, parameter 2 must be a TTURL, provided \'" - + arguments.get(2).getClass() + "\'"); - } - if (arguments.get(3) != null - && !(arguments.get(3) instanceof TSizeInBytes)) { - throw new IllegalArgumentException( - "Unable to create GetOperationResult, parameter 3 must be a TSizeInBytes, provided \'" - + arguments.get(3).getClass() + "\'"); - } - if (!(arguments.get(4) != null && arguments.get(4) instanceof TRequestToken)) { - throw new IllegalArgumentException( - "Unable to create GetOperationResult, parameter 4 must be a TRequestToken, provided \'" - + arguments.get(4).getClass() + "\'"); - } - return copy.new GetOperationResult((TReturnStatus) arguments.get(1), - (TTURL) arguments.get(2), (TSizeInBytes) arguments.get(3), - (TRequestToken) arguments.get(4)); - case PUT: - if (arguments.size() != 3) { - throw new IllegalArgumentException( - "Unable to create GetOperationResult, requierd 3 parameters, provides \'" - + arguments.size() + "\'"); - } - if (arguments.get(1) != null - && !(arguments.get(1) instanceof TReturnStatus)) { - throw new IllegalArgumentException( - "Unable to create GetOperationResult, parameter 1 must be a TReturnStatus, provided \'" - + arguments.get(1).getClass() + "\'"); - } - if (arguments.get(2) != null && !(arguments.get(2) instanceof TTURL)) { - throw new IllegalArgumentException( - "Unable to create GetOperationResult, parameter 2 must be a TTURL, provided \'" - + arguments.get(2).getClass() + "\'"); - } - if (arguments.get(3) != null - && !(arguments.get(3) instanceof TRequestToken)) { - throw new IllegalArgumentException( - "Unable to create GetOperationResult, parameter 3 must be a TRequestToken, provided \'" - + arguments.get(3).getClass() + "\'"); - } - return copy.new PutOperationResult((TReturnStatus) arguments.get(1), - (TTURL) arguments.get(2), (TRequestToken) arguments.get(3)); - case TRANSFER: - if (arguments.size() != 0) { - throw new IllegalArgumentException( - "Unable to create GetOperationResult, requierd 0 parameters, provides \'" - + arguments.size() + "\'"); - } - return copy.new TransferResult(); - default: - throw new IllegalArgumentException( - "Unable to create a Result, unknown Copy.ResultType \'" + type + "\'"); - } - } - - public static Result build(Copy copy, String string, ResultType type) { - - switch (type) { - case GET: - return copy.new GetOperationResult(string); - case PUT: - return copy.new PutOperationResult(string); - case TRANSFER: - return copy.new TransferResult(string); - default: - throw new IllegalArgumentException( - "Unable to create a Result, unknown Copy.ResultType \'" + type + "\'"); - } - } - -} diff --git a/src/main/java/it/grid/storm/asynch/PtP.java b/src/main/java/it/grid/storm/asynch/PtP.java index 135c9d67..94b2a211 100644 --- a/src/main/java/it/grid/storm/asynch/PtP.java +++ b/src/main/java/it/grid/storm/asynch/PtP.java @@ -384,7 +384,7 @@ private void managePermit(StoRI fileStoRI) { requestData.changeStatusSRM_NOT_SUPPORTED("Unable to build TURL with " + "specified transfer protocols!"); failure = true; - log.error("ERROR in PtPChunk! No valid transfer protocol found."); + log.error("ERROR in PtPChunk! No valid transfer protocol found. {}", e.getMessage(), e); return; } catch (TURLBuildingException e) { requestData.changeStatusSRM_FAILURE("Unable to build the TURL for the " diff --git a/src/main/java/it/grid/storm/asynch/PushCopy.java b/src/main/java/it/grid/storm/asynch/PushCopy.java deleted file mode 100644 index c96043ae..00000000 --- a/src/main/java/it/grid/storm/asynch/PushCopy.java +++ /dev/null @@ -1,175 +0,0 @@ -/* - * - * Copyright (c) Istituto Nazionale di Fisica Nucleare (INFN). 2006-2010. - * - * Licensed under the Apache License, Version 2.0 (the "License"); you may not - * use this file except in compliance with the License. You may obtain a copy of - * the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations under - * the License. - */ - -package it.grid.storm.asynch; - -import java.util.List; -import it.grid.storm.catalogs.CopyData; -import it.grid.storm.griduser.GridUserInterface; -import it.grid.storm.srm.types.TRequestToken; -import it.grid.storm.srm.types.TReturnStatus; -import it.grid.storm.srm.types.TSizeInBytes; -import it.grid.storm.srm.types.TTURL; - -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -/** - * SubClass of CopyChunk that handles Push mode, that is, the SRM server that - * receives the srmCopy request transfers a file from itself (local) to another - * SRM server (remote). - * - * The executeGetOpeartion method is overwritten with logic to handle a local - * srmPreparToGet; the executePutOperation method is overwritten with logic to - * handle a remote srmPrepareToPut through the use of an internal SRMClient; the - * executeTransfer method is overwritten to carry out a GridFTP put of the local - * file to the remote location. - * - * @author EGRID - ICTP Trieste - * @date September, 2005 - * @version 2.0 - */ -public class PushCopy extends Copy implements VisitableCopy { - - private static Logger log = LoggerFactory.getLogger(PushCopy.class); - - public PushCopy(GridUserInterface gu, CopyData chunkData, int n) - throws InvalidCopyAttributesException { - - super(gu, chunkData, n); - } - - /** - * In PushMode the getOperation is a _local_ srmPtG. - * - * A requestSummary is then made having the new requestToken, requestType set - * to PREPARE_TO_GET, the same GridUser that issued the srmCopy request. - * - * A PtGChunkData is created and the PtGChunkCatalog is asked to save it in - * persistence. It is made with: the new requestToken, the fromSURL of the - * srmCopy, the lifeTime from the srmCopy, empty TSpaceToken, dirOption set to - * non directory and non recursive, TURLPrefix with TransferProtocol.FILE, - * empty fileSize, TReturnStatus set to SRM_REQUEST_QUEUED and explanation - * string "PushCopyChunk has queued this local srmPrepareToGet operation; - * srmCopy request " followed by the requestToken of the srmCopy, empty TTURL. - * - * A PtGChunk is therefore constructed and executed right away. - * - * The local execution of the srmPtG has some preliminary steps to be - * completed before actually starting it; if this preparatory phase cannot be - * completed thereby not even allowing the initiation of the local operation, - * a Failed GetOperationResult is returned; but if it can start, then a - * successful GetOperationResult is returned regardless of the SRM status. - */ - @Override - protected GetOperationResult executeGetOperation() { - - PushCopyGetVisitor visitor = new PushCopyGetVisitor(); - return (GetOperationResult) visitor.visit(this); - } - - /** - * In PushMode the PutOperation consists of a _remote_ srmPrepareToPut. - * - * The SRMClient is invoked specifying the same GridUser that made the srmCopy - * request, the toSURL, the same fileLifetime specified in the srmCopy, the - * same fileStorageType specified in the srmCopy, the same spaceToken - * specified in the srmCopy, the file size from the getOperation, GSIFTP as - * transfer protocol, "StoRM Remote PtP for (push) srmCopy" as description - * string, the same overwriteOption specified in the srmCopy, a retry time - * found in the Configuration class from getSRMClientPutTimeOut(). - * - * Polling then starts by invoking the SRMClient statusOfPutRequest() - * specifying: the request token from the reply to the remote srmPtP - * operation, the same GridUser that made the srmCopy request, and the toSURL - * from the original srmCopy request. The time-out is calculated from the - * Configuration class from getSRMClientPutTimeOut(); the polling frequency is - * derived from the Configuration class from getSRMClientPutSleepTime(). - * - * Once the polled status reaches a state different from SRM_QUEUED and - * SRM_REQUEST_IN_PROGRESS, a successfull PutOperationResult is returned - * containing the TURL and the TReturnStatus; if the operation times out, then - * a failed PutOperationResult is returned; in case the SRMClient has any - * problem carrying out its functionality, a failed PutOperationResult is - * returned containing the error message returned by the exception thrown by - * SRMClient. - * - * For each of the possible resuts, appropriate messagges get logged! - */ - @Override - protected PutOperationResult executePutOperation(TSizeInBytes getFileSize) { - - PushCopyPutVisitor visitor = new PushCopyPutVisitor(getFileSize); - return (PutOperationResult) visitor.visit(this); - } - - /** - * In PushMode the transfer operation consists of a PUT of the local file into - * the remote storage area. - * - * If the transfer fails, then a failed TransferResult is returned with a - * failureExplanation String; otherwise a successful TransferResult is - * returned. - * - * This operation also invokes an srmPutDone on the remote server. - */ - @Override - protected TransferResult executeTransfer(GetOperationResult get, - PutOperationResult put) { - - PushCopyTransferVisitor visitor = new PushCopyTransferVisitor(get, put); - return (TransferResult) visitor.visit(this); - } - - @Override - public TRequestToken getLocalrt() { - - return this.localrt; - } - - @Override - public GridUserInterface getGu() { - - return this.gu; - } - - @Override - public CopyData getRequestData() { - - return this.requestData; - } - - @Override - public Logger getLog() { - - return PushCopy.log; - } - - @Override - public Result buildOperationResult(String string, Copy.ResultType type) - throws IllegalArgumentException { - - return OperationResultBuilder.build(this, string, type); - } - - @Override - public Result buildOperationResult(List arguments, ResultType type) - throws IllegalArgumentException { - - return OperationResultBuilder.build(this, arguments, type); - } -} diff --git a/src/main/java/it/grid/storm/asynch/PushCopyGetVisitor.java b/src/main/java/it/grid/storm/asynch/PushCopyGetVisitor.java deleted file mode 100644 index c3ffca7c..00000000 --- a/src/main/java/it/grid/storm/asynch/PushCopyGetVisitor.java +++ /dev/null @@ -1,88 +0,0 @@ -/* - * - * Copyright (c) Istituto Nazionale di Fisica Nucleare (INFN). 2006-2010. - * - * Licensed under the Apache License, Version 2.0 (the "License"); you may not - * use this file except in compliance with the License. You may obtain a copy of - * the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations under - * the License. - */ - -package it.grid.storm.asynch; - -import java.util.ArrayList; -import it.grid.storm.asynch.Copy.ResultType; -import it.grid.storm.catalogs.PtGChunkCatalog; -import it.grid.storm.catalogs.PtGPersistentChunkData; -import it.grid.storm.catalogs.RequestSummaryData; -import it.grid.storm.common.types.TURLPrefix; -import it.grid.storm.namespace.model.Protocol; -import it.grid.storm.srm.types.TDirOption; -import it.grid.storm.srm.types.TRequestType; -import it.grid.storm.srm.types.TReturnStatus; -import it.grid.storm.srm.types.TSizeInBytes; -import it.grid.storm.srm.types.TStatusCode; -import it.grid.storm.srm.types.TTURL; - -/** - * @author Michele Dibenedetto - */ -public class PushCopyGetVisitor implements CopyVisitor { - - @Override - public Copy.Result visit(VisitableCopy copy) { - - try { - RequestSummaryData ptgrsd = new RequestSummaryData( - TRequestType.PREPARE_TO_GET, copy.getLocalrt(), copy.getGu()); - TURLPrefix turlPrefix = new TURLPrefix(); - turlPrefix.addProtocol(Protocol.FILE); - PtGPersistentChunkData ptgChunkData = new PtGPersistentChunkData( - copy.getGu(), - copy.getLocalrt(), - copy.getRequestData().getSURL(), - copy.getRequestData().getLifetime(), - new TDirOption(false, false, 0), - turlPrefix, - TSizeInBytes.makeEmpty(), - new TReturnStatus( - TStatusCode.SRM_REQUEST_QUEUED, - "PushCopyChunk has queued this local srmPrepareToGet operation; srmCopy request on SURL" - + copy.getRequestData().getSURL()), TTURL.makeEmpty()); - copy.getLog().debug( - "executeGetOperation: adding new chunkData to PtGCatalog!"); - PtGChunkCatalog.getInstance().add(ptgChunkData, copy.getGu()); - copy.getLog() - .debug("executeGetOperation: finished adding to PtGCatalog!"); - - GlobalStatusManager gsm = new GlobalStatusManager(copy.getLocalrt()); - gsm.addChunk(ptgChunkData); - gsm.finishedAdding(); - PtGPersistentChunk ptgChunk = new PtGPersistentChunk(ptgrsd, - ptgChunkData, gsm); - copy.getLog().debug("executeGetOperation: starting ptgChunk.doIt()!"); - ptgChunk.doIt(); - copy.getLog().debug("executeGetOperation: finished ptgChunk.doIt()!"); - ArrayList parameters = new ArrayList(4); - parameters.add(1, ptgChunkData.getStatus()); - parameters.add(2, ptgChunkData.getTransferURL()); - parameters.add(3, ptgChunkData.getFileSize()); - parameters.add(4, copy.getLocalrt()); - return copy.buildOperationResult(parameters, ResultType.GET); - } catch (Exception e) { - copy.getLog().error("ERROR IN PushCopyChunk! Cannot initiate local PtG! " - + "Requested SURL: {}", copy.getRequestData().getSURL()); - copy.getLog().error(e.getMessage(), e); - return copy.buildOperationResult("Cannot initiate local PtG! " + e, - ResultType.GET); - } - } - -} diff --git a/src/main/java/it/grid/storm/asynch/PushCopyPersistentChunk.java b/src/main/java/it/grid/storm/asynch/PushCopyPersistentChunk.java deleted file mode 100644 index b0a9423b..00000000 --- a/src/main/java/it/grid/storm/asynch/PushCopyPersistentChunk.java +++ /dev/null @@ -1,121 +0,0 @@ -/* - * - * Copyright (c) Istituto Nazionale di Fisica Nucleare (INFN). 2006-2010. - * - * Licensed under the Apache License, Version 2.0 (the "License"); you may not - * use this file except in compliance with the License. You may obtain a copy of - * the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations under - * the License. - */ - -package it.grid.storm.asynch; - -import it.grid.storm.catalogs.CopyData; -import it.grid.storm.catalogs.CopyPersistentChunkData; -import it.grid.storm.catalogs.RequestSummaryData; -import it.grid.storm.griduser.GridUserInterface; -import it.grid.storm.srm.types.TRequestToken; -import it.grid.storm.srm.types.TSizeInBytes; - -import java.util.List; - -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -/** - * SubClass of CopyChunk that handles Push mode, that is, the SRM server that - * receives the srmCopy request transfers a file from itself (local) to another - * SRM server (remote). - * - * The executeGetOpeartion method is overwritten with logic to handle a local - * srmPreparToGet; the executePutOperation method is overwritten with logic to - * handle a remote srmPrepareToPut through the use of an internal SRMClient; the - * executeTransfer method is overwritten to carry out a GridFTP put of the local - * file to the remote locattion. - * - * @author EGRID - ICTP Trieste - * @date September, 2005 - * @version 2.0 - */ -public class PushCopyPersistentChunk extends CopyPersistentChunk implements - VisitableCopy { - - public PushCopyPersistentChunk(GridUserInterface gu, RequestSummaryData rsd, - CopyPersistentChunkData requestData, int n, GlobalStatusManager gsm) - throws InvalidCopyAttributesException, - InvalidCopyPersistentChunkAttributesException { - - super(gu, rsd, requestData, n, gsm); - } - - private static Logger log = LoggerFactory - .getLogger(PushCopyPersistentChunk.class); - - @Override - protected GetOperationResult executeGetOperation() { - - PushCopyGetVisitor visitor = new PushCopyGetVisitor(); - return (GetOperationResult) visitor.visit(this); - } - - @Override - protected PutOperationResult executePutOperation(TSizeInBytes getFileSize) { - - PushCopyPutVisitor visitor = new PushCopyPutVisitor(getFileSize); - return (PutOperationResult) visitor.visit(this); - } - - @Override - protected TransferResult executeTransfer(GetOperationResult get, - PutOperationResult put) { - - PushCopyTransferVisitor visitor = new PushCopyTransferVisitor(get, put); - return (TransferResult) visitor.visit(this); - } - - @Override - public TRequestToken getLocalrt() { - - return this.localrt; - } - - @Override - public GridUserInterface getGu() { - - return this.gu; - } - - @Override - public CopyData getRequestData() { - - return this.requestData; - } - - @Override - public Logger getLog() { - - return PushCopyPersistentChunk.log; - } - - @Override - public Result buildOperationResult(String string, Copy.ResultType type) - throws IllegalArgumentException { - - return OperationResultBuilder.build(this, string, type); - } - - @Override - public Result buildOperationResult(List arguments, ResultType type) - throws IllegalArgumentException { - - return OperationResultBuilder.build(this, arguments, type); - } - -} diff --git a/src/main/java/it/grid/storm/asynch/PushCopyPutVisitor.java b/src/main/java/it/grid/storm/asynch/PushCopyPutVisitor.java deleted file mode 100644 index f82671f5..00000000 --- a/src/main/java/it/grid/storm/asynch/PushCopyPutVisitor.java +++ /dev/null @@ -1,173 +0,0 @@ -package it.grid.storm.asynch; - -import java.util.ArrayList; -import java.util.Date; -import it.grid.storm.asynch.Copy.Result; -import it.grid.storm.asynch.Copy.ResultType; -import it.grid.storm.common.types.TimeUnit; -import it.grid.storm.common.types.TransferProtocol; -import it.grid.storm.config.Configuration; -import it.grid.storm.srm.types.TLifeTimeInSeconds; -import it.grid.storm.srm.types.TSizeInBytes; -import it.grid.storm.srm.types.TStatusCode; - -public class PushCopyPutVisitor implements CopyVisitor { - - private final TSizeInBytes getFileSize; - - @SuppressWarnings("unused") - private PushCopyPutVisitor() { - - // forbidden; - this.getFileSize = null; - } - - public PushCopyPutVisitor(TSizeInBytes getFileSize) { - - this.getFileSize = getFileSize; - } - - @Override - public Result visit(VisitableCopy copy) { - - try { - TLifeTimeInSeconds retryTime = TLifeTimeInSeconds.make(Configuration - .getInstance().getSRMClientPutTotalRetryTime(), TimeUnit.SECONDS); - try { - copy.getLog().debug("PUSH COPY CHUNK: getting SRM client..."); - SRMClient srmClient = SRMClientFactory.getInstance().client(); - copy.getLog().debug("... got it!"); - // Invoke prepareToPut functionality of SRMClient - copy.getLog().debug( - "PUSH COPY CHUNK: Invoking prepareToPut functionality..."); - SRMPrepareToPutReply reply = srmClient.prepareToPut(copy.getGu(), copy - .getRequestData().getDestinationSURL(), copy.getRequestData() - .getLifetime(), copy.getRequestData().getFileStorageType(), copy - .getRequestData().getSpaceToken(), getFileSize, - TransferProtocol.GSIFTP, "StoRM Remote PtP for (push) srmCopy", copy - .getRequestData().getOverwriteOption(), retryTime); - copy.getLog().debug("... got it! Reply was: {}", reply); - // Polling... - long timeOut = new Date().getTime() - + Configuration.getInstance().getSRMClientPutTimeOut() * 1000; - long sleepTime = Configuration.getInstance().getSRMClientPutSleepTime() * 1000; - boolean timedOut = false; - SRMStatusOfPutRequestReply statusOfPutRequestReply = null; - TStatusCode replyCode = null; - try { - do { - copy.getLog().debug("PUSH COPY CHUNK: Going to sleep..."); - try { - Thread.sleep(sleepTime); - } catch (InterruptedException e) { - } - ; - copy.getLog().debug( - "PUSH COPY CHUNK: Waking up and verifying status..."); - statusOfPutRequestReply = srmClient.statusOfPutRequest(reply - .requestToken(), copy.getGu(), copy.getRequestData() - .getDestinationSURL()); - replyCode = statusOfPutRequestReply.returnStatus().getStatusCode(); - timedOut = (new Date().getTime() > timeOut); - copy.getLog().debug("PUSH COPY CHUNK: reply was {}; the reply code " - + "was: {}; timedOut is: {}", statusOfPutRequestReply, replyCode, - timedOut); - } while (((replyCode == TStatusCode.SRM_REQUEST_QUEUED) - || (replyCode == TStatusCode.SRM_REQUEST_INPROGRESS) - || (replyCode == TStatusCode.SRM_INTERNAL_ERROR)) - && !timedOut); - } catch (SRMClientException e2) { - // The SRMClient statusOfPutRequest functionality failed! - copy.getLog().error("ERROR IN PushCopyChunk! PutOperation failed: " - + "SRMClient could not do an srmStatusOfPutRequest! {}", e2); - StringBuilder sb = new StringBuilder(); - sb.append("Parameters passed to client: "); - sb.append("requestToken: "); - sb.append(reply.requestToken().toString()); - sb.append(", "); - sb.append("GridUser: "); - sb.append(copy.getGu().toString()); - sb.append(", "); - sb.append("toSURL: "); - sb.append(copy.getRequestData().getDestinationSURL().toString()); - sb.append("."); - copy.getLog().debug(sb.toString()); - return copy.buildOperationResult( - "SRMClient failure! Could not do an srmStatusOfPutRequest! " + e2, - ResultType.PUT); - } - // Handle all possible states... - copy.getLog().debug("PUSH COPY CHUNK: out of loop ..."); - if (timedOut) { - // Reached time out! - copy.getLog().warn( - "ATTENTION IN PushCopyChunk! PutOperation timed out!"); - return copy.buildOperationResult("PutOperation timed out!", - ResultType.PUT); - } - // The remote operation completed!!! - copy.getLog().debug("PushCopyChunk! The PutOperation completed! {}", - statusOfPutRequestReply.returnStatus()); - ArrayList parameters = new ArrayList(3); - parameters.add(1, statusOfPutRequestReply.returnStatus()); - parameters.add(2, statusOfPutRequestReply.toTURL()); - parameters.add(3, reply.requestToken()); - return copy.buildOperationResult(parameters, ResultType.PUT); - } catch (SRMClientException e1) { - // The SRMClient prepareToPut functionality failed! - copy.getLog().error("ERROR IN PushCopyChunk! PutOperation failed: " - + "SRMClient could not do an srmPrepareToPut! {}", e1); - StringBuilder sb = new StringBuilder(); - sb.append("Parameters passed to client: "); - sb.append("GridUser:"); - sb.append(copy.getGu().toString()); - sb.append(", "); - sb.append("toSURL:"); - sb.append(copy.getRequestData().getDestinationSURL().toString()); - sb.append(", "); - sb.append("lifetime:"); - sb.append(copy.getRequestData().getLifetime().toString()); - sb.append(", "); - sb.append("fileStorageType:"); - sb.append(copy.getRequestData().getFileStorageType().toString()); - sb.append(", "); - sb.append("spaceToken:"); - sb.append(copy.getRequestData().getSpaceToken().toString()); - sb.append(", "); - sb.append("fileSize:"); - sb.append(copy.getRequestData().toString()); - sb.append(", "); - sb.append("transferProtocol:"); - sb.append(TransferProtocol.GSIFTP.toString()); - sb.append(", "); - sb.append("description:"); - sb.append("StoRM Remote PtP for (push) srmCopy"); - sb.append(", "); - sb.append("overwriteOption:"); - sb.append(copy.getRequestData().getOverwriteOption().toString()); - sb.append(", "); - sb.append("retryTime:"); - sb.append(retryTime.toString()); - sb.append("."); - copy.getLog().debug(sb.toString()); - return copy.buildOperationResult( - "SRMClient failure! Could not do an srmPrepareToPut! " + e1, - ResultType.PUT); - } catch (NoSRMClientFoundException e1) { - copy.getLog().error("ERROR IN PushCopyChunk! Cannot call remote SRM " - + "server because no SRM client could be loaded! {}", e1, ResultType.PUT); - return copy - .buildOperationResult( - "Cannot talk to other SRM server because no SRM client could be loaded!", - ResultType.PUT); - } - } catch (IllegalArgumentException e3) { - // Cannot create TLifeTimeInSeconds! This is a programming bug and should - // not occur!!! - copy.getLog().error("ERROR IN PushCopyChunk! Cannot create " - + "TLifeTimeInSeconds! {}", e3.getMessage(), e3); - return copy.buildOperationResult(e3.toString(), ResultType.PUT); - } - } - -} diff --git a/src/main/java/it/grid/storm/asynch/PushCopyTransferVisitor.java b/src/main/java/it/grid/storm/asynch/PushCopyTransferVisitor.java deleted file mode 100644 index a7e7047a..00000000 --- a/src/main/java/it/grid/storm/asynch/PushCopyTransferVisitor.java +++ /dev/null @@ -1,151 +0,0 @@ -/* - * - * Copyright (c) Istituto Nazionale di Fisica Nucleare (INFN). 2006-2010. - * - * Licensed under the Apache License, Version 2.0 (the "License"); you may not - * use this file except in compliance with the License. You may obtain a copy of - * the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations under - * the License. - */ - -package it.grid.storm.asynch; - -import java.util.ArrayList; -import java.util.Date; -import it.grid.storm.asynch.Copy.GetOperationResult; -import it.grid.storm.asynch.Copy.PutOperationResult; -import it.grid.storm.asynch.Copy.Result; -import it.grid.storm.asynch.Copy.ResultType; -import it.grid.storm.config.Configuration; -import it.grid.storm.srm.types.TStatusCode; -import it.grid.storm.srm.types.TTURL; - -/** - * @author Michele Dibenedetto - * - */ -public class PushCopyTransferVisitor implements CopyVisitor { - - private final GetOperationResult get; - private final PutOperationResult put; - - @SuppressWarnings("unused") - private PushCopyTransferVisitor() { - - // forbidden - this.get = null; - this.put = null; - } - - public PushCopyTransferVisitor(GetOperationResult get, PutOperationResult put) { - - this.get = get; - this.put = put; - } - - @Override - public Result visit(VisitableCopy copy) { - - try { - TTURL getTURL = get.getTURL(); - TTURL putTURL = put.putTURL(); - // do transfer - GridFTPTransferClient gridFTPTransferClient = GridFTPTransferClientFactory - .getInstance().client(); - gridFTPTransferClient.putFile(copy.getGu(), getTURL, putTURL); - // Make an SRMClient - copy.getLog().debug( - "PUSH COPY CHUNK - executeTransfer: getting SRM client..."); - SRMClient srmClient = SRMClientFactory.getInstance().client(); - copy.getLog().debug("... got it!"); - // Invoke putDone functionality of SRMClient - // starting time from which to count the time-out! - long timeOut = new Date().getTime() - + Configuration.getInstance().getSRMClientPutDoneTimeOut() * 1000; - long sleepTime = Configuration.getInstance() - .getSRMClientPutDoneSleepTime() * 1000; // time - // interval in milliseconds for periodic polling - boolean timedOut = false; // boolean true if the operation times out - SRMPutDoneReply reply = null; - TStatusCode replyCode = null; - try { - do { - copy.getLog().debug( - "PUSH COPY CHUNK - executeTransfer: Going to sleep..."); - try { - Thread.sleep(sleepTime); - } catch (InterruptedException e) { - } - // go to sleep before executing! - copy - .getLog() - .debug( - "PUSH COPY CHUNK - executeTransfer: Waking up and invoking srmPutDone..."); - reply = srmClient.srmPutDone(put.requestToken(), copy.getGu(), copy - .getRequestData().getDestinationSURL()); - replyCode = reply.overallRetStat().getStatusCode(); - timedOut = (new Date().getTime() > timeOut); - copy.getLog().debug("PUSH COPY CHUNK: reply was {}; the reply code " - + "was: {}; timedOut is: {}", reply, replyCode, timedOut); - } while ((replyCode == TStatusCode.SRM_INTERNAL_ERROR) && !timedOut); - } catch (SRMClientException e2) { - // The SRMClient putDone functionality failed! - copy.getLog().error("File transfer completed successfully, but problems " - + "were encountered performing final srmPutDone! {}", e2); - StringBuilder sb = new StringBuilder(); - sb.append("Parameters passed to client: "); - sb.append(", "); - sb.append("GridUser: "); - sb.append(copy.getGu().toString()); - sb.append(", "); - sb.append("toSURL: "); - sb.append(copy.getRequestData().getDestinationSURL().toString()); - sb.append("."); - copy.getLog().debug(sb.toString()); - return copy - .buildOperationResult( - "File transfer completed successfully, but problems were encountered performing final srmPutDone! " - + e2, ResultType.TRANSFER); - } - if (timedOut) { - // Reached time out! - copy - .getLog() - .warn( - "File transfer completed successfully, but there was a timeout waiting for srmPutDone to return a status different from SRM_INTERNAL_ERROR!"); - return copy - .buildOperationResult( - "File transfer completed successfully, but there was a timeout waiting for srmPutDone to return a status different from SRM_INTERNAL_ERROR!", - ResultType.TRANSFER); - } - // successful! - return copy.buildOperationResult(new ArrayList(0), - ResultType.TRANSFER); - } catch (NoSRMClientFoundException e) { - copy.getLog().error("ERROR IN PushCopyChunk! TransferOperation could not " - + "invoke srmPutDone on remote SRM server because no SRM client could " - + "be loaded! {}", e); - return copy - .buildOperationResult( - "TransferOperation could not invoke srmPutDone on remote SRM server because no SRM client could be loaded!", - ResultType.TRANSFER); - } catch (GridFTPTransferClientException e) { - copy.getLog().error("ERROR IN PushCopyChunk! File transfer failed! {}", e); - return copy.buildOperationResult(e.toString(), ResultType.TRANSFER); - } catch (NoGridFTPTransferClientFoundException e) { - copy.getLog().error("ERROR IN PushCopyChunk! Cannot transfer file because " - + "no transfer client could be loaded! {}", e); - return copy.buildOperationResult( - "Cannot transfer file because no transfer client could be loaded!", - ResultType.TRANSFER); - } - } - -} diff --git a/src/main/java/it/grid/storm/asynch/SRM22Client.java b/src/main/java/it/grid/storm/asynch/SRM22Client.java deleted file mode 100644 index f3b05805..00000000 --- a/src/main/java/it/grid/storm/asynch/SRM22Client.java +++ /dev/null @@ -1,624 +0,0 @@ -/* - * - * Copyright (c) Istituto Nazionale di Fisica Nucleare (INFN). 2006-2010. - * - * Licensed under the Apache License, Version 2.0 (the "License"); you may not - * use this file except in compliance with the License. You may obtain a copy of - * the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations under - * the License. - */ - -package it.grid.storm.asynch; - -import it.grid.storm.common.types.EndPoint; -import it.grid.storm.common.types.Port; -import it.grid.storm.common.types.TransferProtocol; -import it.grid.storm.config.Configuration; -import it.grid.storm.griduser.AbstractGridUser; -import it.grid.storm.griduser.GridUserInterface; -import it.grid.storm.srm.types.InvalidTUserIDAttributeException; -import it.grid.storm.srm.types.TFileStorageType; -import it.grid.storm.srm.types.TLifeTimeInSeconds; -import it.grid.storm.srm.types.TOverwriteMode; -import it.grid.storm.srm.types.TRequestToken; -import it.grid.storm.srm.types.TSURL; -import it.grid.storm.srm.types.TSizeInBytes; -import it.grid.storm.srm.types.TSpaceToken; -import it.grid.storm.srm.types.TTURL; - -import java.io.ByteArrayInputStream; -import java.io.InputStream; - -import javax.xml.rpc.ServiceException; -import javax.xml.rpc.Stub; -import javax.xml.rpc.soap.SOAPFaultException; - -import org.apache.axis.SimpleTargetedChain; -import org.apache.axis.configuration.SimpleProvider; -import org.apache.axis.transport.http.HTTPSender; -import org.globus.axis.transport.GSIHTTPSender; -import org.globus.axis.transport.GSIHTTPTransport; -import org.globus.axis.util.Util; -import org.globus.gsi.GlobusCredential; -import org.globus.gsi.GlobusCredentialException; -import org.globus.gsi.gssapi.GlobusGSSCredentialImpl; -import org.globus.gsi.gssapi.auth.HostAuthorization; -import org.ietf.jgss.GSSCredential; -import org.ietf.jgss.GSSException; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import srmClientStubs.ISRM; - -/** - * Class that represents a first implementation of an SRMClient. - * - * @author EGRID - ICTP Trieste - * @version 3.0 - * @date October, 2005 - */ -public class SRM22Client implements SRMClient { - - private static Logger log = LoggerFactory.getLogger(SRM22Client.class); - - /** - * Method used to execute an srmPrepareToPut. - * - * It will connect to the webservice derived from the toSURL using the - * credentials available in GridUser. It requires the lifetime, the - * fileStorageType, the spaceToken, the fileSize, the protocol, a description, - * the overwriteOption, the retryTime. The method returns an - * SRMPrepareToPutReply containing the result of the operation, and throws an - * SRMClient exception in case the operation cannot be completed. - * - * The client checks the overall status of the request, and provided it is in - * either of SRM_REQUEST_QUEUED, SRM_REQUEST_INPROGESS, SRM_SUCCESS, - * SRM_PARTIAL_SUCCESS it will return the appropriate SRMPrepareToPutReply. - * Any other request level status results in an SRMClientException. - * - * If there are any errors in the communication, or the reply received from - * the other web service is incomprehensible or malformed, an - * SRMClientException is thrown with appropriate error messagges. - */ - public SRMPrepareToPutReply prepareToPut(GridUserInterface gu, TSURL toSURL, - TLifeTimeInSeconds lifetime, TFileStorageType fileStorageType, - TSpaceToken spaceToken, TSizeInBytes filesize, TransferProtocol protocol, - String description, TOverwriteMode overwriteOption, - TLifeTimeInSeconds retryTime) throws SRMClientException { - - try { - srmClientStubs.ISRM _srm = setUpGSI(gu, toSURL); - - // prepare srm request and execute it - srmClientStubs.SrmPrepareToPutRequest req = new srmClientStubs.SrmPrepareToPutRequest(); // srm - // request - // set description - log.debug("NAIVE SRM CLIENT; setting description to: {}", description); - req.setUserRequestDescription(description); - // set array of transfer protocols - String[] protocolArray = new String[1]; - protocolArray[0] = protocol.toString(); - log.debug("NAIVE SRM CLIENT; setting protocol array to: {}", (Object[]) protocolArray); - srmClientStubs.ArrayOfString protocolArrayString = new srmClientStubs.ArrayOfString(); - protocolArrayString.setStringArray(protocolArray); - srmClientStubs.TTransferParameters stubtp = new srmClientStubs.TTransferParameters(); - stubtp.setArrayOfTransferProtocols(protocolArrayString); - req.setTransferParameters(stubtp); - // set Overwrite Option - log.debug("NAIVE SRM CLIENT; setting overwrite option to: {}", overwriteOption); - req.setOverwriteOption(new WSOverwriteModeConverter() - .fromStoRM(overwriteOption)); - // set retry time - Integer dtrt = new Integer(new Long(retryTime.value()).intValue()); - log.debug("NAIVE SRM CLIENT; setting desired total request time: {}", dtrt); - req.setDesiredTotalRequestTime(dtrt); - - // set storage type - srmClientStubs.TFileStorageType stubfst = new WSFileStorageTypeConverter() - .fromStoRM(fileStorageType); // ws file storage type! - log.debug("NAIVE SRM CLIENT; setting file storage type to: {}", fileStorageType); - req.setDesiredFileStorageType(stubfst); - // set space token - if (!spaceToken.isEmpty()) { - String st = spaceToken.toString(); - log.debug("NAIVE SRM CLIENT; setting space token to: {}", st); - req.setTargetSpaceToken(st); - } else { - log.debug("NAIVE SRM CLIENT; setting space token to null. "); - } - // set lifetime - Integer dflt = new Integer(new Long(lifetime.value()).intValue()); - log.debug("NAIVE SRM CLIENT; setting desired file life time to: {}", dflt); - req.setDesiredFileLifeTime(dflt); - - // set pinLifetime - Integer dplt = new Integer(Configuration.getInstance() - .getSRM22ClientPinLifeTime()); - log.debug("NAIVE SRM CLIENT; setting desired pin life time to: {}", dplt); - req.setDesiredPinLifeTime(dplt); - - // set request specific info - srmClientStubs.TPutFileRequest stubpfr = new srmClientStubs.TPutFileRequest(); // ws - // put - // file - // request! - // set file size - long efs = filesize.value(); - log.debug("NAIVE SRM CLIENT; setting expected file size to: {}", efs); - // FIXME here we can have -1, that means the absence of information about - // filesize. manage this case considering the following method! - org.apache.axis.types.UnsignedLong ulFileSize = new org.apache.axis.types.UnsignedLong( - efs); - stubpfr.setExpectedFileSize(ulFileSize); - // set target SURL - String ts = toSURL.toString(); - log.debug("NAIVE SRM CLIENT; setting target SURL to: {}", ts); - stubpfr.setTargetSURL(new org.apache.axis.types.URI(ts)); - - // set array of requests - srmClientStubs.TPutFileRequest[] stubpfrArray = new srmClientStubs.TPutFileRequest[1]; // ws - // array - // of - // put - // file - // request! - stubpfrArray[0] = stubpfr; - srmClientStubs.ArrayOfTPutFileRequest arrayOfPut = new srmClientStubs.ArrayOfTPutFileRequest( - stubpfrArray); - req.setArrayOfFileRequests(arrayOfPut); - - // execute request! - log.debug("NAIVE SRM CLIENT: sending request {}", arrayOfPut); - srmClientStubs.SrmPrepareToPutResponse response = _srm - .srmPrepareToPut(req); - log.debug("NAIVE SRM CLIENT: received reply {}", response); - - // get overall request status - if (response == null) { - throw new SRMClientException( - "Unexpected reply from WebService: got a null response!"); - } - srmClientStubs.TReturnStatus overallRetStat = response.getReturnStatus(); - if (overallRetStat == null) { - throw new SRMClientException( - "Unexpected reply from WebService: null request level TReturnStatus!"); - } - // check overall request status - it.grid.storm.srm.types.TStatusCode overallStat = WSReturnStatusConverter - .getInstance().fromWS(overallRetStat).getStatusCode(); - if ((overallStat != it.grid.storm.srm.types.TStatusCode.SRM_REQUEST_QUEUED) - && (overallStat != it.grid.storm.srm.types.TStatusCode.SRM_REQUEST_INPROGRESS) - && (overallStat != it.grid.storm.srm.types.TStatusCode.SRM_SUCCESS) - && (overallStat != it.grid.storm.srm.types.TStatusCode.SRM_PARTIAL_SUCCESS)) { - // overall status is some kind of failure! - throw new SRMClientException( - "srmPrepareToPut on remote machine failed! Request level return status: " - + overallStat + ", explanation: " + overallRetStat.getExplanation()); - } - // get TRequestToken - String reqTokenString = response.getRequestToken(); - if (reqTokenString == null) { - throw new SRMClientException( - "Unexpected reply from WebService: null TReqeustToken!"); - } - it.grid.storm.srm.types.TRequestToken requestToken = new WSRequestTokenConverter() - .fromWS(reqTokenString); - // return answer - return new SRMPrepareToPutReply(requestToken); - } catch (SRMClientException e) { - throw e; // re-throw any SRMClientException! Otherwiase the general catch - // at the bottom captures it! - } catch (it.grid.storm.srm.types.InvalidTUserIDAttributeException e) { - // GridUser threw an exception! Cannot get credentials! - throw new SRMClientException( - "Unexpected error in NaiveSRMClient! Cannot get gredentials from GridUser! " - + e); - } catch (GlobusCredentialException e) { - // Globus credentials cannot be created! - throw new SRMClientException( - "Unexpected error in NaiveSRMClient! Cannot create GlobusCredentials from GridUser! " - + e); - } catch (GSSException e) { - // GSS credentials cannot be created! - throw new SRMClientException( - "Unexpected error in NaiveSRMClient! Cannot create GSSCredentials from GlobusCredential! " - + e); - } catch (org.apache.axis.types.URI.MalformedURIException ex) { - // This is a programming bug and should not occur! The URI is malformed! - throw new SRMClientException( - "Unexpected error in NaiveSRMClient! Cannot create URI! " + ex); - } catch (javax.xml.rpc.ServiceException ex) { - // Something went wrong with the web service! - throw new SRMClientException("Web Service problem! " + ex); - } catch (java.rmi.RemoteException ex) { - // something went wrong at low level communication with web service! - throw new SRMClientException("Web Service Communication problem! " + ex); - } catch (SOAPFaultException e) { - // The remote service launched an exception! This is a programmatic - // exception remotely thrown, _not_ an error! - throw new SRMClientException( - "The remote web service launched an exception! " + e); - } catch (WSConversionException e) { - // The data received from the web service could not be translated into - // StoRM object model equivalents! - throw new SRMClientException( - "There were problems translating between WebService and StoRM object model! " - + e); - } catch (InvalidPutReplyAttributeException e) { - // This is a programming bug and should not occur! For some reason, - // correctly translated WebService attributes - // did not allow the correct creation of an SRMPrepareToPutReply! - throw new SRMClientException( - "Unexpected error in NaiveSRMClient! Cannot create a reply to return! " - + e); - } catch (Exception e) { - // Unexpected runtime exception! For example, a time out when connectin to - // the web service! - throw new SRMClientException( - "Unexpected runtime error in NaiveSRMClient! " + e); - } // end synchronized! - } - - /** - * Method used to execute an srmStatusOfPutRequest: it requires the request - * token returned during an srmPrepareToPut operation, the GridUser that - * issued the command, and the toSURL of the request. An - * SRMStatusOfPutRequestReply is returned, but in case the operation fails an - * SRMClientException is thrown containing an explanation String. - * - * The client checks the overall status, and provided it is in either of - * SRM_REQUEST_QUEUED, SRM_REQUEST_INPROGESS, SRM_SUCCESS, SRM_PARTIAL_SUCCESS - * it will go and attempt retrieving the specific file status. If it is - * successful it will return the appropriate SRMStatusOfPutReply. - * - * Any other request level status results in an SRMClientException. If there - * are any errors in the communication, or the reply received from the other - * web service is incomprehensible or malformed, an SRMClientException is - * thrown with appropriate error messagges. - */ - public SRMStatusOfPutRequestReply statusOfPutRequest(TRequestToken rt, - GridUserInterface gu, TSURL toSURL) throws SRMClientException { - - try { - srmClientStubs.ISRM _srm = setUpGSI(gu, toSURL); - - // prepare srm request and execute it - srmClientStubs.SrmStatusOfPutRequestRequest req = new srmClientStubs.SrmStatusOfPutRequestRequest(); - // set TRequestToken - req.setRequestToken(rt.toString()); - // set SURL array - org.apache.axis.types.URI[] stubSurlArray = new org.apache.axis.types.URI[1]; - org.apache.axis.types.URI stubSurl = new org.apache.axis.types.URI( - toSURL.toString()); - stubSurlArray[0] = stubSurl; - srmClientStubs.ArrayOfAnyURI arrayOfTSURL = new srmClientStubs.ArrayOfAnyURI( - stubSurlArray); - req.setArrayOfTargetSURLs(arrayOfTSURL); - - // execute request - log.debug("NAIVE SRM CLIENT: invoking status of put with {}", req); - srmClientStubs.SrmStatusOfPutRequestResponse response = _srm - .srmStatusOfPutRequest(req); - log.debug("NAIVE SRM CLIENT: received response {}", response); - - // get overall request status - if (response == null) { - throw new SRMClientException( - "Unexpected reply from WebService: got a null response!"); - } - srmClientStubs.TReturnStatus overallRetStat = response.getReturnStatus(); - if (overallRetStat == null) { - throw new SRMClientException( - "Unexpected reply from WebService: null request level TReturnStatus!"); - } - // check overall request status - it.grid.storm.srm.types.TStatusCode overallStat = WSReturnStatusConverter - .getInstance().fromWS(overallRetStat).getStatusCode(); - if ((overallStat != it.grid.storm.srm.types.TStatusCode.SRM_REQUEST_QUEUED) - && (overallStat != it.grid.storm.srm.types.TStatusCode.SRM_REQUEST_INPROGRESS) - && (overallStat != it.grid.storm.srm.types.TStatusCode.SRM_SUCCESS) - && (overallStat != it.grid.storm.srm.types.TStatusCode.SRM_PARTIAL_SUCCESS)) { - // overall status is some kind of failure! - return new SRMStatusOfPutRequestReply(TTURL.makeEmpty(), - WSReturnStatusConverter.getInstance().fromWS(overallRetStat)); - } - // get file level request status - srmClientStubs.ArrayOfTPutRequestFileStatus arrayOfPutStatuses = response - .getArrayOfFileStatuses(); - if (arrayOfPutStatuses == null) { - throw new SRMClientException( - "Unexpected reply from WebService: null ArrayOfTPutRequestFileStatus!"); - } - srmClientStubs.TPutRequestFileStatus[] stubFileStatusArray = arrayOfPutStatuses - .getStatusArray(); - if ((stubFileStatusArray == null) || (stubFileStatusArray.length == 0)) { - throw new SRMClientException( - "Unexpected reply from WebService: null or empty StatusArray! "); - } - srmClientStubs.TPutRequestFileStatus stubFileStatus = stubFileStatusArray[0]; - if (stubFileStatus == null) { - throw new SRMClientException( - "Unexpected reply from WebService: null first entry of StatusArray! "); - } - // process file level status - org.apache.axis.types.URI stubTurl = stubFileStatus.getTransferURL(); - srmClientStubs.TReturnStatus stubStatus = stubFileStatus.getStatus(); - it.grid.storm.srm.types.TTURL turl = new WSTurlConverter() - .fromWS(stubTurl); - it.grid.storm.srm.types.TReturnStatus retStat = WSReturnStatusConverter - .getInstance().fromWS(stubStatus); - // return reply - return new SRMStatusOfPutRequestReply(turl, retStat); - } catch (SRMClientException e) { - // needed to re-throw SRMClientException that otherwise would get caught - // by generic catch at the bottom! - throw e; - } catch (it.grid.storm.srm.types.InvalidTUserIDAttributeException e) { - // GridUser threw an exception! Cannot get credentials! - throw new SRMClientException( - "Unexpected error in NaiveSRMClient! Cannot get gredentials from GridUser! " - + e); - } catch (GlobusCredentialException e) { - // Globus credentials cannot be created! - throw new SRMClientException( - "Unexpected error in NaiveSRMClient! Cannot create GlobusCredentials from GridUser! " - + e); - } catch (GSSException e) { - // GSS credentials cannot be created! - throw new SRMClientException( - "Unexpected error in NaiveSRMClient! Cannot create GSSCredentials from GlobusCredential! " - + e); - } catch (org.apache.axis.types.URI.MalformedURIException ex) { - // This is a programming bug and should not occur! The URI is malformed! - throw new SRMClientException( - "Unexpected error in NaiveSRMClient! Cannot create URI! " + ex); - } catch (javax.xml.rpc.ServiceException ex) { - // Something went wrong with the web service! - throw new SRMClientException("Web Service problem! " + ex); - } catch (java.rmi.RemoteException ex) { - // something went wrong at low level communication with web service! - throw new SRMClientException("Communication problem! " + ex); - } catch (SOAPFaultException e) { - // the remote service launched an exception! This is a programmatic - // exception remotely thrown, _not_ an error! - throw new SRMClientException( - "The remote web service launched an exception! " + e); - } catch (WSConversionException e) { - // the data received fro mthe web service could not be translated into - // StoRM object model equivalents! - throw new SRMClientException( - "The answer received from the WebService cannot be converted to StoRM object model! " - + e); - } catch (InvalidPutStatusAttributesException e) { - // This is a programming bug and should not occur! For some reason, - // correctly translated WebService attributes - // did not allow the correct creation of an SRMStatusOfPutRequestReply! - throw new SRMClientException( - "Unexpected error in NaiveSRMClient! Cannot create a reply to return! " - + e); - } catch (Exception e) { - // Catch any runtime exceptions, such as a time out! - throw new SRMClientException( - "Unexpected runtime error in NaiveSRMClient! " + e); - } - } - - /** - * Method used to execute an srmPutDone. The reply contains the status for the - * specified toSURL; yet if the overall status received differs from - * SRM_SUCCESS or SRM_PARTIAL_SUCCESS, the reply will contain _that_ overall - * status instead. The overall status is also returned in case the received - * array (containing file specific status) is null or has length equals to 0 - * (zero). - */ - public SRMPutDoneReply srmPutDone(TRequestToken rt, GridUserInterface gu, - TSURL toSURL) throws SRMClientException { - - try { - srmClientStubs.ISRM _srm = setUpGSI(gu, toSURL); - - // prepare srm request and execute it - srmClientStubs.SrmPutDoneRequest req = new srmClientStubs.SrmPutDoneRequest(); - // set TRequestToken - req.setRequestToken(rt.toString()); - // set array of SURLs - org.apache.axis.types.URI[] stubSurlArray = new org.apache.axis.types.URI[1]; - org.apache.axis.types.URI stubSurl = new org.apache.axis.types.URI( - toSURL.toString()); - stubSurlArray[0] = stubSurl; - srmClientStubs.ArrayOfAnyURI arrayOfTSURL = new srmClientStubs.ArrayOfAnyURI( - stubSurlArray); - req.setArrayOfSURLs(arrayOfTSURL); - - // execute request - log.debug("NAIVE SRM CLIENT: invoking srmPutDone with {}", req); - srmClientStubs.SrmPutDoneResponse response = _srm.srmPutDone(req); - log.debug("NAIVE SRM CLIENT: received response {}", response); - - // get overall request status - if (response == null) { - throw new SRMClientException( - "Unexpected reply from WebService: got a null response!"); - } - srmClientStubs.TReturnStatus overallRetStat = response.getReturnStatus(); - if (overallRetStat == null) { - throw new SRMClientException( - "Unexpected reply from WebService: null request level TReturnStatus!"); - } - // check overall request status - it.grid.storm.srm.types.TStatusCode overallStat = WSReturnStatusConverter - .getInstance().fromWS(overallRetStat).getStatusCode(); - if ((overallStat != it.grid.storm.srm.types.TStatusCode.SRM_SUCCESS) - && (overallStat != it.grid.storm.srm.types.TStatusCode.SRM_PARTIAL_SUCCESS)) { - // overall status is some kind of failure! - return new SRMPutDoneReply(WSReturnStatusConverter.getInstance() - .fromWS(overallRetStat)); - } - // get file level request status - srmClientStubs.ArrayOfTSURLReturnStatus arrayOfFileStatuses = response - .getArrayOfFileStatuses(); - // ArrayOfTSURLReturnStatus is optional according to the specifications! - // If indeed it is absent, assume that - // the web service saved bandwidth by not including a detailed description - // for each SURL, so the overall - // status does summarise the status also for the specific SURL! Return the - // overall status! - if (arrayOfFileStatuses == null) { - return new SRMPutDoneReply(WSReturnStatusConverter.getInstance() - .fromWS(overallRetStat)); /* - * throw new SRMClientException( - * "Unexpected reply from WebService: null ArrayOfTSURLReturnStatus!" - * ); - */ - } - srmClientStubs.TSURLReturnStatus[] stubFileStatusArray = arrayOfFileStatuses - .getStatusArray(); - if ((stubFileStatusArray == null) || (stubFileStatusArray.length == 0)) { - return new SRMPutDoneReply(WSReturnStatusConverter.getInstance() - .fromWS(overallRetStat)); /* - * throw new SRMClientException( - * "Unexpected reply from WebService: null or empty StatusArray! " - * ); - */ - } - srmClientStubs.TSURLReturnStatus stubFileStatus = stubFileStatusArray[0]; - if (stubFileStatus == null) { - throw new SRMClientException( - "Unexpected reply from WebService: null first entry of StatusArray! "); - } - // process file level satus - srmClientStubs.TReturnStatus stubStatus = stubFileStatus.getStatus(); - it.grid.storm.srm.types.TReturnStatus retStat = WSReturnStatusConverter - .getInstance().fromWS(stubStatus); - // return reply - return new SRMPutDoneReply(retStat); - } catch (SRMClientException e) { - // needed to re-throw SRMClientException that otherwise would get caught - // by generic catch at the bottom! - throw e; - } catch (it.grid.storm.srm.types.InvalidTUserIDAttributeException e) { - // GridUser threw an exception! Cannot get credentials! - throw new SRMClientException( - "Unexpected error in NaiveSRMClient! Cannot get gredentials from GridUser! " - + e); - } catch (GlobusCredentialException e) { - // Globus credentials cannot be created! - throw new SRMClientException( - "Unexpected error in NaiveSRMClient! Cannot create GlobusCredentials from GridUser! " - + e); - } catch (GSSException e) { - // GSS credentials cannot be created! - throw new SRMClientException( - "Unexpected error in NaiveSRMClient! Cannot create GSSCredentials from GlobusCredential! " - + e); - } catch (org.apache.axis.types.URI.MalformedURIException ex) { - // This is a programming bug and should not occur! The URI is malformed! - throw new SRMClientException( - "Unexpected error in NaiveSRMClient! Cannot create URI! " + ex); - } catch (javax.xml.rpc.ServiceException ex) { - // Something went wrong with the web service! - throw new SRMClientException("Web Service problem! " + ex); - } catch (java.rmi.RemoteException ex) { - // something went wrong at low level communication with web service! - throw new SRMClientException("Communication problem! " + ex); - } catch (SOAPFaultException e) { - // the remote service launched an exception! This is a programmatic - // exception remotely thrown, _not_ an error! - throw new SRMClientException( - "The remote web service launched an exception! " + e); - } catch (WSConversionException e) { - // the data received fro mthe web service could not be translated into - // StoRM object model equivalents! - throw new SRMClientException( - "The answer received from the WebService cannot be converted to StoRM object model! " - + e); - } catch (InvalidPutDoneReplyAttributeException e) { - // This is a programming bug and should not occur! For some reason, - // correctly translated WebService attributes - // did not allow the correct creation of an SRMPutDoneReply! - throw new SRMClientException( - "Unexpected error in NaiveSRMClient! Cannot create a reply to return! " - + e); - } catch (Exception e) { - // Catch any runtime exceptions, such as a time out! - throw new SRMClientException( - "Unexpected runtime error in NaiveSRMClient! " + e); - } - } - - /** - * Private auxiliary method that sets up a secure GSI connection for the given - * GridUser to the specfied toSURL. The method returns the service interface. - */ - private ISRM setUpGSI(GridUserInterface gu, TSURL toSURL) - throws ServiceException, GlobusCredentialException, GSSException, - InvalidTUserIDAttributeException { - - // get web service, setting HTTP and HTTPG as transport! - Util.registerTransport(); - SimpleProvider provider = new SimpleProvider(); - SimpleTargetedChain c = null; - c = new SimpleTargetedChain(new GSIHTTPSender()); - provider.deployTransport("httpg", c); - c = new SimpleTargetedChain(new HTTPSender()); - provider.deployTransport("http", c); - srmClientStubs.SRMService sRMService = new srmClientStubs.SRMServiceLocator( - provider); - srmClientStubs.ISRM _srm = sRMService.getsrm(); - - // set proxy in stub - if (((AbstractGridUser) gu).getUserCredentials() == null) { - log.error("ERROR in NaiveSRMClient! No proxy present for {}", gu.getDn()); - } - InputStream proxy = new ByteArrayInputStream(((AbstractGridUser) gu) - .getUserCredentials().getBytes()); // String containing the proxy seen as - // an input stream! - GSSCredential globusProxy = new GlobusGSSCredentialImpl( - new GlobusCredential(proxy), GSSCredential.INITIATE_AND_ACCEPT); // GSSCredential - // containing - // the - // proxy! - ((Stub) _srm)._setProperty(GSIHTTPTransport.GSI_CREDENTIALS, globusProxy); // set - // the - // proxy - // to - // be - // used - // during - // GSI - // connection! - ((Stub) _srm)._setProperty(GSIHTTPTransport.GSI_AUTHORIZATION, - HostAuthorization.getInstance()); // set the authorization that will be - // performed by the web service for the - // supplied credentails! - ((Stub) _srm)._setProperty(GSIHTTPTransport.GSI_MODE, - GSIHTTPTransport.GSI_MODE_FULL_DELEG); // set the supply of both private - // and public key of credentials - - // set service endpoint address - EndPoint ep = toSURL.sfn().endPoint(); - String epString = ""; - if (ep.isEmpty()) { - epString = "/"; - } else { - epString = ep.toString(); - } - Port port = toSURL.sfn().port(); - String portString = ""; - if (!port.isEmpty()) { - portString = ":" + port.toString(); - } - String sea = "httpg://" + toSURL.sfn().machine() + portString + epString; - ((Stub) _srm)._setProperty(Stub.ENDPOINT_ADDRESS_PROPERTY, sea); - - // return the interface - return _srm; - } -} diff --git a/src/main/java/it/grid/storm/asynch/SRMClient.java b/src/main/java/it/grid/storm/asynch/SRMClient.java deleted file mode 100644 index 96e3b41f..00000000 --- a/src/main/java/it/grid/storm/asynch/SRMClient.java +++ /dev/null @@ -1,73 +0,0 @@ -/* - * - * Copyright (c) Istituto Nazionale di Fisica Nucleare (INFN). 2006-2010. - * - * Licensed under the Apache License, Version 2.0 (the "License"); you may not - * use this file except in compliance with the License. You may obtain a copy of - * the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations under - * the License. - */ - -package it.grid.storm.asynch; - -// import it.grid.storm.griduser.VomsGridUser; -import it.grid.storm.srm.types.TLifeTimeInSeconds; -import it.grid.storm.srm.types.TFileStorageType; -import it.grid.storm.srm.types.TSpaceToken; -import it.grid.storm.srm.types.TSizeInBytes; -import it.grid.storm.srm.types.TOverwriteMode; -import it.grid.storm.srm.types.TSURL; -import it.grid.storm.srm.types.TRequestToken; -import it.grid.storm.common.types.TransferProtocol; -import it.grid.storm.griduser.GridUserInterface; - -/** - * Interface for the SRM Client functionality needed in StoRM. - * - * @author EGRID - ICTP Trieste - * @version 2.0 - * @date September, 2005 - */ -public interface SRMClient { - - /** - * Method used to execute an srmPrepareToPut: it will connect to the - * webservice derived from the toSURL using the credentials available in - * GridUser. It requires the lifetime, the fileStorageType, the spaceToken, - * the fileSize, the protocol, a description, the overwriteOption, the - * retryTime. The method returns an SRMPrepareToPutReply containing the result - * of the operation, and throws an SRMClient exception in case the operation - * could not be completed. - */ - public SRMPrepareToPutReply prepareToPut(GridUserInterface su, TSURL toSURL, - TLifeTimeInSeconds lifetime, TFileStorageType fileStorageType, - TSpaceToken spaceToken, TSizeInBytes filesize, TransferProtocol protocol, - String description, TOverwriteMode overwriteOption, - TLifeTimeInSeconds retryTime) throws SRMClientException; - - /** - * Method used to execute an srmStatusOfPutRequest: it requires the request - * token returned durign an srmPrepareToPut operation, the GridUser that - * issued the command, and the toSURL of the request. An - * SRMStatusOfPutRequestReply is returned, but in case the operation fails an - * SRMClientException is thrown containing an explanation String. - */ - public SRMStatusOfPutRequestReply statusOfPutRequest(TRequestToken rt, - GridUserInterface gu, TSURL toSURL) throws SRMClientException; - - /** - * Method used to execute an srmPutDone: it requires the request token, the - * GridUser that issued the command, and the toSURL that must be putDone. - * SRMPutDoneReply is returned but in case the operation fails an - * SRMClientException is thrown containing an explanation String. - */ - public SRMPutDoneReply srmPutDone(TRequestToken rt, GridUserInterface gu, - TSURL toSURL) throws SRMClientException; -} diff --git a/src/main/java/it/grid/storm/asynch/SRMClientException.java b/src/main/java/it/grid/storm/asynch/SRMClientException.java deleted file mode 100644 index 312f62b6..00000000 --- a/src/main/java/it/grid/storm/asynch/SRMClientException.java +++ /dev/null @@ -1,51 +0,0 @@ -/* - * - * Copyright (c) Istituto Nazionale di Fisica Nucleare (INFN). 2006-2010. - * - * Licensed under the Apache License, Version 2.0 (the "License"); you may not - * use this file except in compliance with the License. You may obtain a copy of - * the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations under - * the License. - */ - -package it.grid.storm.asynch; - -/** - * Class that represents an exception thrown when the internal client could not - * carry out the invoked SRM operation. - * - * @author EGRID - ICTP Trieste - * @version 1.0 - * @date September, 2005 - */ -public class SRMClientException extends Exception { - - private String explanation = ""; // String that explains what went wrong with - // srm client operation - - public SRMClientException() { - - } - - /** - * Public constructor that requires the String explaining the reason for the - * srm failure. - */ - public SRMClientException(String explanation) { - - if (explanation != null) - this.explanation = explanation; - } - - public String toString() { - - return explanation; - } -} diff --git a/src/main/java/it/grid/storm/asynch/SRMClientFactory.java b/src/main/java/it/grid/storm/asynch/SRMClientFactory.java deleted file mode 100644 index 9817927e..00000000 --- a/src/main/java/it/grid/storm/asynch/SRMClientFactory.java +++ /dev/null @@ -1,66 +0,0 @@ -/* - * - * Copyright (c) Istituto Nazionale di Fisica Nucleare (INFN). 2006-2010. - * - * Licensed under the Apache License, Version 2.0 (the "License"); you may not - * use this file except in compliance with the License. You may obtain a copy of - * the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations under - * the License. - */ - -package it.grid.storm.asynch; - -import it.grid.storm.config.Configuration; - -/** - * Class that represents a factory for SRMClients. It allows for the creation of - * clients from classes specified in the configuration file. - * - * @author EGRID - ICTP Trieste - * @version 1.0 - * @date October 2005 - */ -public class SRMClientFactory { - - final private static SRMClientFactory factory = new SRMClientFactory(); // only - // instance - // of - // GridFTPTraqnsferClientFactory! - - private SRMClientFactory() { - - } - - /** - * Method that returns the only instance of the factory. - */ - public static SRMClientFactory getInstance() { - - return factory; - } - - /** - * Method that returns a new instance of an SRMClient. If the configured class - * cannot be supplied, a NoSRMClientFoundException is thrown. - */ - synchronized public SRMClient client() throws NoSRMClientFoundException { - - try { - String client = Configuration.getInstance().getSRMClient(); - return (SRMClient) Class.forName(client).newInstance(); - } catch (ClassNotFoundException e) { - throw new NoSRMClientFoundException(e.toString()); - } catch (InstantiationException e) { - throw new NoSRMClientFoundException(e.toString()); - } catch (IllegalAccessException e) { - throw new NoSRMClientFoundException(e.toString()); - } - } -} diff --git a/src/main/java/it/grid/storm/asynch/SRMClientStub.java b/src/main/java/it/grid/storm/asynch/SRMClientStub.java deleted file mode 100644 index fa8dd5d1..00000000 --- a/src/main/java/it/grid/storm/asynch/SRMClientStub.java +++ /dev/null @@ -1,99 +0,0 @@ -/* - * - * Copyright (c) Istituto Nazionale di Fisica Nucleare (INFN). 2006-2010. - * - * Licensed under the Apache License, Version 2.0 (the "License"); you may not - * use this file except in compliance with the License. You may obtain a copy of - * the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations under - * the License. - */ - -package it.grid.storm.asynch; - -import java.util.Calendar; -import it.grid.storm.srm.types.TLifeTimeInSeconds; -import it.grid.storm.srm.types.TFileStorageType; -import it.grid.storm.srm.types.TSpaceToken; -import it.grid.storm.srm.types.TSizeInBytes; -import it.grid.storm.srm.types.TOverwriteMode; -import it.grid.storm.srm.types.TSURL; -import it.grid.storm.srm.types.TTURL; -import it.grid.storm.srm.types.TReturnStatus; -import it.grid.storm.srm.types.TStatusCode; -import it.grid.storm.srm.types.TRequestToken; -import it.grid.storm.common.types.TransferProtocol; - -import it.grid.storm.common.types.*; -import it.grid.storm.griduser.GridUserInterface; - -/** - * Class that represents a stub of an SRMClient, which does not contact an - * external web service. - * - * @author EGRID - ICTP Trieste - * @version 1.0 - * @date September, 2005 - */ -public class SRMClientStub implements SRMClient { - - /** - * Method that returns an SRMPrepareToPutReply containging a dummy request - * token. - */ - public SRMPrepareToPutReply prepareToPut(GridUserInterface su, TSURL toSURL, - TLifeTimeInSeconds lifetime, TFileStorageType fileStorageType, - TSpaceToken spaceToken, TSizeInBytes filesize, TransferProtocol protocol, - String description, TOverwriteMode overwriteOption, - TLifeTimeInSeconds retryTime) throws SRMClientException { - - try { - return new SRMPrepareToPutReply(new TRequestToken("DUMMY REQUEST TOKEN!", - Calendar.getInstance().getTime())); - } catch (Exception e) { - throw new SRMClientException(); - } - } - - /** - * Method that returns an SRMStatusOfPutRequestReply, whose toTURL method - * returns gsiftp://dummy.dummy-cnaf.dummy-infn.it:2811/mnt/gpfs/cnaf/tmp/ - * srmCopyDummy.txt, and whose returnStatus returns SRM_SUCCESS. - */ - public SRMStatusOfPutRequestReply statusOfPutRequest(TRequestToken rt, - GridUserInterface gu, TSURL toSURL) throws SRMClientException { - - try { - TTURL aux = TTURL.make( - TransferProtocol.GSIFTP, - TFN.make(Machine.make("dummy.dummy-cnaf.dummy-infn.it"), - Port.make(2811), PFN.make("/mnt/gpfs/cnaf/tmp/srmCopyDummy.txt"))); - TReturnStatus auxst = new TReturnStatus(TStatusCode.SRM_SUCCESS, - "Success!"); - return new SRMStatusOfPutRequestReply(aux, auxst); - } catch (Exception e) { - throw new SRMClientException(); - } - } - - /** - * Method that returns an SRMPutDoneReply containing TReturnStatus with - * TStatusCode.SRM_SUCCESS, and explanation string "DUMMY SUCCESS". - */ - public SRMPutDoneReply srmPutDone(TRequestToken rt, GridUserInterface gu, - TSURL toSURL) throws SRMClientException { - - try { - return new SRMPutDoneReply(new TReturnStatus(TStatusCode.SRM_SUCCESS, - "DUMMY SUCCESS")); - } catch (Exception e) { - throw new SRMClientException(); - } - } -} diff --git a/src/main/java/it/grid/storm/asynch/ThirdPartGridFTPTransferClient.java b/src/main/java/it/grid/storm/asynch/ThirdPartGridFTPTransferClient.java deleted file mode 100644 index 04c57979..00000000 --- a/src/main/java/it/grid/storm/asynch/ThirdPartGridFTPTransferClient.java +++ /dev/null @@ -1,267 +0,0 @@ -/* - * - * Copyright (c) Istituto Nazionale di Fisica Nucleare (INFN). 2006-2010. - * - * Licensed under the Apache License, Version 2.0 (the "License"); you may not - * use this file except in compliance with the License. You may obtain a copy of - * the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations under - * the License. - */ - -package it.grid.storm.asynch; - -import it.grid.storm.common.types.TransferProtocol; -import it.grid.storm.griduser.AbstractGridUser; -import it.grid.storm.griduser.GridUserInterface; -import it.grid.storm.srm.types.TTURL; - -import java.io.ByteArrayInputStream; -import java.io.IOException; -import java.io.InputStream; - -import org.globus.ftp.ByteRangeList; -import org.globus.ftp.GridFTPClient; -import org.globus.ftp.GridFTPRestartMarker; -import org.globus.ftp.GridFTPSession; -import org.globus.ftp.Marker; -import org.globus.ftp.MarkerListener; -import org.globus.ftp.PerfMarker; -import org.globus.ftp.RetrieveOptions; -import org.globus.ftp.exception.ClientException; -import org.globus.ftp.exception.PerfMarkerException; -import org.globus.ftp.exception.ServerException; -import org.globus.gsi.GlobusCredential; -import org.globus.gsi.GlobusCredentialException; -import org.globus.gsi.gssapi.GlobusGSSCredentialImpl; -import org.ietf.jgss.GSSCredential; -import org.ietf.jgss.GSSException; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -/** - *

- * Title: ThirdPartGridFTPTransferClient - *

- * - *

- * Description: to be defined - *

- * - *

- * Copyright: Copyright (c) 2006 - *

- * - *

- * Company: INFN - CNAF - *

- * - * @author Riccardo Zappi - * @version 1.0 - * @date 18 March, 2006 - */ - -public class ThirdPartGridFTPTransferClient implements GridFTPTransferClient { - - private static Logger log = LoggerFactory - .getLogger(ThirdPartGridFTPTransferClient.class); - - /** - * - * @param gu - * VomsGridUser - * @param source - * TTURL - * @param destination - * TTURL - * @throws GridFTPTransferClientException - */ - public void putFile(GridUserInterface gu, TTURL source, TTURL destination) - throws GridFTPTransferClientException { - - log.debug(" --- Third part copy --- "); - - boolean firstPart = (source.protocol() == TransferProtocol.GSIFTP); - boolean secondPart = (destination.protocol() == TransferProtocol.GSIFTP); - if (!firstPart || !secondPart) { - throw new GridFTPTransferClientException( - "The third part gridFTP trasfer requires both TURL in GSIFTP protocol! (first =" - + firstPart + ") second =" + secondPart + ")"); - } - - String fullSourceFile = "/" + source.tfn().pfn().getValue(); - String fullDestinationFile = "/" + destination.tfn().pfn().getValue(); - - log.debug("source file: {}", fullSourceFile); - log.debug("destin file: {}", fullDestinationFile); - - // Smart implementation of Marker Listener - MarkerListenerImpl listener = new MarkerListenerImpl(); - - try { - InputStream proxy = new ByteArrayInputStream(((AbstractGridUser) gu) - .getUserCredentials().getBytes()); - GSSCredential cred = new GlobusGSSCredentialImpl(new GlobusCredential( - proxy), GSSCredential.INITIATE_AND_ACCEPT); - - log.debug("Created GSS Credential from proxy"); - - // Set up of remote Source GridFTP - String remoteSourceHost = source.tfn().machine().getValue(); - int remoteSourcePort = source.tfn().port().toInt(); - log.debug("remote source GridFTP {}:{}", remoteSourceHost, remoteSourcePort); - GridFTPClient sourceClient = new GridFTPClient(remoteSourceHost, - remoteSourcePort); - setParams(sourceClient, cred); - - // Set up of remote Destination GridFTP - String remoteDestinationHost = destination.tfn().machine().getValue(); - int remoteDestinationPort = destination.tfn().port().toInt(); - log.debug("remote destination GridFTP: {}:{}", remoteDestinationHost, - remoteDestinationPort); - GridFTPClient destClient = new GridFTPClient(remoteDestinationHost, - remoteDestinationPort); - setParams(destClient, cred); - - // Retrieve Parallelism of transfer from Configuration file - // org.globus.ftp.test.gridftp.parallelism=6 - int parallelism = 6; - sourceClient.setOptions(new RetrieveOptions(parallelism)); - log.debug(" Transfer parallelism: {}", parallelism); - - // Execute the transfer - log.debug(" Starting transfer ... "); - sourceClient.extendedTransfer(fullSourceFile, destClient, - fullDestinationFile, listener); - log.debug(" ... transfer ended."); - - // Close the session of transfer - sourceClient.close(); - destClient.close(); - } catch (IOException e) { - log.warn("IO Except", e); - throw new GridFTPTransferClientException(e.toString()); - } catch (ServerException e) { - log.warn("Server Except", e); - throw new GridFTPTransferClientException(e.toString()); - } catch (ClientException e) { - log.warn("Client Except", e); - throw new GridFTPTransferClientException(e.toString()); - } catch (GlobusCredentialException e) { - log.warn("Credential Except", e); - throw new GridFTPTransferClientException(e.toString()); - } catch (GSSException e) { - log.warn("GSS Except", e); - throw new GridFTPTransferClientException(e.toString()); - } catch (Exception e) { - log.warn("Generic Except", e); - // Catch any runtime exception! - throw new GridFTPTransferClientException( - "Unexpected runtime error in ThirdPartGridFTPTransferClient! " + e); - } - } - - void setParams(GridFTPClient client, GSSCredential cred) throws Exception { - - client.authenticate(cred); - client.setProtectionBufferSize(16384); - client.setType(GridFTPSession.TYPE_IMAGE); - client.setMode(GridFTPSession.MODE_EBLOCK); - } - - /** - * - *

- * Title: - *

- * - *

- * Description: - *

- * - *

- * Copyright: Copyright (c) 2005 - *

- * - *

- * Company: - *

- * - * @author not attributable - * @version 1.0 - */ - class MarkerListenerImpl implements MarkerListener { - - public ByteRangeList list; - - public MarkerListenerImpl() { - - list = new ByteRangeList(); - } - - public void markerArrived(Marker m) { - - if (m instanceof GridFTPRestartMarker) { - restartMarkerArrived((GridFTPRestartMarker) m); - } else if (m instanceof PerfMarker) { - perfMarkerArrived((PerfMarker) m); - } else { - log.warn("Received unsupported marker type"); - } - }; - - private void restartMarkerArrived(GridFTPRestartMarker marker) { - - log.info("--> restart marker arrived:"); - list.merge(marker.toVector()); - log.info("Current transfer state: {}", list.toFtpCmdArgument()); - } - - private void perfMarkerArrived(PerfMarker marker) { - - log.info("--> perf marker arrived"); - // time stamp - log.info("Timestamp = {}", marker.getTimeStamp()); - - // stripe index - if (marker.hasStripeIndex()) { - try { - log.info("Stripe index = {}", marker.getStripeIndex()); - } catch (PerfMarkerException e) { - log.warn(e.toString()); - } - } else { - log.info("Stripe index: not present"); - } - - // stripe bytes transferred - if (marker.hasStripeBytesTransferred()) { - try { - log.info("Stripe bytes transferred = {}", marker.getStripeBytesTransferred()); - } catch (PerfMarkerException e) { - log.warn(e.toString()); - } - } else { - log.info("Stripe Bytes Transferred: not present"); - } - - // total stripe count - if (marker.hasTotalStripeCount()) { - try { - log.info("Total stripe count = {}", marker.getTotalStripeCount()); - } catch (PerfMarkerException e) { - log.warn(e.toString()); - } - } else { - log.info("Total stripe count: not present"); - } - } // PerfMarkerArrived - } // class MarkerListenerImpl - -} diff --git a/src/main/java/it/grid/storm/asynch/UnsupportedOperationFeeder.java b/src/main/java/it/grid/storm/asynch/UnsupportedOperationFeeder.java new file mode 100644 index 00000000..9dea8966 --- /dev/null +++ b/src/main/java/it/grid/storm/asynch/UnsupportedOperationFeeder.java @@ -0,0 +1,20 @@ +package it.grid.storm.asynch; + +import it.grid.storm.scheduler.Delegable; + +public class UnsupportedOperationFeeder implements Delegable { + + @Override + public void doIt() { + + throw new UnsupportedOperationException(); + + } + + @Override + public String getName() { + + return "Unsupported Operation Feeder"; + } + +} diff --git a/src/main/java/it/grid/storm/asynch/VisitableCopy.java b/src/main/java/it/grid/storm/asynch/VisitableCopy.java deleted file mode 100644 index 7e399990..00000000 --- a/src/main/java/it/grid/storm/asynch/VisitableCopy.java +++ /dev/null @@ -1,46 +0,0 @@ -/* - * - * Copyright (c) Istituto Nazionale di Fisica Nucleare (INFN). 2006-2010. - * - * Licensed under the Apache License, Version 2.0 (the "License"); you may not - * use this file except in compliance with the License. You may obtain a copy of - * the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations under - * the License. - */ - -package it.grid.storm.asynch; - -import java.util.List; -import org.slf4j.Logger; -import it.grid.storm.asynch.Copy.Result; -import it.grid.storm.catalogs.CopyData; -import it.grid.storm.griduser.GridUserInterface; -import it.grid.storm.srm.types.TRequestToken; - -/** - * @author Michele Dibenedetto - * - */ -public interface VisitableCopy { - - public TRequestToken getLocalrt(); - - public GridUserInterface getGu(); - - public CopyData getRequestData(); - - public Logger getLog(); - - public Result buildOperationResult(String string, Copy.ResultType type) - throws IllegalArgumentException; - - public Result buildOperationResult(List argument, Copy.ResultType type) - throws IllegalArgumentException; -} diff --git a/src/main/java/it/grid/storm/asynch/WSConversionException.java b/src/main/java/it/grid/storm/asynch/WSConversionException.java deleted file mode 100644 index 799b0086..00000000 --- a/src/main/java/it/grid/storm/asynch/WSConversionException.java +++ /dev/null @@ -1,46 +0,0 @@ -/* - * - * Copyright (c) Istituto Nazionale di Fisica Nucleare (INFN). 2006-2010. - * - * Licensed under the Apache License, Version 2.0 (the "License"); you may not - * use this file except in compliance with the License. You may obtain a copy of - * the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations under - * the License. - */ - -package it.grid.storm.asynch; - -/** - * Class that represens an exception thrown when the conversion between WS types - * and StoRM Object Model types, fails for some reason. - * - * @author EGRID - ICTP Trieste - * @version 1.0 - * @date October, 2005 - */ -public class WSConversionException extends Exception { - - private String explanation = ""; // String containing the reason for the - // exception - - /** - * Constructor that requires a String describing the reason for the exception. - */ - public WSConversionException(String explanation) { - - if (explanation != null) - this.explanation = explanation; - } - - public String toString() { - - return explanation; - } -} diff --git a/src/main/java/it/grid/storm/asynch/WSFileStorageTypeConverter.java b/src/main/java/it/grid/storm/asynch/WSFileStorageTypeConverter.java deleted file mode 100644 index 03041e9c..00000000 --- a/src/main/java/it/grid/storm/asynch/WSFileStorageTypeConverter.java +++ /dev/null @@ -1,97 +0,0 @@ -/* - * - * Copyright (c) Istituto Nazionale di Fisica Nucleare (INFN). 2006-2010. - * - * Licensed under the Apache License, Version 2.0 (the "License"); you may not - * use this file except in compliance with the License. You may obtain a copy of - * the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations under - * the License. - */ - -package it.grid.storm.asynch; - -import it.grid.storm.srm.types.*; - -import srmClientStubs.TFileStorageType; - -/** - * Class used to convert between TFileStorageType from the WebService and StoRM - * object model counterpart. - * - * @author EGRID - ICTP Trieste - * @version 2.0 - * @date October 2005 - */ -public class WSFileStorageTypeConverter { - - /** - * Method that accepts an srmClientStubs.TFileStorageType and returns an - * it.grid.storm.srm.types.TFileStorageType; if the conversion fails, a - * WSConversionException is thrown with a String reporting the problem - * encountered. - * - * If the supplied srmClientStubs.TFileStorageType is null, a - * WSConversionException is thrown. - * - * Beware that it was noticed that sometimes a null stub represents an empty - * field for the remote WS. Instead of getting an empty String, null may be - * used instead! This is why null stubs are interpreted as a field that the - * remote WS decided not to fill in. - * - * In particular, since the FileStorageType cannot be optional, a missing - * field is just not accepted by StoRM: it is treated as a misbehaving WS! For - * null, then, an Exception is thrown! - */ - public it.grid.storm.srm.types.TFileStorageType fromWS( - srmClientStubs.TFileStorageType stub) throws WSConversionException { - - if (stub == null) - throw new WSConversionException( - "Supplied srmClientStubs.TFileStorageType was null!"); - if (stub == srmClientStubs.TFileStorageType.VOLATILE) - return it.grid.storm.srm.types.TFileStorageType.VOLATILE; - else if (stub == srmClientStubs.TFileStorageType.PERMANENT) - return it.grid.storm.srm.types.TFileStorageType.PERMANENT; - else if (stub == srmClientStubs.TFileStorageType.DURABLE) - return it.grid.storm.srm.types.TFileStorageType.DURABLE; - else - throw new WSConversionException( - "Unable to convert srmClientStubs.TFileStorageType " + stub.toString()); - } - - /** - * Method that accepts an it.grid.storm.srm.types.TFileStorageType and returns - * an srmClientStubs.TFileStorageType; if the conversion fails, a - * WSConversionException is thrown with a String reporting the problem - * encountered. - * - * If the supplied it.grid.storm.srm.types.TFileStorageType is null, a - * WSConversionException is thrown: StoRM makes no use of null in its object - * model, so it must be interpreted as a programming bug! - */ - public srmClientStubs.TFileStorageType fromStoRM( - it.grid.storm.srm.types.TFileStorageType storm) - throws WSConversionException { - - if (storm == null) - throw new WSConversionException( - "Supplied it.grid.storm.srm.types.TFileStorageType was null!"); - if (storm == it.grid.storm.srm.types.TFileStorageType.VOLATILE) - return srmClientStubs.TFileStorageType.VOLATILE; - else if (storm == it.grid.storm.srm.types.TFileStorageType.PERMANENT) - return srmClientStubs.TFileStorageType.PERMANENT; - else if (storm == it.grid.storm.srm.types.TFileStorageType.DURABLE) - return srmClientStubs.TFileStorageType.DURABLE; - else - throw new WSConversionException( - "Unable to convert it.grid.storm.srm.types.TFileStorageType " - + storm.toString()); - } -} diff --git a/src/main/java/it/grid/storm/asynch/WSOverwriteModeConverter.java b/src/main/java/it/grid/storm/asynch/WSOverwriteModeConverter.java deleted file mode 100644 index dba367a3..00000000 --- a/src/main/java/it/grid/storm/asynch/WSOverwriteModeConverter.java +++ /dev/null @@ -1,96 +0,0 @@ -/* - * - * Copyright (c) Istituto Nazionale di Fisica Nucleare (INFN). 2006-2010. - * - * Licensed under the Apache License, Version 2.0 (the "License"); you may not - * use this file except in compliance with the License. You may obtain a copy of - * the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations under - * the License. - */ - -package it.grid.storm.asynch; - -import it.grid.storm.srm.types.*; - -import srmClientStubs.TOverwriteMode; - -/** - * Class used to convert between TOverwriteMode from the WebService and StoRM - * object model counterpart. - * - * @author EGRID - ICTP Trieste - * @version 2.0 - * @date October 2005 - */ -public class WSOverwriteModeConverter { - - /** - * Method that accepts an srmClientStubs.TOverwriteMode and returns an - * it.grid.storm.srm.types.TTURL; if the conversion fails, a - * WSConversionException is thrown with a String reporting the problem - * encountered. - * - * If the supplied srmClientStubs.TOverwriteMode is null, a - * WSConversionException is thrown. - * - * Beware that it was noticed that sometimes a null stub represents an empty - * field for the remote WS. Instead of getting an empty String, null may be - * used instead! This is why null stubs are interpreted as a field that the - * remote WS decided not to fill in. - * - * In particular, since the TOverwriteMode cannot be optional, a missing field - * is just not accepted by StoRM: it is treated as a misbehaving WS! For null, - * then, an Exception is thrown! - */ - public it.grid.storm.srm.types.TOverwriteMode fromWS( - srmClientStubs.TOverwriteMode stub) throws WSConversionException { - - if (stub == null) - throw new WSConversionException( - "Supplied srmClientStubs.TOverwriteMode was null!"); - if (stub == srmClientStubs.TOverwriteMode.ALWAYS) - return it.grid.storm.srm.types.TOverwriteMode.ALWAYS; - else if (stub == srmClientStubs.TOverwriteMode.NEVER) - return it.grid.storm.srm.types.TOverwriteMode.NEVER; - else if (stub == srmClientStubs.TOverwriteMode.WHEN_FILES_ARE_DIFFERENT) - return it.grid.storm.srm.types.TOverwriteMode.WHENFILESAREDIFFERENT; - else - throw new WSConversionException( - "Unable to convert srmClientStubs.TOverwriteMode " + stub.toString()); - } - - /** - * Method that accepts an it.grid.storm.srm.types.TOverwriteMode and returns - * an srmClientStubs.TOverwriteMode; if the conversion fails, a - * WSConversionException is thrown with a String reporting the problem - * encountered. - * - * If the supplied it.grid.storm.srm.types.TOverwriteMode is null, a - * WSConversionException is thrown: StoRM makes no use of null in its object - * model, so it must be interpreted as a programming bug! - */ - public srmClientStubs.TOverwriteMode fromStoRM( - it.grid.storm.srm.types.TOverwriteMode storm) throws WSConversionException { - - if (storm == null) - throw new WSConversionException( - "Supplied it.grid.storm.srm.types.TOverwriteMode was null!"); - if (storm == it.grid.storm.srm.types.TOverwriteMode.ALWAYS) - return srmClientStubs.TOverwriteMode.ALWAYS; - else if (storm == it.grid.storm.srm.types.TOverwriteMode.NEVER) - return srmClientStubs.TOverwriteMode.NEVER; - else if (storm == it.grid.storm.srm.types.TOverwriteMode.WHENFILESAREDIFFERENT) - return srmClientStubs.TOverwriteMode.WHEN_FILES_ARE_DIFFERENT; - else - throw new WSConversionException( - "Unable to convert it.grid.storm.srm.types.TOverwriteMode " - + storm.toString()); - } -} diff --git a/src/main/java/it/grid/storm/asynch/WSRequestTokenConverter.java b/src/main/java/it/grid/storm/asynch/WSRequestTokenConverter.java deleted file mode 100644 index 6f73f122..00000000 --- a/src/main/java/it/grid/storm/asynch/WSRequestTokenConverter.java +++ /dev/null @@ -1,75 +0,0 @@ -/* - * - * Copyright (c) Istituto Nazionale di Fisica Nucleare (INFN). 2006-2010. - * - * Licensed under the Apache License, Version 2.0 (the "License"); you may not - * use this file except in compliance with the License. You may obtain a copy of - * the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations under - * the License. - */ - -package it.grid.storm.asynch; - -import java.util.Calendar; -import it.grid.storm.srm.types.InvalidTRequestTokenAttributesException; - -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -/** - * Class used to convert between TRequestToken from the WebService and StoRM - * object model counterpart. - * - * @author EGRID - ICTP Trieste - * @version 2.0 - * @date October 2005 - */ -public class WSRequestTokenConverter { - - private static Logger log = LoggerFactory - .getLogger(WSRequestTokenConverter.class); - - /** - * Method that accepts an srmClientStubs.TRequestToken and returns an - * it.grid.storm.srm.types.TRequestToken; if the conversion fails, a - * WSConversionException is thrown with a String reporting the problem - * encountered. - * - * Beware that in case the String representation of - * srmClientStubs.TRequestToken is null then a TRequestToken with the "" - * String is returned. Likewise if the _stub_ itself is null! - * - * Beware that it was noticed that sometimes a null stub represents an empty - * field for the remote ws. Instead of getting an empty String, null may be - * used instead! This is why null stubs are interpreted as a field that the - * remote WS decided not to fill in. - * - * In case for any reason th econversion cannot proceed, a - * WSConverterException is thrown. - */ - public it.grid.storm.srm.types.TRequestToken fromWS(String stub) - throws WSConversionException { - - try { - String auxString = null; - if (stub == null) { - auxString = ""; - } else { - auxString = stub; - } - return new it.grid.storm.srm.types.TRequestToken(auxString, Calendar - .getInstance().getTime()); - } catch (InvalidTRequestTokenAttributesException e) { - log.debug("Unexpected error in WSRequestTokenConverter! This is a " - + "programming bug! Could not translate TRequestToken from WS! {}", e); - throw new WSConversionException(e.toString()); - } - } -} diff --git a/src/main/java/it/grid/storm/asynch/WSReturnStatusConverter.java b/src/main/java/it/grid/storm/asynch/WSReturnStatusConverter.java deleted file mode 100644 index a133e7ae..00000000 --- a/src/main/java/it/grid/storm/asynch/WSReturnStatusConverter.java +++ /dev/null @@ -1,180 +0,0 @@ -/* - * - * Copyright (c) Istituto Nazionale di Fisica Nucleare (INFN). 2006-2010. - * - * Licensed under the Apache License, Version 2.0 (the "License"); you may not - * use this file except in compliance with the License. You may obtain a copy of - * the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations under - * the License. - */ - -package it.grid.storm.asynch; - -import java.util.Map; -import java.util.HashMap; -import java.util.Iterator; - -import it.grid.storm.srm.types.InvalidTTURLAttributesException; -import it.grid.storm.srm.types.*; - -import srmClientStubs.TReturnStatus; -import srmClientStubs.TStatusCode; - -/** - * Class used to convert between TReturnStatus from the WebService and StoRM - * object model counterpart. - * - * @author EGRID - ICTP Trieste - * @version 2.0 - * @date October 2005 - */ -public class WSReturnStatusConverter { - - private static final WSReturnStatusConverter converter = new WSReturnStatusConverter(); // only - // instance - // of - // converter - private final Map wsTOstorm = new HashMap(); // map that contains the - // correspondence between WS - // TStatusCode type and StoRM - // object model TStatusCode type - private final Map stormTOws = new HashMap(); // map that contains the previous - // correspondence, but reversed! - - private WSReturnStatusConverter() { - - wsTOstorm.put(srmClientStubs.TStatusCode.SRM_SUCCESS, - it.grid.storm.srm.types.TStatusCode.SRM_SUCCESS); - wsTOstorm.put(srmClientStubs.TStatusCode.SRM_FAILURE, - it.grid.storm.srm.types.TStatusCode.SRM_FAILURE); - wsTOstorm.put(srmClientStubs.TStatusCode.SRM_AUTHENTICATION_FAILURE, - it.grid.storm.srm.types.TStatusCode.SRM_AUTHENTICATION_FAILURE); - wsTOstorm.put(srmClientStubs.TStatusCode.SRM_AUTHORIZATION_FAILURE, - it.grid.storm.srm.types.TStatusCode.SRM_AUTHORIZATION_FAILURE); // Bug in - // wsdl!!! - // un-AUA-thorised - // instead - // of - // un-AU-thorised!!! - wsTOstorm.put(srmClientStubs.TStatusCode.SRM_INVALID_REQUEST, - it.grid.storm.srm.types.TStatusCode.SRM_INVALID_REQUEST); - wsTOstorm.put(srmClientStubs.TStatusCode.SRM_INVALID_PATH, - it.grid.storm.srm.types.TStatusCode.SRM_INVALID_PATH); - wsTOstorm.put(srmClientStubs.TStatusCode.SRM_FILE_LIFETIME_EXPIRED, - it.grid.storm.srm.types.TStatusCode.SRM_FILE_LIFETIME_EXPIRED); - wsTOstorm.put(srmClientStubs.TStatusCode.SRM_SPACE_LIFETIME_EXPIRED, - it.grid.storm.srm.types.TStatusCode.SRM_SPACE_LIFETIME_EXPIRED); - wsTOstorm.put(srmClientStubs.TStatusCode.SRM_EXCEED_ALLOCATION, - it.grid.storm.srm.types.TStatusCode.SRM_EXCEED_ALLOCATION); - wsTOstorm.put(srmClientStubs.TStatusCode.SRM_NO_USER_SPACE, - it.grid.storm.srm.types.TStatusCode.SRM_NO_USER_SPACE); - wsTOstorm.put(srmClientStubs.TStatusCode.SRM_NO_FREE_SPACE, - it.grid.storm.srm.types.TStatusCode.SRM_NO_FREE_SPACE); - wsTOstorm.put(srmClientStubs.TStatusCode.SRM_DUPLICATION_ERROR, - it.grid.storm.srm.types.TStatusCode.SRM_DUPLICATION_ERROR); - wsTOstorm.put(srmClientStubs.TStatusCode.SRM_NON_EMPTY_DIRECTORY, - it.grid.storm.srm.types.TStatusCode.SRM_NON_EMPTY_DIRECTORY); - wsTOstorm.put(srmClientStubs.TStatusCode.SRM_TOO_MANY_RESULTS, - it.grid.storm.srm.types.TStatusCode.SRM_TOO_MANY_RESULTS); - wsTOstorm.put(srmClientStubs.TStatusCode.SRM_INTERNAL_ERROR, - it.grid.storm.srm.types.TStatusCode.SRM_INTERNAL_ERROR); - wsTOstorm.put(srmClientStubs.TStatusCode.SRM_FATAL_INTERNAL_ERROR, - it.grid.storm.srm.types.TStatusCode.SRM_FATAL_INTERNAL_ERROR); - wsTOstorm.put(srmClientStubs.TStatusCode.SRM_NOT_SUPPORTED, - it.grid.storm.srm.types.TStatusCode.SRM_NOT_SUPPORTED); - wsTOstorm.put(srmClientStubs.TStatusCode.SRM_REQUEST_QUEUED, - it.grid.storm.srm.types.TStatusCode.SRM_REQUEST_QUEUED); // hex 0x1000 --- - // 4096 - wsTOstorm.put(srmClientStubs.TStatusCode.SRM_REQUEST_INPROGRESS, - it.grid.storm.srm.types.TStatusCode.SRM_REQUEST_INPROGRESS); // hex 0x2000 - // --- 8192 - wsTOstorm.put(srmClientStubs.TStatusCode.SRM_REQUEST_SUSPENDED, - it.grid.storm.srm.types.TStatusCode.SRM_REQUEST_SUSPENDED); - wsTOstorm.put(srmClientStubs.TStatusCode.SRM_ABORTED, - it.grid.storm.srm.types.TStatusCode.SRM_ABORTED); // hex 0x7000 --- 28672 - wsTOstorm.put(srmClientStubs.TStatusCode.SRM_RELEASED, - it.grid.storm.srm.types.TStatusCode.SRM_RELEASED); - wsTOstorm.put(srmClientStubs.TStatusCode.SRM_FILE_PINNED, - it.grid.storm.srm.types.TStatusCode.SRM_FILE_PINNED); - wsTOstorm.put(srmClientStubs.TStatusCode.SRM_FILE_IN_CACHE, - it.grid.storm.srm.types.TStatusCode.SRM_FILE_IN_CACHE); - wsTOstorm.put(srmClientStubs.TStatusCode.SRM_SPACE_AVAILABLE, - it.grid.storm.srm.types.TStatusCode.SRM_SPACE_AVAILABLE); - wsTOstorm.put(srmClientStubs.TStatusCode.SRM_LOWER_SPACE_GRANTED, - it.grid.storm.srm.types.TStatusCode.SRM_LOWER_SPACE_GRANTED); - wsTOstorm.put(srmClientStubs.TStatusCode.SRM_DONE, - it.grid.storm.srm.types.TStatusCode.SRM_DONE); // hex 0x5000 - - /* New return status codes: SRM v2.2 */ - // wsTOstorm.put(srmClientStubs.TStatusCode.SRM_PARTIAL_SUCCESS , - // it.grid.storm.srm.types.TStatusCode.SRM_PARTIAL_SUCCESS); - // wsTOstorm.put(srmClientStubs.TStatusCode.SRM_REQUEST_TIMED_OUT , - // it.grid.storm.srm.types.TStatusCode.SRM_REQUEST_TIMED_OUT); - // wsTOstorm.put(srmClientStubs.TStatusCode.SRM_LAST_COPY , - // it.grid.storm.srm.types.TStatusCode.SRM_LAST_COPY); - // wsTOstorm.put(srmClientStubs.TStatusCode.SRM_FILE_BUSY , - // it.grid.storm.srm.types.TStatusCode.SRM_FILE_BUSY); - // wsTOstorm.put(srmClientStubs.TStatusCode.SRM_FILE_LOST , - // it.grid.storm.srm.types.TStatusCode.SRM_FILE_LOST); - // wsTOstorm.put(srmClientStubs.TStatusCode.SRM_FILE_UNAVAILABLE , - // it.grid.storm.srm.types.TStatusCode.SRM_FILE_UNAVAILABLE); - - wsTOstorm.put(srmClientStubs.TStatusCode.SRM_CUSTOM_STATUS, - it.grid.storm.srm.types.TStatusCode.SRM_CUSTOM_STATUS); - Object aux; - for (Iterator i = wsTOstorm.keySet().iterator(); i.hasNext();) { - aux = i.next(); - stormTOws.put(wsTOstorm.get(aux), aux); - } - } - - /** - * Method that returns the only instance of WSReturnStatusConverter. - */ - public static WSReturnStatusConverter getInstance() { - - return converter; - } - - /** - * Method that accepts an srmClientStubs.TReturnStatus and returns an - * it.grid.storm.srm.types.TReturnStatus; if the conversion fails, a - * WSConversionException is thrown with a String reporting the problem - * encountered. - * - * Beware that it was noticed that sometimes a null stub represents an empty - * field for the remote ws. Instead of getting an empty String, null may be - * used instead! This is why null stubs are interpreted as a field that the - * remote WS decided not to fill in. - * - * In particular, since the status cannot be optional, a missing field is just - * not accepted by StoRM: it is treated as a misbehaving WS! For null, then, - * an Exception is thrown! - */ - synchronized public it.grid.storm.srm.types.TReturnStatus fromWS( - srmClientStubs.TReturnStatus stub) throws WSConversionException { - - if (stub == null) - throw new WSConversionException( - "Supplied srmClientStubs.TReturnStatus was null!"); - try { - it.grid.storm.srm.types.TStatusCode code = (it.grid.storm.srm.types.TStatusCode) wsTOstorm - .get(stub.getStatusCode()); - String auxExplanation = stub.getExplanation(); - if (auxExplanation == null) - auxExplanation = ""; - return new it.grid.storm.srm.types.TReturnStatus(code, auxExplanation); - } catch (IllegalArgumentException e) { - throw new WSConversionException( - "Unable to complete conversion for WS TReturnStatus: " - + stub.toString() + "; " + e); - } - } -} diff --git a/src/main/java/it/grid/storm/asynch/WSTurlConverter.java b/src/main/java/it/grid/storm/asynch/WSTurlConverter.java deleted file mode 100644 index 79e45122..00000000 --- a/src/main/java/it/grid/storm/asynch/WSTurlConverter.java +++ /dev/null @@ -1,73 +0,0 @@ -/* - * - * Copyright (c) Istituto Nazionale di Fisica Nucleare (INFN). 2006-2010. - * - * Licensed under the Apache License, Version 2.0 (the "License"); you may not - * use this file except in compliance with the License. You may obtain a copy of - * the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations under - * the License. - */ - -package it.grid.storm.asynch; - -import it.grid.storm.srm.types.InvalidTTURLAttributesException; - -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -/** - * Class used to convert between TTURL from the WebService and StoRM object - * model counterpart. - * - * @author EGRID - ICTP Trieste - * @version 2.0 - * @date October 2005 - */ -public class WSTurlConverter { - - private static Logger log = LoggerFactory.getLogger(WSTurlConverter.class); - - /** - * Method that accepts an srmClientStubs.TTURL and returns an - * it.grid.storm.srm.types.TTURL; if the conversion fails, a - * WSConversionException is thrown with a String reporting the problem - * encountered. - * - * Beware that the representation of an empty srmClientStubs.TTURL is the - * _null_ handle; so null causes an EmptyTTURL to be returned. - * - * However, even if srmClientStubs.TTURL is not null, but its URI then again - * an EmptyTTURL is returned. - * - * Finally, if the URI s String is null or "", then egain an EmptyTTURL is - * returned. - * - * In case for any reason th econversion cannot proceed, a - * WSConverterException is thrown. - */ - public it.grid.storm.srm.types.TTURL fromWS(org.apache.axis.types.URI auxURI) - throws WSConversionException { - - try { - if (auxURI == null) { - return it.grid.storm.srm.types.TTURL.makeEmpty(); - } - String auxString = auxURI.toString(); - if ((auxString == null) || (auxString.equals(""))) { - return it.grid.storm.srm.types.TTURL.makeEmpty(); - } - return it.grid.storm.srm.types.TTURL.makeFromString(auxString); - } catch (InvalidTTURLAttributesException e) { - log.debug("Unexpected error in WSTurlConverter! This is a programming " - + "bug! Could not translate TTURL from WS! {}", e); - throw new WSConversionException(e.toString()); - } - } -} diff --git a/src/main/java/it/grid/storm/catalogs/MalformedGridUserException.java b/src/main/java/it/grid/storm/catalogs/MalformedGridUserException.java index 2a952b3a..f4b61055 100644 --- a/src/main/java/it/grid/storm/catalogs/MalformedGridUserException.java +++ b/src/main/java/it/grid/storm/catalogs/MalformedGridUserException.java @@ -18,8 +18,8 @@ package it.grid.storm.catalogs; /** - * This class represents an Exception thrown when the RequestSummaryCatalog - * cannot create a VomsGridUser with the available data. + * This class represents an Exception thrown when the RequestSummaryCatalog cannot create a + * VomsGridUser with the available data. * * @author EGRID - ICTP Trieste * @date June, 2005 @@ -27,10 +27,9 @@ */ public class MalformedGridUserException extends Exception { - private static final long serialVersionUID = 5607710323595609428L; + private static final long serialVersionUID = 5607710323595609428L; - public String toString() { - - return "MalformedGridUserException"; - } + public MalformedGridUserException(String message) { + super(message); + } } diff --git a/src/main/java/it/grid/storm/catalogs/RequestSummaryCatalog.java b/src/main/java/it/grid/storm/catalogs/RequestSummaryCatalog.java index f43baba9..ee0c6aca 100644 --- a/src/main/java/it/grid/storm/catalogs/RequestSummaryCatalog.java +++ b/src/main/java/it/grid/storm/catalogs/RequestSummaryCatalog.java @@ -31,12 +31,6 @@ import it.grid.storm.srm.types.TSURL; import it.grid.storm.srm.types.TStatusCode; -import java.io.ByteArrayOutputStream; -import java.io.File; -import java.io.FileInputStream; -import java.io.FileNotFoundException; -import java.io.IOException; -import java.io.InputStream; import java.util.ArrayList; import java.util.Collection; import java.util.List; @@ -169,8 +163,7 @@ private RequestSummaryData makeOne(RequestSummaryDataTO to) GridUserInterface auxgu; try { - auxgu = loadVomsGridUser(to.clientDN(), to.vomsAttributes(), - to.requestToken()); + auxgu = loadVomsGridUser(to.clientDN(), to.vomsAttributes()); } catch (MalformedGridUserException e) { StringBuilder sb = new StringBuilder(); sb.append("VomsGridUser could not be created from DN String "); @@ -233,122 +226,29 @@ private RequestSummaryData makeOne(RequestSummaryDataTO to) * persistence and to load any available Proxy. For the moment the VOMS * attributes present in persistence are NOT loaded! */ - // private VomsGridUser loadVomsGridUser(String dn, String rtoken) throws - // MalformedGridUserException { - private GridUserInterface loadVomsGridUser(String dn, String fqans_string, - String rtoken) throws MalformedGridUserException { - - log.debug("REQUEST SUMMARY CATALOG! Received request to create VomsGridUser " - + "for {} {}", dn, rtoken); - // set up proxy from file, if it exists! - String proxyString = null; - FQAN[] fqans_vector = null; - try { - File proxyFile = new File(config.getProxyHome() - + File.separator + rtoken); - if (proxyFile.exists()) { - ByteArrayOutputStream out; - InputStream in; - int c; - out = new ByteArrayOutputStream(); - in = new FileInputStream(proxyFile); - while ((c = in.read()) != -1) { - out.write(c); - } - in.close(); - out.close(); - proxyString = new String(out.toByteArray()); - log.debug("REQUEST SUMMARY CATALOG: Loaded proxy file {} for " - + "request {}", proxyFile.getAbsolutePath(), rtoken); - log.debug("REQUEST SUMMARY CATALOG: proxy content is {}", proxyString); - } else { - log.debug("REQUEST SUMMARY CATALOG: No proxy file {} found for request", - proxyFile.getAbsolutePath(), rtoken); - } - } catch (FileNotFoundException e) { - // This should not happen given the existence test just performed! - log.error("REQUEST SUMMARY CATALOG! The file containing the proxy was " - + "deleted just before reading its content! No proxy has been loaded!", e); - } catch (IOException e) { - // Some generic IO error occured! - log.error("REQUEST SUMMARY CATALOG! The file containing the proxy could " - + "not be read! No proxy has been loaded! {}", e.getMessage(), e); - } catch (Exception e) { - // An unexpected error occured: I am including this generic catch - // because the underlaying filesystem has ACLs, and I do not know - // how exactly Java behaves! - log.error("REQUEST SUMMARY CATALOG! There was an unexpected error while " - + "attempting to read the file containing the proxy! No proxy has been " - + "loaded!"); - log.error(e.getMessage(), e); - } + private GridUserInterface loadVomsGridUser(String dn, String fqansString) throws MalformedGridUserException { - /** - * This code is only for the 1.3.18. This is a workaround to get FQANs using - * the proxy field on request_queue. From the DB is retrieved a single FQAN - * string containing all FQAN separeted by the "#" char. - */ - - if (fqans_string != "") { - String[] fqans_string_array = fqans_string.split("#"); - if (fqans_string_array.length != 0) { - fqans_vector = new FQAN[fqans_string_array.length]; - for (int i = 0; i < fqans_string_array.length; i++) { - fqans_vector[i] = new FQAN(fqans_string_array[i]); - } - } - } else { - // Set FQAN string to null - fqans_string = null; - } + log.debug("load VomsGridUser for dn='{}' and fqansString='{}'", dn, fqansString); - log.debug("REQUEST SUMMARY CATALOG! Received request to create VomsGridUser " - + "for {} {} {}", dn, fqans_string, proxyString); - if ((dn != null) && (fqans_vector != null) && (fqans_vector.length > 0) - && (proxyString != null)) { - // all credentials available! - log.debug("REQUEST SUMMARY CATALOG! DN, VOMS Attributes, and Proxy " - + "certificate found for request {}", rtoken); - GridUserInterface gridUser = null; - try { - gridUser = GridUserManager.makeVOMSGridUser(dn, proxyString, - fqans_vector); - } catch (IllegalArgumentException e) { - log.error("Unexpected error on voms grid user creation. " - + "IllegalArgumentException: {}", e.getMessage(), e); - } - return gridUser; - } else if ((dn != null) - && (fqans_vector != null && fqans_vector.length > 0) - && (proxyString == null)) { - // voms credentials without proxy - log.debug("REQUEST SUMMARY CATALOG! DN and VOMS Attributes found for " - + "request {}", rtoken); - GridUserInterface gridUser = null; - try { - gridUser = GridUserManager.makeVOMSGridUser(dn, fqans_vector); - } catch (IllegalArgumentException e) { - log.error("Unexpected error on voms grid user creation. " - + "IllegalArgumentException: {}", e.getMessage(), e); - } - return gridUser; - } else if ((dn != null) && (fqans_string == null) && (proxyString != null)) { - // NON-voms credentials with proxy - log.debug("REQUEST SUMMARY CATALOG! DN and Proxy found for request {}", rtoken); - return GridUserManager.makeGridUser(dn, proxyString); - } else if ((dn != null) && (fqans_string == null) && (proxyString == null)) { - // NON-voms credentials without proxy - log.debug("REQUEST SUMMARY CATALOG! DN only found for request {}", rtoken); - return GridUserManager.makeGridUser(dn); - } else { - // unmanageble combination! - log.warn("REQUEST SUMMARY CATALOG! Catalog retrieved invalid credentials " - + "data for request {}", rtoken); - log.warn("REQUEST SUMMARY CATALOG! proxy={}\n dn={}\n attributes={}", - proxyString, dn, fqans_string); - throw new MalformedGridUserException(); + if (dn == null) { + throw new MalformedGridUserException("Invalid null DN"); + } + if (fqansString == null || fqansString.isEmpty()) { + return GridUserManager.makeGridUser(dn); } + FQAN[] fqans = new FQAN[fqansString.split("#").length]; + int i = 0; + for (String fqan: fqansString.split("#")) { + fqans[i++] = new FQAN(fqan); + } + try { + return GridUserManager.makeVOMSGridUser(dn, fqans); + } catch (IllegalArgumentException e) { + log.error("Unexpected error on voms grid user creation. " + + "IllegalArgumentException: {}", e.getMessage(), e); + throw new MalformedGridUserException(e.getMessage()); + } } /** diff --git a/src/main/java/it/grid/storm/checksum/ChecksumClient.java b/src/main/java/it/grid/storm/checksum/ChecksumClient.java deleted file mode 100644 index d692b565..00000000 --- a/src/main/java/it/grid/storm/checksum/ChecksumClient.java +++ /dev/null @@ -1,76 +0,0 @@ -/* - * - * Copyright (c) Istituto Nazionale di Fisica Nucleare (INFN). 2006-2010. - * - * Licensed under the Apache License, Version 2.0 (the "License"); you may not - * use this file except in compliance with the License. You may obtain a copy of - * the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations under - * the License. - */ - -package it.grid.storm.checksum; - -import java.io.IOException; -import java.net.MalformedURLException; - -public interface ChecksumClient { - - /** - * Ping the server. - * - * @return true if the server is up and running, - * false otherwise. - */ - public boolean ping(); - - /** - * Returns all the supported checksum algorithms. - * - * @return the supported checksum algorithms. - */ - public String[] getSupportedAlgorithms() throws IOException; - - /** - * Returns the status of the server. - * - * @param filePath - * temporary workaround, checking existence of the file. - * @return the status of the server. - * @throws IOException - */ - public ChecksumServerStatus getStatus(String filePath) throws IOException; - - /** - * Contacts the checksum service and returns the computed checksum for the - * given file. - * - * @param fileAbsolutePath - * file to compute the checksum for. - * @param algorithm - * checksum algorithm. - * @return the computed checksum for the given file. - * @throws IOException - * in case of error contacting the remote service - * @throws ChecksumRuntimeException - * in case there was an error computing the checksum. The exception - * message is set with the error explanation. - */ - public String getChecksum(String fileAbsolutePath, String algorithm) - throws IOException, ChecksumRuntimeException; - - /** - * Set the service endpoint to contact. - * - * @param service - * endpoint (e.g. http://host:port/). - */ - public void setEndpoint(String url) throws MalformedURLException; - -} diff --git a/src/main/java/it/grid/storm/checksum/ChecksumClientFactory.java b/src/main/java/it/grid/storm/checksum/ChecksumClientFactory.java deleted file mode 100644 index 633e56f1..00000000 --- a/src/main/java/it/grid/storm/checksum/ChecksumClientFactory.java +++ /dev/null @@ -1,26 +0,0 @@ -/* - * - * Copyright (c) Istituto Nazionale di Fisica Nucleare (INFN). 2006-2010. - * - * Licensed under the Apache License, Version 2.0 (the "License"); you may not - * use this file except in compliance with the License. You may obtain a copy of - * the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations under - * the License. - */ - -package it.grid.storm.checksum; - -public class ChecksumClientFactory { - - public static ChecksumClient getChecksumClient() { - - return new ChecksumClientImpl(); - } -} diff --git a/src/main/java/it/grid/storm/checksum/ChecksumClientImpl.java b/src/main/java/it/grid/storm/checksum/ChecksumClientImpl.java deleted file mode 100644 index fccf2daa..00000000 --- a/src/main/java/it/grid/storm/checksum/ChecksumClientImpl.java +++ /dev/null @@ -1,239 +0,0 @@ -/* - * - * Copyright (c) Istituto Nazionale di Fisica Nucleare (INFN). 2006-2010. - * - * Licensed under the Apache License, Version 2.0 (the "License"); you may not - * use this file except in compliance with the License. You may obtain a copy of - * the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations under - * the License. - */ - -package it.grid.storm.checksum; - -import java.io.IOException; -import java.io.InputStream; -import java.io.OutputStream; -import java.net.HttpURLConnection; -import java.net.MalformedURLException; -import java.net.URL; - -import org.json.JSONArray; -import org.json.JSONException; -import org.json.JSONObject; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -public class ChecksumClientImpl implements ChecksumClient { - - private static Logger log = LoggerFactory.getLogger(ChecksumClientImpl.class); - - private static final String GET_CHECKSUM_SERVICE = "storm/checksum.json"; - private static final String PING_SERVICE = "storm/ping.json"; - private static final String STATUS_SERVICE = "status"; - - private String endpoint = null; - - public ChecksumClientImpl() { - - } - - public ChecksumClientImpl(String endpoint) throws MalformedURLException { - - setEndpoint(endpoint); - } - - /* - * (non-Javadoc) - * - * @see it.grid.storm.checksum.ChecksumClient#getChecksum(java.lang.String, - * java.lang.String) - */ - public String getChecksum(String fileAbsolutePath, String algorithm) - throws IOException { - - String body = "filePath=" + fileAbsolutePath + "&algorithm=" + algorithm; - - URL url = new URL(endpoint + GET_CHECKSUM_SERVICE); - - HttpURLConnection connection = (HttpURLConnection) url.openConnection(); - connection.setRequestMethod("POST"); - connection.setReadTimeout(0); - connection.setDoOutput(true); - - OutputStream output = connection.getOutputStream(); - output.write(body.getBytes()); - - connection.connect(); - - String responseBody = getResponse(connection); - - connection.disconnect(); - - if (connection.getResponseCode() != 201) { - throw new IOException("Cannot retrieve checksum from URL: " - + url.toString()); - } - - JSONObject jsonResponse; - - try { - jsonResponse = new JSONObject(responseBody); - int status = jsonResponse.getInt("status"); - - if (status == 0) { - return jsonResponse.getString("checksum"); - } - - throw new ChecksumRuntimeException("Error computing checksum (" - + url.toString() + "): " + jsonResponse.getString("explanation")); - - } catch (JSONException e) { - throw new ChecksumRuntimeException("Malformed result from URL: " - + url.toString() + " Response=" + responseBody); - } - } - - private String getResponse(HttpURLConnection connection) throws IOException { - - InputStream responseBodyStream = connection.getInputStream(); - StringBuilder responseBody = new StringBuilder(); - - byte buffer[] = new byte[connection.getContentLength()]; - int read = 0; - while ((read = responseBodyStream.read(buffer)) != -1) { - responseBody.append(new String(buffer, 0, read)); - } - - return responseBody.toString(); - } - - public ChecksumServerStatus getStatus(String filePath) throws IOException { - - String input = ""; - - if (filePath != null) { - input = "?filePath=" + filePath; - } - URL url = new URL(endpoint + STATUS_SERVICE + input); - - HttpURLConnection connection = (HttpURLConnection) url.openConnection(); - connection.setRequestMethod("GET"); - - connection.connect(); - - String responseBody = getResponse(connection); - - connection.disconnect(); - - log.trace("Checksum server status response: {}", responseBody); - - if (connection.getResponseCode() != 200) { - return new ChecksumServerStatus(false, "HTML error: " - + connection.getResponseCode(), -1, -1); - } - - try { - JSONObject jsonServerStatus = (new JSONObject(responseBody)) - .getJSONObject("ChecksumServerStatus"); - - ChecksumServerStatus serverStatus = new ChecksumServerStatus(true); - - serverStatus.setStatusString(jsonServerStatus - .getString(ChecksumServerStatus.STATUS_STRING_KEY)); - serverStatus.setRequestQueue(jsonServerStatus - .getInt(ChecksumServerStatus.REQUEST_QUEUE_KEY)); - serverStatus.setIdleThreads(jsonServerStatus - .getInt(ChecksumServerStatus.IDLE_THREADS_KEY)); - - return serverStatus; - - } catch (JSONException e) { - throw new ChecksumRuntimeException("Malformed result from URL: " - + url.toString() + " Response=" + responseBody); - } - } - - public String[] getSupportedAlgorithms() throws IOException { - - URL url = new URL(endpoint + GET_CHECKSUM_SERVICE); - - HttpURLConnection connection = (HttpURLConnection) url.openConnection(); - connection.setRequestMethod("GET"); - - connection.connect(); - - String responseBody = getResponse(connection); - - connection.disconnect(); - - if (connection.getResponseCode() != 200) { - throw new IOException("Cannot retrieve supported algorithms from URL: " - + url.toString()); - } - - try { - JSONArray jsonArray = (new JSONObject(responseBody)).getJSONArray(null); - - String[] algArray = new String[jsonArray.length()]; - - for (int i = 0; i < jsonArray.length(); i++) { - algArray[i] = jsonArray.getString(i); - } - - return algArray; - - } catch (JSONException e) { - throw new ChecksumRuntimeException("Malformed result from URL: " - + url.toString() + " Response=" + responseBody); - } - } - - public boolean ping() { - - URL url; - try { - url = new URL(endpoint + PING_SERVICE); - } catch (MalformedURLException e) { - // Never thrown... - return false; - } - - HttpURLConnection connection; - try { - - connection = (HttpURLConnection) url.openConnection(); - connection.setRequestMethod("GET"); - connection.connect(); - connection.disconnect(); - - if (connection.getResponseCode() != 200) { - return false; - } - - return true; - - } catch (IOException e) { - return false; - } - } - - public void setEndpoint(String endpoint) throws MalformedURLException { - - // Check for malformed URL - @SuppressWarnings("unused") - URL url = new URL(endpoint); - - if (endpoint.endsWith("/")) { - this.endpoint = endpoint; - } else { - this.endpoint = endpoint + "/"; - } - } -} diff --git a/src/main/java/it/grid/storm/checksum/ChecksumServerStatus.java b/src/main/java/it/grid/storm/checksum/ChecksumServerStatus.java deleted file mode 100644 index 411810ae..00000000 --- a/src/main/java/it/grid/storm/checksum/ChecksumServerStatus.java +++ /dev/null @@ -1,85 +0,0 @@ -/* - * - * Copyright (c) Istituto Nazionale di Fisica Nucleare (INFN). 2006-2010. - * - * Licensed under the Apache License, Version 2.0 (the "License"); you may not - * use this file except in compliance with the License. You may obtain a copy of - * the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations under - * the License. - */ - -package it.grid.storm.checksum; - -public class ChecksumServerStatus { - - public static final String STATUS_STRING_KEY = "statusString"; - public static final String REQUEST_QUEUE_KEY = "requestQueue"; - public static final String IDLE_THREADS_KEY = "idleThreads"; - - private boolean running = false; - private String statusString = ""; - private int requestQueue = -1; - private int idleThreads = -1; - - public ChecksumServerStatus(boolean isRunning) { - - this.running = isRunning; - } - - public ChecksumServerStatus(boolean isRunning, String statusString, - int requestQueue, int idleThreads) { - - this.running = isRunning; - this.statusString = statusString; - this.requestQueue = requestQueue; - this.idleThreads = idleThreads; - } - - public int getIdleThreads() { - - return idleThreads; - } - - public int getRequestQueue() { - - return requestQueue; - } - - public String getStatusString() { - - return statusString; - } - - public boolean isRunning() { - - return running; - } - - public void setIdleThreads(int idleThreads) { - - this.idleThreads = idleThreads; - } - - public void setRequestQueue(int requestQueue) { - - this.requestQueue = requestQueue; - } - - public void setRunning(boolean running) { - - this.running = running; - } - - public void setStatusString(String statusString) { - - this.statusString = statusString; - } - -} diff --git a/src/main/java/it/grid/storm/config/ConfigReader.java b/src/main/java/it/grid/storm/config/ConfigReader.java index 7bfcf4b6..25ca3c75 100644 --- a/src/main/java/it/grid/storm/config/ConfigReader.java +++ b/src/main/java/it/grid/storm/config/ConfigReader.java @@ -17,10 +17,10 @@ package it.grid.storm.config; -import java.util.ArrayList; +import static com.google.common.base.Preconditions.checkNotNull; + import java.util.Iterator; -import org.apache.commons.configuration.AbstractConfiguration; import org.apache.commons.configuration.CompositeConfiguration; import org.apache.commons.configuration.Configuration; import org.apache.commons.configuration.ConfigurationException; @@ -31,122 +31,60 @@ public class ConfigReader { - private static final Logger log = LoggerFactory.getLogger(ConfigReader.class); - - private Configuration c = makeEmptyConfiguration(); - - private String configurationPathname = ""; - - private int refresh = 0; - - - public ConfigReader() { - makeEmptyConfiguration(); - } - - public ConfigReader(String configurationPathname, int refresh) { - - if (configurationPathname != null) { - if (refresh < 0) - refresh = 0; - this.refresh = refresh; - this.configurationPathname = configurationPathname; - log.info("Configuration file {}. Refresh rate: {} seconds", - configurationPathname, - refresh); - - try { - FileChangedReloadingStrategy strategy = new FileChangedReloadingStrategy(); - strategy.setRefreshDelay(refresh); - PropertiesConfiguration properties = new PropertiesConfiguration( - configurationPathname); - log.debug("Configuration properties:"); - String key; - for (Iterator i = properties.getKeys(); i.hasNext();) { - key = (String) i.next(); - log.debug("{} = {}", key, properties.getProperty(key).toString()); - } - properties.setReloadingStrategy(strategy); - this.c = new CompositeConfiguration(); - ((CompositeConfiguration) this.c).addConfiguration(properties); - log.info("Configuration read successfully."); - } catch (ConfigurationException e) { - this.c = makeEmptyConfiguration(); - log.error("Configuration parsing error: {}", e.getMessage(), e); - } - } else { - throw new NullPointerException("Null configuration pathname."); - } - } - - /** - * Method that returns the Apache object holding all configuration parameters! - */ - public Configuration getConfiguration() { - - return c; - } - - /** - * Method that returns the directory containing the configuration files: it is - * extrapolated from the complete pathname of the configuration file. If the - * pathname was not setup, an empty String is returned. - */ - public String configurationDirectory() { - - if (this.configurationPathname.equals("")) - return ""; - int lastSlash = this.configurationPathname - .lastIndexOf(java.io.File.separator); - if (lastSlash == -1) - return ""; // no slash! - return this.configurationPathname.substring(0, lastSlash + 1); - } - - /** - * Private method that returns an Empty implementation of Apache s - * Configuration Object, which does not contain any key, does not - * addPropertyDirect, does not clearProperty, returns an empty Iterator for - * getKeys, returns a primitive Object for getPropertyDirect, returns true for - * isEmpty. - */ - private Configuration makeEmptyConfiguration() { - - return new AbstractConfiguration() { - - protected void addPropertyDirect(String key, Object obj) { - - } - - public void clearProperty(String key) { - - } - - public boolean containsKey(String key) { - - return false; - } - - public Iterator getKeys() { - - return new ArrayList().iterator(); - } - - protected Object getPropertyDirect(String key) { - - return new Object(); - } - - public boolean isEmpty() { - - return true; - } - - public Object getProperty(String key) { - - return new Object(); - } - }; - } + private static final Logger log = LoggerFactory.getLogger(ConfigReader.class); + + private Configuration c; + + private String configurationPathname = ""; + + public ConfigReader(String configurationPathname, int refresh) throws ConfigurationException { + + checkNotNull(configurationPathname, "Null configuration pathname."); + int refreshRate = refresh < 0 ? 0 : refresh; + this.configurationPathname = configurationPathname; + log.info("Configuration file {}. Refresh rate: {} seconds", configurationPathname, refreshRate); + + FileChangedReloadingStrategy strategy = new FileChangedReloadingStrategy(); + strategy.setRefreshDelay(refreshRate); + PropertiesConfiguration properties = new PropertiesConfiguration(configurationPathname); + logPropertiesConfiguration(properties); + properties.setReloadingStrategy(strategy); + this.c = new CompositeConfiguration(); + ((CompositeConfiguration) this.c).addConfiguration(properties); + log.info("Configuration read successfully."); + } + + private void logPropertiesConfiguration(PropertiesConfiguration properties) { + + log.debug("Configuration properties: "); + String key; + for (Iterator i = properties.getKeys(); i.hasNext();) { + key = (String) i.next(); + log.debug("{} = {}", key, properties.getProperty(key)); + } + } + + /** + * Method that returns the Apache object holding all configuration parameters! + */ + public Configuration getConfiguration() { + + return c; + } + + /** + * Method that returns the directory containing the configuration files: it is extrapolated from + * the complete pathname of the configuration file. If the pathname was not setup, an empty String + * is returned. + */ + public String configurationDirectory() { + + if (configurationPathname.isEmpty()) + return ""; + int lastSlash = this.configurationPathname.lastIndexOf(java.io.File.separator); + if (lastSlash == -1) + return ""; // no slash! + return this.configurationPathname.substring(0, lastSlash + 1); + } } diff --git a/src/main/java/it/grid/storm/config/Configuration.java b/src/main/java/it/grid/storm/config/Configuration.java index 9f62a05b..2acef7fb 100644 --- a/src/main/java/it/grid/storm/config/Configuration.java +++ b/src/main/java/it/grid/storm/config/Configuration.java @@ -25,6 +25,7 @@ import java.util.HashMap; import java.util.List; +import org.apache.commons.configuration.ConfigurationException; import org.apache.commons.lang.ArrayUtils; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -45,12 +46,16 @@ public class Configuration { - private static final Logger log = LoggerFactory - .getLogger(Configuration.class); + public static final String DEFAULT_STORM_CONFIG_FILE = "/etc/storm/backend-server/storm.properties"; + public static final String CONFIG_FILE_PATH = "storm.configuration.file"; + public static final String DEFAULT_STORM_CONFIG_REFRESH_RATE = "0"; + public static final String REFRESH_RATE = "storm.configuration.refresh"; - private ConfigReader cr = new ConfigReader(); // set an empty ConfigReader + private static final Logger log = LoggerFactory.getLogger(Configuration.class); - static Configuration instance = new Configuration(); + private final ConfigReader cr; + + private static Configuration instance; private static final String MANAGED_SURLS_KEY = "storm.service.SURL.endpoint"; private static final String MANAGED_SURL_DEFAULT_PORTS_KEY = "storm.service.SURL.default-ports"; @@ -77,16 +82,10 @@ public class Configuration { private static final String PICKING_INITIAL_DELAY_KEY = "asynch.PickingInitialDelay"; private static final String PICKING_TIME_INTERVAL_KEY = "asynch.PickingTimeInterval"; private static final String PICKING_MAX_BATCH_SIZE_KEY = "asynch.PickingMaxBatchSize"; - private static final String SRMCLIENT_PUT_TOTAL_RETRY_TIME_KEY = "asynch.srmclient.retrytime"; - private static final String SRMCLIENT_PUT_TIME_OUT_KEY = "asynch.srmclient.timeout"; - private static final String SRMCLIENT_PUT_SLEEP_TIME_KEY = "asynch.srmclient.sleeptime"; - private static final String SRMCLIENT_PUT_DONE_SLEEP_TIME_KEY = "asynch.srmclient.putdone.sleeptime"; - private static final String SRMCLIENT_PUT_DONE_TIME_OUT_KEY = "asynch.srmclient.putdone.timeout"; private static final String XMLRPC_MAX_THREAD_KEY = "synchcall.xmlrpc.maxthread"; private static final String XMLRPC_MAX_QUEUE_SIZE_KEY = "synchcall.xmlrpc.max_queue_size"; private static final String LIST_OF_DEFAULT_SPACE_TOKEN_KEY = "storm.service.defaultSpaceTokens"; private static final String GRIDFTP_TRANSFER_CLIENT_KEY = "asynch.gridftpclient"; - private static final String SRMCLIENT_KEY = "asynch.srmclient"; private static final String COMMAND_SERVER_BINDING_PORT_KEY = "storm.commandserver.port"; private static final String SERIAL_SCHEDULER_KEY = "scheduler.serial"; private static final String BE_PERSISTENCE_DB_VENDOR_KEY = "persistence.internal-db.dbms-vendor"; @@ -94,11 +93,9 @@ public class Configuration { private static final String BE_PERSISTENCE_DBMS_URL_2KEY = "" + DB_URL_2KEY; private static final String BE_PERSISTENCE_DB_NAME_KEY = "persistence.internal-db.db-name"; private static final String BE_PERSISTENCEDB_USER_NAME_1KEY = "persistence.internal-db.username"; - private static final String BE_PERSISTENCEDB_USER_NAME_2KEY = "" - + DB_USER_NAME_KEY; + private static final String BE_PERSISTENCEDB_USER_NAME_2KEY = "" + DB_USER_NAME_KEY; private static final String BE_PERSISTENCE_DB_PASSWORD_1KEY = "persistence.internal-db.passwd"; - private static final String BE_PERSISTENCE_DB_PASSWORD_2KEY = "" - + DB_PASSWORD_KEY; + private static final String BE_PERSISTENCE_DB_PASSWORD_2KEY = "" + DB_PASSWORD_KEY; private static final String BE_PERSISTENCE_POOL_DB_KEY = "persistence.internal-db.connection-pool"; private static final String BE_PERSISTENCE_POOL_DB_MAX_ACTIVE_KEY = "persistence.internal-db.connection-pool.maxActive"; private static final String BE_PERSISTENCE_POOL_DB_MAX_WAIT_KEY = "persistence.internal-db.connection-pool.maxWait"; @@ -128,7 +125,6 @@ public class Configuration { private static final String NAMESPACE_AUTOMATIC_RELOADING_KEY = "namespace.automatic-config-reload"; private static final String GRIDFTP_TIME_OUT_KEY = "asynch.srmcopy.gridftp.timeout"; private static final String SRM22CLIENT_PIN_LIFE_TIME_KEY = "SRM22Client.PinLifeTime"; - private static final String PROXY_HOME_KEY = "proxy.home"; private static final String AUTOMATIC_DIRECTORY_CREATION_KEY = "directory.automatic-creation"; private static final String DEFAULT_OVERWRITE_MODE_KEY = "default.overwrite"; private static final String DEFAULT_FILE_STORAGE_TYPE_KEY = "default.storagetype"; @@ -160,7 +156,6 @@ public class Configuration { private static final String RETRY_VALUE_KEY_KEY = "tape.recalltable.service.param.retry-value"; private static final String STATUS_KEY_KEY = "tape.recalltable.service.param.status"; private static final String TASKOVER_KEY_KEY = "tape.recalltable.service.param.takeover"; - private static final String GRIDHTTPS_ENABLED_KEY = "gridhttps.enabled"; private static final String STORM_PROPERTIES_VERSION_KEY = "storm.properties.version"; private static final String TAPE_SUPPORT_ENABLED_KEY = "tape.support.enabled"; private static final String SYNCHRONOUS_QUOTA_CHECK_ENABLED_KEY = "info.quota-check.enabled"; @@ -172,9 +167,28 @@ public class Configuration { private static final String XMLRPC_SECURITY_TOKEN_KEY = "synchcall.xmlrpc.security.token"; private static final String PTG_SKIP_ACL_SETUP = "ptg.skip-acl-setup"; private static final String HTTP_TURL_PREFIX = "http.turl_prefix"; + private static final String NETWORKADDRESS_CACHE_TTL = "networkaddress.cache.ttl"; + private static final String NETWORKADDRESS_CACHE_NEGATIVE_TTL = "networkaddress.cache.negative.ttl"; - private Configuration() { + static { + try { + instance = new Configuration(); + } catch (ConfigurationException e) { + log.error(e.getMessage(), e); + throw new ExceptionInInitializerError(e); + } + } + private Configuration() throws ConfigurationException { + + String filePath = System.getProperty(CONFIG_FILE_PATH, DEFAULT_STORM_CONFIG_FILE); + String refreshRate = System.getProperty(REFRESH_RATE, DEFAULT_STORM_CONFIG_REFRESH_RATE); + try { + cr = new ConfigReader(filePath, Integer.parseInt(refreshRate)); + } catch (NumberFormatException e) { + log.error(e.getMessage(), e); + throw new ConfigurationException(e.getMessage(), e); + } } /** @@ -185,17 +199,6 @@ public static Configuration getInstance() { return Configuration.instance; } - /** - * Method used to set the config reader: if a null is supplied then a default - * empty ConfigReader is used instead. - */ - public void setConfigReader(ConfigReader cr) { - - if (cr != null) { - this.cr = cr; - } - } - /** * Method that returns the directory holding the configuration file. The * methods that make use of it are uncertain... must be found soon!!! Beware @@ -676,104 +679,6 @@ public int getPickingMaxBatchSize() { } } - /** - * Method used by CopyChunk when making a remote srmPrepareToPut (Push Mode). - * It needs it to estalish the totalRetryTime in seconds to supply to the - * internal SRMClient. The parameter is passed to the prepareToPut - * functionality. If no value is found in the configuration medium, then the - * default value is returned instead. key="asynch.srmclient.retrytime"; - * default value=60; - */ - public long getSRMClientPutTotalRetryTime() { - - if (!cr.getConfiguration().containsKey(SRMCLIENT_PUT_TOTAL_RETRY_TIME_KEY)) { - // return default - return 60; - } else { - // load from external source - return cr.getConfiguration().getLong(SRMCLIENT_PUT_TOTAL_RETRY_TIME_KEY); - } - } - - /** - * Method used by CopyChunk when making a remote srmPrepareToPut (Push Mode). - * The CopyChunk will periodically invoke the statusOfPutRequest functionality - * of the internal SRMClient, for at most the time out interval in seconds - * returned by this method. If no value is found in the configuration medium, - * then the default value is returned instead. key="asynch.srmclient.timeout"; - * default value=180; - */ - public long getSRMClientPutTimeOut() { - - if (!cr.getConfiguration().containsKey(SRMCLIENT_PUT_TIME_OUT_KEY)) { - // return default - return 180; - } else { - // load from external source - return cr.getConfiguration().getLong(SRMCLIENT_PUT_TIME_OUT_KEY); - } - } - - /** - * Method used by CopyChunk when making a remote srmPrepareToPut (Push Mode). - * The CopyChunk will wait the amount of time in seconds returned by this - * method, before invoking again the statusOfPutRequest functionality of the - * internal SRMClient. That is, it tells the polling interval. If no value is - * found in the configuration medium, then the default value is returned - * instead. key="asynch.srmclient.sleeptime"; default value=5; - */ - public long getSRMClientPutSleepTime() { - - if (!cr.getConfiguration().containsKey(SRMCLIENT_PUT_SLEEP_TIME_KEY)) { - // return default - return 5; - } else { - // load from external source - return cr.getConfiguration().getLong(SRMCLIENT_PUT_SLEEP_TIME_KEY); - } - } - - /** - * Method used by CopyChunk when making the FileTransfer and finally invoking - * a remote srmPutDone. The CopyChunk will wait the amount of time in seconds - * returned by this method, before invoking again the srmPutDone functionality - * of the internal SRMClient. That is, it tells the time interval between - * successive invocations: they are necessary when the returned status is - * SRM_INTERNAL_ERROR which denotes a transient error situation. If no value - * is found in the configuration medium, then the default value is returned - * instead. key="asynch.srmclient.putdone.sleeptime"; default value=2; - */ - public long getSRMClientPutDoneSleepTime() { - - if (!cr.getConfiguration().containsKey(SRMCLIENT_PUT_DONE_SLEEP_TIME_KEY)) { - // return default - return 1; - } else { - // load from external source - return cr.getConfiguration().getLong(SRMCLIENT_PUT_DONE_SLEEP_TIME_KEY); - } - } - - /** - * Method used by CopyChunk when making the FileTransfer and finally invoking - * a remote srmPutDone. The CopyChunk may have to periodically invoke - * srmPutDone functionality of the internal SRMClient if the web service - * returns SRM_INTERNAL_ERROR; in that case invocations will be attempted for - * at most the time out interval in seconds returned by this method. If no - * value is found in the configuration medium, then the default value is - * returned instead. key="asynch.srmclient.putdone.timeout"; default value=60; - */ - public long getSRMClientPutDoneTimeOut() { - - if (!cr.getConfiguration().containsKey(SRMCLIENT_PUT_DONE_TIME_OUT_KEY)) { - // return default - return 60; - } else { - // load from external source - return cr.getConfiguration().getLong(SRMCLIENT_PUT_DONE_TIME_OUT_KEY); - } - } - /** * Get max number of xmlrpc threads into for the XMLRPC server. */ @@ -839,25 +744,6 @@ public String getGridFTPTransferClient() { } } - /** - * Method used by Factory invoked in CopyChunk subclasses, to instantiate an - * SRMClient. The String returned specifies the name of the class to - * instantiate; for now, there are two classes: NaiveSRMClient and - * StubSRMClient. If no value is found in the configuration medium, then the - * default value is returned instead. key="asynch.srmclient"; default - * value="it.grid.storm.asynch.SRM22Client"; - */ - public String getSRMClient() { - - if (!cr.getConfiguration().containsKey(SRMCLIENT_KEY)) { - // return default - return "it.grid.storm.asynch.SRM22Client"; - } else { - // load from external source - return cr.getConfiguration().getString(SRMCLIENT_KEY); - } - } - /** * Method used by StoRMCommandServer to establish the listening port to which * it should bind. If no value is found in the configuration medium, then the @@ -1626,23 +1512,6 @@ public int getSRM22ClientPinLifeTime() { } } - /** - * Method used by RequestCredentialsDAO to establish the directory that holds - * the proxy file. If no value is found in the configuration medium, then the - * default one is used instead. key="proxy.home"; default - * value="/opt/storm/var/proxies" - */ - public String getProxyHome() { - - if (!cr.getConfiguration().containsKey(PROXY_HOME_KEY)) { - // return default - return "/opt/storm/var/proxies"; - } else { - // load from external source - return cr.getConfiguration().getString(PROXY_HOME_KEY); - } - } - /** * Method used by PtPChunk to find out if missing local directories should be * created automatically or not. SRM 2.2 specification forbids automatic @@ -2138,22 +2007,6 @@ public String getTaskoverKey() { } } - /** - * This is the FLAG to support or not the http(s) protocol. Default is false. - * - * @return - */ - public boolean getGridhttpsEnabled() { - - if (!cr.getConfiguration().containsKey(GRIDHTTPS_ENABLED_KEY)) { - // return default - return false; - } else { - // load from external source - return cr.getConfiguration().getBoolean(GRIDHTTPS_ENABLED_KEY); - } - } - public String getStoRMPropertiesVersion() { if (!cr.getConfiguration().containsKey(STORM_PROPERTIES_VERSION_KEY)) { @@ -2244,14 +2097,7 @@ public Long getServerPoolStatusCheckTimeout() { public boolean getSanityCheckEnabled() { - if (!cr.getConfiguration().containsKey(SANITY_CHECK_ENABLED_KEY)) { - // return default - return true; - } else { - // load from external source - return new Boolean(cr.getConfiguration().getBoolean( - SANITY_CHECK_ENABLED_KEY)); - } + return cr.getConfiguration().getBoolean(SANITY_CHECK_ENABLED_KEY, true); } public Boolean getXmlRpcTokenEnabled() { @@ -2351,4 +2197,11 @@ public long getInProgressPutRequestExpirationTime() { return cr.getConfiguration().getLong(EXPIRED_INPROGRESS_PTP_TIME_KEY, 2592000L); } + public int getNetworkAddressCacheTtl() { + return cr.getConfiguration().getInt(NETWORKADDRESS_CACHE_TTL, 0); + } + + public int getNetworkAddressCacheNegativeTtl() { + return cr.getConfiguration().getInt(NETWORKADDRESS_CACHE_NEGATIVE_TTL, 0); + } } diff --git a/src/main/java/it/grid/storm/ea/StormEA.java b/src/main/java/it/grid/storm/ea/StormEA.java index d08902a4..a48c2fde 100644 --- a/src/main/java/it/grid/storm/ea/StormEA.java +++ b/src/main/java/it/grid/storm/ea/StormEA.java @@ -52,7 +52,7 @@ public static void init(ExtendedAttributes extendedAttributes) { public static Map getChecksums(String filename) { - HashMap result = new HashMap(); + Map result = new HashMap<>(); for (ChecksumAlgorithm checksumAlgorithm : ChecksumAlgorithm.values()) { @@ -167,9 +167,9 @@ public static void setPinned(String fileName, long expirationDateInSEC) { Format formatter = new SimpleDateFormat("dd MMM yyyy HH:mm:ss"); if (existingPinValueInSEC >= expirationDateInSEC) { - log.debug("The file '" + fileName - + "' is already Pinned and the pre-existing PinLifeTime is greater than the new one. Nothing is changed in EA. Expiration: " - + formatter.format(new Date(existingPinValueInSEC * 1000))); + log.debug("The file '{}' is already Pinned and the pre-existing PinLifeTime is greater " + + "than the new one. Nothing is changed in EA. Expiration: {}", + fileName, formatter.format(new Date(existingPinValueInSEC * 1000))); return; } @@ -189,7 +189,7 @@ public static void setPinned(String fileName, long expirationDateInSEC) { } } catch (ExtendedAttributesException e) { - log.warn("Cannot set pinned EA to file: " + fileName); + log.warn("Cannot set pinned EA to file: {}", fileName, e); } } @@ -199,7 +199,7 @@ public static void setPremigrate(String fileName) { ea.setXAttr(fileName, EA_PREMIGRATE, null); } catch (ExtendedAttributesException e) { - log.warn("Cannot set pre-migrate EA to file: " + fileName); + log.warn("Cannot set pre-migrate EA to file: {}", fileName, e); } } @@ -226,7 +226,7 @@ public static void setOnline(String fileName, boolean status) { ea.setXAttr(fileName, EA_TEST_ONLINE, String.valueOf(status)); } catch (ExtendedAttributesException e) { - log.warn("Cannot set test-online EA to file: " + fileName); + log.warn("Cannot set test-online EA to file: {}", fileName, e); } } } diff --git a/src/main/java/it/grid/storm/filesystem/LocalFile.java b/src/main/java/it/grid/storm/filesystem/LocalFile.java index c4310a11..99f7ca65 100644 --- a/src/main/java/it/grid/storm/filesystem/LocalFile.java +++ b/src/main/java/it/grid/storm/filesystem/LocalFile.java @@ -244,7 +244,7 @@ public Map getChecksums() { localFile.getAbsolutePath()); } catch (FileNotFoundException e) { log.error(e.getMessage(), e); - return new HashMap(0); + return new HashMap<>(0); } } @@ -438,10 +438,6 @@ public FilesystemPermission getUserPermission(final LocalUser u) { * the given LocalUser u in this file ACL, or * {@link Filesystem#NONE} if no ACE for that group was found. */ - // TODO ACL manager - // public FilesystemPermission grantGroupPermission(final LocalUser u, final - // FilesystemPermission permission) - // throws CannotMapUserException { public FilesystemPermission grantGroupPermission(final LocalUser u, final FilesystemPermission permission) { @@ -467,10 +463,6 @@ public FilesystemPermission grantGroupPermission(final LocalUser u, * given LocalUser u in this file ACL, or * {@link Filesystem#NONE} if no ACE for that user was found. */ - // TODO ACL manager - // public FilesystemPermission grantUserPermission(final LocalUser u, final - // FilesystemPermission permission) - // throws CannotMapUserException { public FilesystemPermission grantUserPermission(final LocalUser u, final FilesystemPermission permission) { @@ -488,7 +480,7 @@ public boolean hasChecksum() { return ChecksumManager.getInstance().hasChecksum( localFile.getAbsolutePath()); } catch (FileNotFoundException e) { - log.warn("File not found when checking checksum: {}",e.getMessage()); + log.warn("File not found when checking checksum: {}", e.getMessage(), e); return false; } } @@ -497,21 +489,6 @@ public boolean isDirectory() throws SecurityException { return localFile.isDirectory(); } - private boolean isGPFS() throws FSException { - - try { - return FileSystemCheckerFactory.getInstance().createFileSystemChecker() - .isGPFS(this.localFile); - } catch (Exception e) { - log.error("Unable to check if file {} is on GPFS. {}", - this.localFile.getAbsolutePath(), - e.getMessage(),e); - throw new FSException("Unable to check if file " - + this.localFile.getAbsolutePath() - + " is on GPFS. IllegalArgumentException " + e.getMessage()); - } - } - /** * Returns true is the file is present on the disk, * false otherwise. @@ -609,9 +586,6 @@ public boolean parentExists() { * the given LocalUser u in this file ACL, or * {@link Filesystem#NONE} if no ACE for that group was found. */ - // TODO ACL manager - // public FilesystemPermission removeGroupPermission(final LocalUser u) throws - // CannotMapUserException { public FilesystemPermission removeGroupPermission(final LocalUser u) { return fs.removeGroupPermission(u, localFile.getAbsolutePath()); @@ -633,9 +607,6 @@ public FilesystemPermission removeGroupPermission(final LocalUser u) { * given LocalUser u in this file ACL, or * {@link Filesystem#NONE} if no ACE for that user was found. */ - // TODO ACL manager - // public FilesystemPermission removeUserPermission(final LocalUser u) throws - // CannotMapUserException { public FilesystemPermission removeUserPermission(final LocalUser u) { return fs.removeUserPermission(u, localFile.getAbsolutePath()); @@ -674,10 +645,6 @@ public boolean renameTo(String newName) throws SecurityException, * {@link Filesystem#NONE} if no ACE for that group was found. * @see fs_acl::revoke_group_perm() */ - // TODO ACL manager - // public FilesystemPermission revokeGroupPermission(final LocalUser u, final - // FilesystemPermission permission) - // throws CannotMapUserException { public FilesystemPermission revokeGroupPermission(final LocalUser u, final FilesystemPermission permission) { @@ -704,10 +671,6 @@ public FilesystemPermission revokeGroupPermission(final LocalUser u, * given LocalUser u in this file ACL, or * {@link Filesystem#NONE} if no ACE for that user was found. */ - // TODO ACL manager - // public FilesystemPermission revokeUserPermission(final LocalUser u, final - // FilesystemPermission permission) - // throws CannotMapUserException { public FilesystemPermission revokeUserPermission(final LocalUser u, final FilesystemPermission permission) { @@ -752,10 +715,6 @@ public void setGroupOwnership(String groupName) throws FSException { * the given LocalUser u in this file ACL, or * {@link Filesystem#NONE} if no ACE for that group was found. */ - // TODO ACL manager - // public FilesystemPermission setGroupPermission(final LocalUser u, final - // FilesystemPermission permission) - // throws CannotMapUserException { public FilesystemPermission setGroupPermission(final LocalUser u, final FilesystemPermission permission) { @@ -778,10 +737,6 @@ public FilesystemPermission setGroupPermission(final LocalUser u, * given LocalUser u in this file ACL, or * {@link Filesystem#NONE} if no ACE for that user was found. */ - // TODO ACL manager - // public FilesystemPermission setUserPermission(final LocalUser u, final - // FilesystemPermission permission) - // throws CannotMapUserException { public FilesystemPermission setUserPermission(final LocalUser u, final FilesystemPermission permission) { diff --git a/src/main/java/it/grid/storm/namespace/InvalidGetTURLProtocolException.java b/src/main/java/it/grid/storm/namespace/InvalidGetTURLProtocolException.java index f8f378e1..e65fd4e6 100644 --- a/src/main/java/it/grid/storm/namespace/InvalidGetTURLProtocolException.java +++ b/src/main/java/it/grid/storm/namespace/InvalidGetTURLProtocolException.java @@ -27,19 +27,15 @@ * @version 1.0 */ -import it.grid.storm.common.types.*; - public class InvalidGetTURLProtocolException extends Exception { - private int size = 0; - - public InvalidGetTURLProtocolException(TURLPrefix turls) { - - size = turls.size(); - } + /** + * + */ + private static final long serialVersionUID = 1L; - public String toString() { + public InvalidGetTURLProtocolException(String message) { - return ("Preifix of Matching Protocol is EMPTY = " + size); - } + super(message); + } } diff --git a/src/main/java/it/grid/storm/namespace/NamespaceDirector.java b/src/main/java/it/grid/storm/namespace/NamespaceDirector.java index 5425e964..4332bbfd 100644 --- a/src/main/java/it/grid/storm/namespace/NamespaceDirector.java +++ b/src/main/java/it/grid/storm/namespace/NamespaceDirector.java @@ -17,15 +17,12 @@ package it.grid.storm.namespace; -import it.grid.storm.config.ConfigReader; import it.grid.storm.config.Configuration; import it.grid.storm.namespace.config.NamespaceLoader; import it.grid.storm.namespace.config.NamespaceParser; import it.grid.storm.namespace.config.xml.XMLNamespaceLoader; import it.grid.storm.namespace.config.xml.XMLNamespaceParser; -import java.io.File; - import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -35,58 +32,26 @@ public class NamespaceDirector { .getLogger(NamespaceDirector.class);; private static NamespaceInterface namespaceIstance = null; - private static int refreshInSeconds = 5; // Default value; - private static String configurationPATH; - private static String namespaceConfigFileName; - private static boolean runningMode = false; - private static String configurationFileName; private static NamespaceLoader loader; private static NamespaceParser parser; private static boolean initialized = false; - public static void initializeDirector(boolean verboseMode, boolean testingMode) { + private NamespaceDirector() {} + + public static void initializeDirector() { log.info("NAMESPACE : Initializing ..."); Configuration config = Configuration.getInstance(); - if (testingMode) { - log.info(" ####################### "); - log.info(" #### TESTING MODE #### "); - log.info(" ####################### "); - setRunningMode(testingMode); - configurationPATH = System.getProperty("user.dir") + File.separator - + "etc"; - configurationFileName = configurationPATH + File.separator - + "storm_test.properties"; - config.setConfigReader(new ConfigReader(configurationFileName, - refreshInSeconds)); - namespaceConfigFileName = config.getNamespaceConfigFilename(); - refreshInSeconds = config.getNamespaceConfigRefreshRateInSeconds(); - loader = new XMLNamespaceLoader(configurationPATH, - namespaceConfigFileName, refreshInSeconds, false); - - // Check the validity of namespace. - if (loader instanceof XMLNamespaceLoader) { - XMLNamespaceLoader xmlLoader = (XMLNamespaceLoader) loader; - if (!(xmlLoader.schemaValidity)) { - // Error into the validity ckeck of namespace - log.error("Namespace configuration is not conformant with namespae grammar."); - log.error("Please validate namespace configuration file."); - System.exit(0); - } - } + log.info(" +++++++++++++++++++++++ "); + log.info(" Production Mode "); + log.info(" +++++++++++++++++++++++ "); - } else { - log.info(" +++++++++++++++++++++++ "); - log.info(" Production Mode "); - log.info(" +++++++++++++++++++++++ "); - setRunningMode(testingMode); - configurationPATH = config.namespaceConfigPath(); - namespaceConfigFileName = config.getNamespaceConfigFilename(); - refreshInSeconds = config.getNamespaceConfigRefreshRateInSeconds(); - loader = new XMLNamespaceLoader(configurationPATH, - namespaceConfigFileName, refreshInSeconds, verboseMode); + String configurationPATH = config.namespaceConfigPath(); + String namespaceConfigFileName = config.getNamespaceConfigFilename(); + int refreshInSeconds = config.getNamespaceConfigRefreshRateInSeconds(); + loader = new XMLNamespaceLoader(configurationPATH, namespaceConfigFileName, refreshInSeconds); // Check the validity of namespace. if (loader instanceof XMLNamespaceLoader) { @@ -99,13 +64,11 @@ public static void initializeDirector(boolean verboseMode, boolean testingMode) } } - } - log.debug("Namespace Configuration PATH : {}" , configurationPATH); log.debug("Namespace Configuration FILENAME : {}" , namespaceConfigFileName); log.debug("Namespace Configuration GLANCE RATE : {}" , refreshInSeconds); - parser = new XMLNamespaceParser(loader, verboseMode, testingMode); + parser = new XMLNamespaceParser(loader); namespaceIstance = new Namespace(parser); log.debug("NAMESPACE INITIALIZATION : ... done!"); @@ -120,7 +83,7 @@ public static void initializeDirector(boolean verboseMode, boolean testingMode) public static NamespaceInterface getNamespace() { if (!(initialized)) { - initializeDirector(false, false); + initializeDirector(); } return namespaceIstance; } @@ -129,24 +92,10 @@ public static NamespaceInterface getNamespace() { * * @return Namespace */ - public static NamespaceInterface getNamespace(boolean verboseMode, - boolean testingMode) { + public static NamespaceParser getNamespaceParser() { if (!(initialized)) { - initializeDirector(verboseMode, testingMode); - } - return namespaceIstance; - } - - /** - * - * @return Namespace - */ - public static NamespaceParser getNamespaceParser(boolean verboseMode, - boolean testingMode) { - - if (!(initialized)) { - initializeDirector(verboseMode, testingMode); + initializeDirector(); } return parser; } @@ -155,11 +104,10 @@ public static NamespaceParser getNamespaceParser(boolean verboseMode, * * @return Namespace */ - public static NamespaceLoader getNamespaceLoader(boolean verboseMode, - boolean testingMode) { + public static NamespaceLoader getNamespaceLoader() { if (!(initialized)) { - initializeDirector(verboseMode, testingMode); + initializeDirector(); } return loader; } @@ -169,14 +117,4 @@ public static Logger getLogger() { return log; } - public static boolean isRunningMode() { - - return runningMode; - } - - private static void setRunningMode(boolean runningMode) { - - NamespaceDirector.runningMode = runningMode; - } - } diff --git a/src/main/java/it/grid/storm/namespace/StoRIImpl.java b/src/main/java/it/grid/storm/namespace/StoRIImpl.java index 07aa682f..98698211 100644 --- a/src/main/java/it/grid/storm/namespace/StoRIImpl.java +++ b/src/main/java/it/grid/storm/namespace/StoRIImpl.java @@ -49,6 +49,8 @@ import it.grid.storm.srm.types.TSpaceToken; import it.grid.storm.srm.types.TTURL; +import static org.apache.commons.lang.StringUtils.join; + import java.io.File; import java.util.ArrayList; import java.util.Calendar; @@ -447,18 +449,15 @@ public TTURL getTURL(TURLPrefix desiredProtocols) // Within the request there are some protocol preferences // Calculate the intersection between Desired Protocols and Available // Protocols - ArrayList desiredP = new ArrayList( - desiredProtocols.getDesiredProtocols()); - - ArrayList availableP = new ArrayList( - this.capability.getAllManagedProtocols()); - + List desiredP = new ArrayList<>(desiredProtocols.getDesiredProtocols()); + List availableP = new ArrayList<>(capability.getAllManagedProtocols()); desiredP.retainAll(availableP); if (desiredP.isEmpty()) { - log - .error("stori:No match with Protocol Preferences and Protocol Managed!"); - throw new InvalidGetTURLProtocolException(desiredProtocols); + String msg = String.format("None of [%s] protocols matches the available " + + "protocols [%s]", join(desiredP, ','), join(availableP, ',')); + log.error(msg); + throw new InvalidGetTURLProtocolException(msg); } else { diff --git a/src/main/java/it/grid/storm/namespace/config/NamespaceCheck.java b/src/main/java/it/grid/storm/namespace/config/NamespaceCheck.java index 4eae95da..5b0edbe0 100644 --- a/src/main/java/it/grid/storm/namespace/config/NamespaceCheck.java +++ b/src/main/java/it/grid/storm/namespace/config/NamespaceCheck.java @@ -17,10 +17,8 @@ package it.grid.storm.namespace.config; -import it.grid.storm.config.Configuration; import it.grid.storm.namespace.CapabilityInterface; import it.grid.storm.namespace.NamespaceDirector; -import it.grid.storm.namespace.NamespaceException; import it.grid.storm.namespace.VirtualFSInterface; import it.grid.storm.namespace.model.ACLEntry; import it.grid.storm.namespace.model.ApproachableRule; @@ -30,8 +28,9 @@ import java.io.File; import java.util.ArrayList; -import java.util.Hashtable; import java.util.Iterator; +import java.util.List; +import java.util.Map; import org.slf4j.Logger; @@ -58,13 +57,13 @@ public class NamespaceCheck { private final Logger log = NamespaceDirector.getLogger(); - private final Hashtable vfss; - private final Hashtable maprules; - private final Hashtable apprules; + private final Map vfss; + private final Map maprules; + private final Map apprules; - public NamespaceCheck(Hashtable vfss, - Hashtable maprules, - Hashtable apprules) { + public NamespaceCheck(Map vfss, + Map maprules, + Map apprules) { this.vfss = vfss; this.maprules = maprules; @@ -73,13 +72,11 @@ public NamespaceCheck(Hashtable vfss, public boolean check() { - boolean totalResult = true; boolean vfsCheck = checkVFS(); boolean mapRulesCheck = checkMapRules(); boolean appRules = checkAppRules(); - boolean checkGroups = checkGroups(vfsCheck); - totalResult = vfsCheck && mapRulesCheck && appRules; - return totalResult; + checkGroups(vfsCheck); + return vfsCheck && mapRulesCheck && appRules; } private boolean checkGroups(boolean vfsCheckResult) { @@ -92,8 +89,7 @@ private boolean checkGroups(boolean vfsCheckResult) { .warn("Skip the check of the needed Local Group, because check of VFSs failed."); } else { - ArrayList vf = new ArrayList( - vfss.values()); + List vf = new ArrayList<>(vfss.values()); for (VirtualFSInterface vfs : vf) { // Check the presence of Default ACL @@ -101,13 +97,12 @@ private boolean checkGroups(boolean vfsCheckResult) { if (cap != null) { DefaultACL defACL = cap.getDefaultACL(); if (defACL != null) { - ArrayList acl = new ArrayList(defACL.getACL()); + List acl = new ArrayList<>(defACL.getACL()); if (!acl.isEmpty()) { for (ACLEntry aclEntry : acl) { if (!LocalGroups.getInstance().isGroupDefined( aclEntry.getGroupName())) { - log.warn("!!!!! Local Group for ACL ('" + aclEntry - + "') is not defined!"); + log.warn("!!!!! Local Group for ACL ('{}') is not defined!", aclEntry); result = false; } } @@ -140,21 +135,19 @@ private boolean checkVFS() { log.error("Anyone VFS is defined in namespace!"); return false; } else { - ArrayList rules = new ArrayList( - vfss.values()); + List rules = new ArrayList<>(vfss.values()); Iterator scan = rules.iterator(); while (scan.hasNext()) { VirtualFSInterface vfs = scan.next(); - + String aliasName = vfs.getAliasName(); - log.debug("VFS named '" + aliasName + "' found."); + log.debug("VFS named '{}' found.", aliasName); String root = vfs.getRootPath(); File file = new File(root); boolean exists = file.exists(); if (!exists) { - log.error("ERROR in NAMESPACE: The VFS '" + aliasName - + "' does not have a valid root :'" + root + "'"); + log.error("ERROR in NAMESPACE: The VFS '{}' does not have a valid root :'{}'", aliasName, root); result = false; } } @@ -172,9 +165,8 @@ private boolean checkMapRules() { return false; } else { int nrOfMappingRules = maprules.size(); - log.debug("Number of Mapping rules = " + nrOfMappingRules); - ArrayList rules = new ArrayList( - maprules.values()); + log.debug("Number of Mapping rules = {}", nrOfMappingRules); + List rules = new ArrayList<>(maprules.values()); Iterator scan = rules.iterator(); MappingRule rule; String mappedVFS; @@ -182,11 +174,9 @@ private boolean checkMapRules() { while (scan.hasNext()) { rule = scan.next(); mappedVFS = rule.getMappedFS().getAliasName(); - // log.debug("Map rule "+rule.getRuleName()+" maps to VFS named = '"+mappedVFS+"'"); check = vfss.containsKey(mappedVFS); if (!check) { - log.error("ERROR in NAMESPACE - MAP RULE '" + rule.getRuleName() - + "' point a UNKNOWN VFS '" + mappedVFS + "'!"); + log.error("ERROR in NAMESPACE - MAP RULE '{}' point a UNKNOWN VFS '{}'!", rule.getRuleName(), mappedVFS); result = false; } } @@ -202,20 +192,17 @@ private boolean checkAppRules() { return false; } else { int nrOfApproachableRules = apprules.size(); - log.debug("Number of Approachable rules = " + nrOfApproachableRules); - ArrayList rules = new ArrayList( - apprules.values()); + log.debug("Number of Approachable rules = {}", nrOfApproachableRules); + List rules = new ArrayList<>(apprules.values()); Iterator scan = rules.iterator(); boolean check = false; while (scan.hasNext()) { ApproachableRule rule = scan.next(); - ArrayList approachVFSs = new ArrayList( - rule.getApproachableVFS()); + List approachVFSs = new ArrayList<>(rule.getApproachableVFS()); for (VirtualFSInterface aVfs : approachVFSs) { check = vfss.containsKey(aVfs.getAliasName()); if (!check) { - log.error("ERROR in NAMESPACE - APP RULE '" + rule.getRuleName() - + "' point a UNKNOWN VFS '" + aVfs + "'!"); + log.error("ERROR in NAMESPACE - APP RULE '{}' point a UNKNOWN VFS '{}'!", rule.getRuleName(), aVfs); result = false; } } diff --git a/src/main/java/it/grid/storm/namespace/config/xml/XMLNamespaceLoader.java b/src/main/java/it/grid/storm/namespace/config/xml/XMLNamespaceLoader.java index a75f8e0f..58d8429a 100644 --- a/src/main/java/it/grid/storm/namespace/config/xml/XMLNamespaceLoader.java +++ b/src/main/java/it/grid/storm/namespace/config/xml/XMLNamespaceLoader.java @@ -20,11 +20,10 @@ import it.grid.storm.namespace.NamespaceValidator; import it.grid.storm.namespace.config.NamespaceLoader; +import static java.io.File.separatorChar; + import java.io.File; import java.io.IOException; -import java.text.Format; -import java.text.SimpleDateFormat; -import java.util.Date; import java.util.Observable; import java.util.Observer; import java.util.Timer; @@ -77,7 +76,6 @@ public class XMLNamespaceLoader extends Observable implements NamespaceLoader { private final Timer timer = new Timer(); private XMLReloadingStrategy xmlStrategy; private String namespaceFN = null; - private boolean verbose = false; private final String namespaceSchemaURL; public boolean schemaValidity = false; @@ -99,7 +97,7 @@ public XMLNamespaceLoader(int refresh) { } namespaceFN = getNamespaceFileName(); namespaceSchemaURL = getNamespaceSchemaFileName(); - log.debug("Namespace XSD : " + namespaceSchemaURL); + log.debug("Namespace XSD : {}", namespaceSchemaURL); init(namespaceFN, refresh); } @@ -108,7 +106,7 @@ public XMLNamespaceLoader(String filename) { this.filename = filename; namespaceFN = getNamespaceFileName(); namespaceSchemaURL = getNamespaceSchemaFileName(); - log.debug("Namespace XSD : " + namespaceSchemaURL); + log.debug("Namespace XSD : {}", namespaceSchemaURL); init(namespaceFN, refresh); } @@ -118,12 +116,11 @@ public XMLNamespaceLoader(String path, String filename) { this.filename = filename; namespaceFN = getNamespaceFileName(); namespaceSchemaURL = getNamespaceSchemaFileName(); - log.debug("Namespace XSD : " + namespaceSchemaURL); + log.debug("Namespace XSD : {}", namespaceSchemaURL); init(namespaceFN, refresh); } - public XMLNamespaceLoader(String path, String filename, int refresh, - boolean verboseMode) { + public XMLNamespaceLoader(String path, String filename, int refresh) { if (refresh < 0) { this.refresh = 0; @@ -134,8 +131,7 @@ public XMLNamespaceLoader(String path, String filename, int refresh, this.filename = filename; namespaceFN = getNamespaceFileName(); namespaceSchemaURL = getNamespaceSchemaFileName(); - log.debug("Namespace XSD : " + namespaceSchemaURL); - verbose = verboseMode; + log.debug("Namespace XSD : {}", namespaceSchemaURL); init(namespaceFN, refresh); } @@ -150,11 +146,6 @@ public void setNotifyManaged() { config.setReloadingStrategy(xmlStrategy); } - public void setVerbosity(boolean verbosity) { - - verbose = verbosity; - } - /** * The setChanged() protected method must overridden to make it public */ @@ -166,16 +157,13 @@ public synchronized void setChanged() { private void init(String namespaceFileName, int refresh) { - log.info("Reading Namespace configuration file " - + namespaceFileName + " and setting refresh rate to " + refresh - + " seconds."); + log.info("Reading Namespace configuration file {} and setting refresh rate to {} seconds.", namespaceFileName, refresh); // create reloading strategy for refresh xmlStrategy = new XMLReloadingStrategy(); period = 3000; // Conversion in millisec. - log.debug(" Refresh time is " + period + " millisec"); - xmlStrategy.setRefreshDelay(period); // Set to refresh sec the refreshing - // delay. + log.debug(" Refresh time is {} millisec", period); + xmlStrategy.setRefreshDelay(period); // Set to refresh sec the refreshing delay. namespaceFN = namespaceFileName; @@ -210,7 +198,7 @@ private void init(String namespaceFileName, int refresh) { log.debug("Namespace Configuration read!"); } catch (ConfigurationException cex) { - log.error("ATTENTION! Unable to load Namespace Configuration!"); + log.error("ATTENTION! Unable to load Namespace Configuration!", cex); log.error(toString()); } @@ -224,16 +212,16 @@ private String getNamespaceFileName() { String namespaceFN = it.grid.storm.config.Configuration.getInstance() .getNamespaceConfigFilename(); // Build the filename - if (configurationDir.charAt(configurationDir.length() - 1) != File.separatorChar) { - configurationDir += File.separatorChar; + if (configurationDir.charAt(configurationDir.length() - 1) != separatorChar) { + configurationDir += Character.toString(separatorChar); } String namespaceAbsFN = configurationDir + namespaceFN; // Check the namespace conf file accessibility File nsFile = new File(namespaceAbsFN); if (nsFile.exists()) { - log.debug("Found the namespace file : " + namespaceAbsFN); + log.debug("Found the namespace file : {}", namespaceAbsFN); } else { - log.error("Unable to find the namespace file :" + namespaceAbsFN); + log.error("Unable to find the namespace file : {}", namespaceAbsFN); } return namespaceAbsFN; } @@ -243,7 +231,7 @@ private String getNamespaceSchemaFileName() { String schemaName = it.grid.storm.config.Configuration.getInstance() .getNamespaceSchemaFilename(); - if (schemaName.equals("Schema UNKNOWN!")) { + if ("Schema UNKNOWN!".equals(schemaName)) { schemaName = "namespace.xsd"; String namespaceFN = getNamespaceFileName(); @@ -255,28 +243,22 @@ private String getNamespaceSchemaFileName() { Document doc = builder.parse(namespaceFN); Element rootElement = doc.getDocumentElement(); String tagName = rootElement.getTagName(); - if (tagName.equals("namespace")) { + if ("namespace".equals(tagName)) { if (rootElement.hasAttributes()) { String value = rootElement .getAttribute("xsi:noNamespaceSchemaLocation"); if ((value != null) && (value.length() > 0)) { schemaName = value; - // log.debug("namespace schema is : " + schemaName); } } else { - log.error(namespaceFN - + " don't have a valid root element attributes"); + log.error("{} don't have a valid root element attributes", namespaceFN); } } else { - log.error(namespaceFN + " don't have a valid root element."); + log.error("{} don't have a valid root element.", namespaceFN); } - } catch (ParserConfigurationException e) { - log.error("Error while parsing " + namespaceFN + e.getMessage()); - } catch (SAXException e) { - log.error("Error while parsing " + namespaceFN + e.getMessage()); - } catch (IOException e) { - log.error("Error while parsing " + namespaceFN + e.getMessage()); + } catch (ParserConfigurationException | SAXException | IOException e) { + log.error("Error while parsing {}: {}", namespaceFN, e.getMessage(), e); } } } @@ -294,8 +276,7 @@ private static boolean checkValidity(String namespaceSchemaURL, String filename) { NamespaceValidator validator = new NamespaceValidator(); - boolean valid = validator.validateSchema(namespaceSchemaURL, filename); - return valid; + return validator.validateSchema(namespaceSchemaURL, filename); } /** @@ -336,22 +317,6 @@ public void run() { // log.debug(" The glange of peeper.."); reloadingStrategy = (XMLReloadingStrategy) config.getReloadingStrategy(); - if (verbose) { - File xmlFile = reloadingStrategy.getConfigurationFile(); - log.debug(" Peeper glance on XMLReloadingStrategy bound with FILE : " - + xmlFile.getName()); - long lastFileModified = xmlFile.lastModified(); - Date dateFile = new Date(lastFileModified); - long lastFileModifiedReload = reloadingStrategy.getLastReload(); - reloadingStrategy.reloadingPerformed(); - Date dateReload = new Date(lastFileModifiedReload); - if (lastFileModifiedReload < lastFileModified) { - log.debug("RELOAD NEEDED!"); - Format formatter = new SimpleDateFormat("HH.mm.ss dd.MM.yyyy"); - log.debug(" FILE XML Last Modified : " + formatter.format(dateFile)); - log.debug(" FILE XML Last RELOAD : " + formatter.format(dateReload)); - } - } boolean changed = reloadingStrategy.reloadingRequired(); if (changed) { log.debug(" NAMESPACE CONFIGURATION is changed ! "); diff --git a/src/main/java/it/grid/storm/namespace/config/xml/XMLNamespaceParser.java b/src/main/java/it/grid/storm/namespace/config/xml/XMLNamespaceParser.java index 33f59d60..bf8d10cd 100644 --- a/src/main/java/it/grid/storm/namespace/config/xml/XMLNamespaceParser.java +++ b/src/main/java/it/grid/storm/namespace/config/xml/XMLNamespaceParser.java @@ -1,974 +1,904 @@ -/* - * - * Copyright (c) Istituto Nazionale di Fisica Nucleare (INFN). 2006-2010. - * - * Licensed under the Apache License, Version 2.0 (the "License"); you may not - * use this file except in compliance with the License. You may obtain a copy of - * the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations under - * the License. - */ - -package it.grid.storm.namespace.config.xml; - -import it.grid.storm.balancer.BalancingStrategyType; -import it.grid.storm.check.sanity.filesystem.SupportedFSType; -import it.grid.storm.namespace.CapabilityInterface; -import it.grid.storm.namespace.DefaultValuesInterface; -import it.grid.storm.namespace.NamespaceDirector; -import it.grid.storm.namespace.NamespaceException; -import it.grid.storm.namespace.PropertyInterface; -import it.grid.storm.namespace.VirtualFSInterface; -import it.grid.storm.namespace.config.NamespaceCheck; -import it.grid.storm.namespace.config.NamespaceLoader; -import it.grid.storm.namespace.config.NamespaceParser; -import it.grid.storm.namespace.model.ACLEntry; -import it.grid.storm.namespace.model.ApproachableRule; -import it.grid.storm.namespace.model.Authority; -import it.grid.storm.namespace.model.Capability; -import it.grid.storm.namespace.model.DefaultValues; -import it.grid.storm.namespace.model.MappingRule; -import it.grid.storm.namespace.model.PermissionException; -import it.grid.storm.namespace.model.PoolMember; -import it.grid.storm.namespace.model.Property; -import it.grid.storm.namespace.model.Property.SizeUnitType; -import it.grid.storm.namespace.model.Protocol; -import it.grid.storm.namespace.model.ProtocolPool; -import it.grid.storm.namespace.model.Quota; -import it.grid.storm.namespace.model.QuotaType; -import it.grid.storm.namespace.model.SAAuthzType; -import it.grid.storm.namespace.model.StorageClassType; -import it.grid.storm.namespace.model.SubjectRules; -import it.grid.storm.namespace.model.TransportProtocol; -import it.grid.storm.namespace.model.VirtualFS; -import it.grid.storm.space.SpaceHelper; -import it.grid.storm.space.gpfsquota.GPFSFilesetQuotaInfo; -import it.grid.storm.space.gpfsquota.GetGPFSFilesetQuotaInfoCommand; -import it.grid.storm.srm.types.TSizeInBytes; -import it.grid.storm.srm.types.TSpaceToken; -import it.grid.storm.util.GPFSSizeHelper; - -import java.util.ArrayList; -import java.util.Collection; -import java.util.Enumeration; -import java.util.HashMap; -import java.util.Hashtable; -import java.util.Iterator; -import java.util.List; -import java.util.Map; -import java.util.Map.Entry; -import java.util.Observable; -import java.util.Observer; -import java.util.Vector; -import java.util.concurrent.locks.Lock; -import java.util.concurrent.locks.ReentrantLock; - -import org.apache.commons.configuration.ConfigurationException; -import org.apache.commons.configuration.XMLConfiguration; -import org.slf4j.Logger; - -/** - *

- * Title: - *

- * - *

- * Description: - *

- * - *

- * Copyright: Copyright (c) 2006 - *

- * - *

- * Company: INFN-CNAF and ICTP/eGrid project - *

- * - * @author Riccardo Zappi - * @version 1.0 - */ - -public class XMLNamespaceParser implements NamespaceParser, Observer { - - private final Logger log = NamespaceDirector.getLogger(); - - private String version; - private Hashtable vfss; - private Hashtable maprules; - private Hashtable apprules; - - private XMLParserUtil parserUtil; - private final XMLConfiguration configuration; - private XMLNamespaceLoader xmlLoader; - - private final Lock refreshing = new ReentrantLock(); - - // For debug purpose only - private final boolean internalLog; - private final boolean testingMode; - - /** - * Constructor - * - * @param loader - * NamespaceLoader - */ - public XMLNamespaceParser(NamespaceLoader loader, boolean verboseLogging, - boolean testingMode) { - - configuration = (XMLConfiguration) loader.getConfiguration(); - if (loader instanceof XMLNamespaceLoader) { - xmlLoader = (XMLNamespaceLoader) loader; - xmlLoader.setObserver(this); - } else { - log.error("XMLParser initialized with a non-XML Loader"); - } - // this.internalLog = verboseLogging; - // TOREMOVE - internalLog = true; - - this.testingMode = testingMode; - - parserUtil = new XMLParserUtil(configuration); - - for (Iterator iter = parserUtil.getKeys(); iter.hasNext();) { - Object item = iter.next(); - verboseLog(item.toString()); - } - - vfss = new Hashtable(); - maprules = new Hashtable(); - apprules = new Hashtable(); - - boolean validNamespaceConfiguration = refreshCachedData(); - if (!(validNamespaceConfiguration)) { - log.error(" ???????????????????????????????????? "); - log.error(" ???? NAMESPACE does not VALID ???? "); - log.error(" ???????????????????????????????????? "); - log.error(" Please see the log. "); - System.exit(0); - } - - } - - public Map getVFSs() { - - return vfss; - } - - public Map getApproachableRules() { - - return apprules; - } - - public Map getMappingRules() { - - return maprules; - } - - public long getLastUpdateTime() { - - return 0L; - } - - public void update(Observable observed, Object arg) { - - log.debug(arg + " Refreshing Namespace Memory Cache .. "); - - XMLNamespaceLoader loader = (XMLNamespaceLoader) observed; - parserUtil = new XMLParserUtil(loader.getConfiguration()); - - if (loader.schemaValidity) { - refreshCachedData(); - } - - loader.setNotifyManaged(); - - log.debug(" ... Cache Refreshing ended"); - } - - /**************************************************************** - * PRIVATE METHODs - *****************************************************************/ - - private boolean refreshCachedData() { - - boolean result = false; - try { - refreshing.lock(); - configuration.clear(); - configuration.clearTree("filesystems"); - configuration.clearTree("mapping-rules"); - configuration.clearTree("approachable-rules"); - try { - configuration.load(); - log - .debug(" ... reading and parsing the namespace configuration from file!"); - } catch (ConfigurationException ex) { - ex.printStackTrace(); - } - log.debug("REFRESHING CACHE.."); - // Save the cache content - log.debug(" ..save the cache content before semantic check"); - Hashtable vfssSAVED = vfss; - Hashtable maprulesSAVED = maprules; - Hashtable apprulesSAVED = apprules; - // Refresh the cache content with new values - - log.debug(" ..refresh the cache"); - refreshCache(); - - // Do the checking on Namespace - log.debug(" ..semantic check of namespace"); - NamespaceCheck checker = new NamespaceCheck(vfss, maprules, apprules); - boolean semanticCheck = checker.check(); - - // If there is an error restore old cache content - log.debug("REFRESHING ENDED."); - if (semanticCheck) { - log.debug("Namespace is semantically valid"); - result = true; - } else { - log - .warn("Namespace does not semantically valid!, so no load performed!"); - vfss = vfssSAVED; - maprules = maprulesSAVED; - apprules = apprulesSAVED; - result = false; - } - } finally { - refreshing.unlock(); - } - return result; - } - - private void verboseLog(String msg) { - - if (internalLog) { - log.debug(msg); - } - } - - private void refreshCache() { - - log - .info(" ############## REFRESHING NAMESPACE CONFIGURATION CACHE : start ###############"); - - /************************** - * Retrieve Version Number - *************************/ - try { - retrieveVersion(); - } catch (NamespaceException ex1) { - log - .warn( - "Namespace configuration does not contain a valid version number.", - ex1); - /** - * @todo Manage this exceptional status! - */ - } - - /************************** - * Building VIRTUAL FS - *************************/ - try { - buildVFSs(); - } catch (ClassNotFoundException ex) { - log - .error("Namespace Configuration ERROR in VFS-DRIVER specification", ex); - /** - * @todo Manage this exceptional status! - */ - } catch (NamespaceException ex) { - log - .error( - "Namespace Configuration ERROR in VFS definition, please check it.", - ex); - /** - * @todo Manage this exceptional status! - */ - } - - /************************** - * Building MAPPING RULES - *************************/ - try { - buildMapRules(); - } catch (NamespaceException ex1) { - log - .error( - "Namespace Configuration ERROR in MAPPING RULES definition, please check it.", - ex1); - /** - * @todo Manage this exceptional status! - */ - } - - /************************** - * Building APPROACHABLE RULES - *************************/ - try { - buildAppRules(); - } catch (NamespaceException ex2) { - log - .error( - "Namespace Configuration ERROR in APPROACHABLE RULES definition, please check it.", - ex2); - /** - * @todo Manage this exceptional status! - */ - } - log - .info(" ############## REFRESHING NAMESPACE CONFIGURATION CACHE : end ###############"); - - handleTotalOnlineSizeFromGPFSQuota(); - // Update SA within Reserved Space Catalog - updateSA(); - } - - private void handleTotalOnlineSizeFromGPFSQuota() { - - for (Entry entry : vfss.entrySet()) { - String storageAreaName = entry.getKey(); - VirtualFSInterface storageArea = entry.getValue(); - if (SupportedFSType.parseFS(storageArea.getFSType()) == SupportedFSType.GPFS) { - Quota quota = storageArea.getCapabilities().getQuota(); - if (quota != null && quota.getEnabled()) { - - GPFSFilesetQuotaInfo quotaInfo = getGPFSQuotaInfo(storageArea); - if (quotaInfo != null) { - updateTotalOnlineSizeFromGPFSQuota(storageAreaName, storageArea, - quotaInfo); - } - } - } - } - } - - private GPFSFilesetQuotaInfo getGPFSQuotaInfo(VirtualFSInterface storageArea) { - - GetGPFSFilesetQuotaInfoCommand cmd = new GetGPFSFilesetQuotaInfoCommand( - storageArea); - - try { - return cmd.call(); - } catch (Throwable t) { - log - .warn( - "Cannot get quota information out of GPFS. Using the TotalOnlineSize in namespace.xml " - + "for Storage Area {}. Reason: {}", storageArea.getAliasName(), - t.getMessage()); - return null; - } - } - - private void updateTotalOnlineSizeFromGPFSQuota(String storageAreaName, - VirtualFSInterface storageArea, GPFSFilesetQuotaInfo quotaInfo) { - - long gpfsTotalOnlineSize = GPFSSizeHelper.getBytesFromKIB(quotaInfo - .getBlockSoftLimit()); - Property newProperties = Property.from(storageArea.getProperties()); - try { - newProperties.setTotalOnlineSize(SizeUnitType.BYTE.getTypeName(), - gpfsTotalOnlineSize); - storageArea.setProperties(newProperties); - log.warn("TotalOnlineSize as specified in namespace.xml will be ignored " - + "since quota is enabled on the GPFS {} Storage Area.", - storageAreaName); - } catch (NamespaceException e) { - log - .warn( - "Cannot get quota information out of GPFS. Using the TotalOnlineSize in namespace.xml " - + "for Storage Area {}.", storageAreaName, e); - } - } - - // ******************* Update SA Catalog *************************** - private void updateSA() { - - TSpaceToken spaceToken = null; - // ReservedSpaceCatalog spaceCatalog = new ReservedSpaceCatalog(); - SpaceHelper spaceHelp = new SpaceHelper(); - log - .debug("Updating Space Catalog with Storage Area defined within NAMESPACE"); - VirtualFS vfs = null; - Enumeration scan = vfss.elements(); - while (scan.hasMoreElements()) { - - vfs = (VirtualFS) scan.nextElement(); - String vfsAliasName = vfs.getAliasName(); - verboseLog(" Considering VFS : " + vfsAliasName); - String aliasName = vfs.getSpaceTokenDescription(); - if (aliasName == null) { - // Found a VFS without the optional element Space Token Description - log.debug("XMLNamespaceParser.UpdateSA() : Found a VFS ('" - + vfsAliasName - + "') without space-token-description. Skipping the Update of SA"); - } else { - TSizeInBytes onlineSize = vfs.getProperties().getTotalOnlineSize(); - String spaceFileName = vfs.getRootPath(); - spaceToken = spaceHelp.createVOSA_Token(aliasName, onlineSize, - spaceFileName); - vfs.setSpaceToken(spaceToken); - - verboseLog(" Updating SA ('" + aliasName + "'), token:'" + spaceToken - + "', onlineSize:'" + onlineSize + "', spaceFileName:'" - + spaceFileName); - } - - } - spaceHelp.purgeOldVOSA_token(); - log.debug("Updating Space Catalog... DONE!!"); - - } - - // ******************* VERSION NUMBER *************************** - private void retrieveVersion() throws NamespaceException { - - version = parserUtil.getNamespaceVersion(); - verboseLog(" ==== NAMESPACE VERSION : '" + version + "' ===="); - } - - // ******************* VIRTUAL FS *************************** - - private void buildVFSs() throws ClassNotFoundException, NamespaceException { - - int nrOfVFS = 0; - - nrOfVFS = parserUtil.getNumberOfFS(); - // For each VFS within configuration build VFS class istance - VirtualFS vfs; - String spaceTokenDescription = null; - StorageClassType storageClass = StorageClassType.UNKNOWN; - String root = null; - String name; - String fsType; - Class driver; - String storageAreaAuthz; - PropertyInterface prop; - CapabilityInterface cap; - DefaultValuesInterface defValues; - SAAuthzType saAuthzType = SAAuthzType.UNKNOWN; - - for (int i = 0; i < nrOfVFS; i++) { - // Building VFS - vfs = new VirtualFS(testingMode); - - name = parserUtil.getFSName(i); - vfs.setAliasName(name); - verboseLog("VFS(" + i + ").name = '" + name + "'"); - - fsType = parserUtil.getFSType(name); - vfs.setFSType(fsType); - verboseLog("VFS(" + name + ").fs_type = '" + fsType + "'"); - - spaceTokenDescription = parserUtil.getFSSpaceTokenDescription(name); - vfs.setSpaceTokenDescription(spaceTokenDescription); - verboseLog("VFS(" + name + ").space-token-description = '" - + spaceTokenDescription + "'"); - - storageClass = StorageClassType.getStorageClassType(parserUtil - .getStorageClass(name)); - vfs.setStorageClassType(storageClass); - verboseLog("VFS(" + name + ").storage-class = '" + storageClass + "'"); - - root = parserUtil.getFSRoot(name); - vfs.setRoot(root); - verboseLog("VFS(" + name + ").root = '" + root + "'"); - - driver = Class.forName(parserUtil.getFSDriver(name)); - vfs.setFSDriver(driver); - verboseLog("VFS(" + name + ").fsDriver [CLASS Name] = '" - + driver.getName() + "'"); - - driver = Class.forName(parserUtil.getSpaceDriver(name)); - vfs.setSpaceSystemDriver(driver); - verboseLog("VFS(" + name + ").spaceDriver [CLASS Name] = '" - + driver.getName() + "'"); - - saAuthzType = parserUtil.getStorageAreaAuthzType(name); - vfs.setSAAuthzType(saAuthzType); - verboseLog("VFS(" + name + ").storage-area-authz.TYPE = '" + saAuthzType - + "'"); - - storageAreaAuthz = parserUtil.getStorageAreaAuthz(name, saAuthzType); - vfs.setSAAuthzSource(storageAreaAuthz); - verboseLog("VFS(" + name + ").storage-area-authz = '" + storageAreaAuthz - + "'"); - - prop = buildProperties(name); - vfs.setProperties(prop); - - cap = buildCapabilities(name); - vfs.setCapabilities(cap); - - defValues = buildDefaultValues(name); - vfs.setDefaultValues(defValues); - - // Adding VFS - synchronized (this) { - vfss.remove(name); - vfss.put(name, vfs); - } - } - } - - // ******************* PROPERTY *************************** - private PropertyInterface buildProperties(String fsName) - throws NamespaceException { - - Property prop = new Property(); - - String accessLatency = parserUtil.getAccessLatencyType(fsName); - prop.setAccessLatency(accessLatency); - verboseLog("VFS(" + fsName + ").Properties.AccessLatency = '" - + accessLatency + "'"); - - String expirationMode = parserUtil.getExpirationModeType(fsName); - prop.setExpirationMode(expirationMode); - verboseLog("VFS(" + fsName + ").Properties.ExpirationMode = '" - + expirationMode + "'"); - - String retentionPolicy = parserUtil.getRetentionPolicyType(fsName); - prop.setRetentionPolicy(retentionPolicy); - verboseLog("VFS(" + fsName + ").Properties.RetentionPolicy = '" - + retentionPolicy + "'"); - - String unitType = parserUtil.getNearlineSpaceUnitType(fsName); - long nearLineSize = parserUtil.getNearlineSpaceSize(fsName); - prop.setTotalNearlineSize(unitType, nearLineSize); - verboseLog("VFS(" + fsName + ").Properties.NearlineSpaceSize = '" - + nearLineSize + " " + unitType + "'"); - - unitType = parserUtil.getOnlineSpaceUnitType(fsName); - long onlineSize = parserUtil.getOnlineSpaceSize(fsName); - prop.setTotalOnlineSize(unitType, onlineSize); - verboseLog("VFS(" + fsName + ").Properties.OnlineSpaceSize = '" - + onlineSize + " " + unitType + "'"); - - boolean hasLimitedSize = parserUtil.getOnlineSpaceLimitedSize(fsName); - prop.setLimitedSize(hasLimitedSize); - verboseLog("VFS(" + fsName + ").Properties.OnlineSpaceLimitedSize = '" - + hasLimitedSize + "'"); - - return prop; - } - - // ******************* CAPABILITY *************************** - - private CapabilityInterface buildCapabilities(String fsName) - throws NamespaceException { - - /** - * String[] fileType = parserUtil.getFileType(fsName); for (int j = 0; j < - * fileType.length; j++) { verboseLog("VFS(" + fsName + - * ").Capabilities.file.types(" + j + ") = '" + fileType[j] + "'"); } - * String[] spaceType = parserUtil.getSpaceType(fsName); for (int j = 0; j < - * spaceType.length; j++) { verboseLog("VFS(" + fsName + - * ").Capabilities.space.types(" + j + ") = '" + spaceType[j] + "'"); } - **/ - - /** - * ACL MODE ELEMENT - */ - String aclMode = parserUtil.getACLMode(fsName); - Capability cap = new Capability(aclMode); - verboseLog("VFS(" + fsName + ").Capabilities.aclMode = '" + aclMode + "'"); - - /** - * DEFAULT ACL - */ - boolean defaultACLDefined = parserUtil.getDefaultACLDefined(fsName); - verboseLog("VFS(" + fsName + ").Capabilities.defaultACL [Defined?] =" - + defaultACLDefined); - if (defaultACLDefined) { - int nrACLEntries = parserUtil.getNumberOfACL(fsName); - String groupName = null; - String filePermString = null; - ACLEntry aclEntry = null; - for (int entryNumber = 0; entryNumber < nrACLEntries; entryNumber++) { - groupName = parserUtil.getGroupName(fsName, entryNumber); - filePermString = parserUtil.getPermissionString(fsName, entryNumber); - try { - aclEntry = new ACLEntry(groupName, filePermString); - cap.addACLEntry(aclEntry); - } catch (PermissionException permEx) { - log - .error("Namespace XML Parser -- ERROR -- : " + permEx.getMessage()); - } - } - verboseLog("VFS(" + fsName + ").Capabilities.defaultACL = " - + cap.getDefaultACL()); - } - - /** - * QUOTA ELEMENT - */ - boolean quotaDefined = parserUtil.getQuotaDefined(fsName); - Quota quota = null; - if (quotaDefined) { - boolean quotaEnabled = parserUtil.getQuotaEnabled(fsName); - String device = parserUtil.getQuotaDevice(fsName); - - QuotaType quotaType; - String quotaValue = null; - - if (parserUtil.getQuotaFilesetDefined(fsName)) { - quotaType = QuotaType.buildQuotaType(QuotaType.FILESET); - quotaValue = parserUtil.getQuotaFileset(fsName); - } else { - if (parserUtil.getQuotaGroupIDDefined(fsName)) { - quotaType = QuotaType.buildQuotaType(QuotaType.GRP); - quotaValue = parserUtil.getQuotaGroupID(fsName); - } else { - if (parserUtil.getQuotaUserIDDefined(fsName)) { - quotaType = QuotaType.buildQuotaType(QuotaType.USR); - quotaValue = parserUtil.getQuotaUserID(fsName); - } else { - quotaType = QuotaType.buildQuotaType(QuotaType.UNKNOWN); - quotaValue = "unknown"; - } - } - } - - quotaType.setValue(quotaValue); - quota = new Quota(quotaEnabled, device, quotaType); - - } else { - quota = new Quota(); - } - cap.setQuota(quota); - - verboseLog("VFS(" + fsName + ").Capabilities.quota = '" + quota + "'"); - log.debug("VFS(" + fsName + ").Capabilities.quota = '" + quota + "'"); - - /** - * TRANSFER PROTOCOL - */ - int nrProtocols = parserUtil.getNumberOfProt(fsName); - Protocol protocol; - Authority service; - TransportProtocol transportProt; - int protocolIndex; - String serviceHostName; - String servicePortValue; - String schema; - String name; - for (int protCounter = 0; protCounter < nrProtocols; protCounter++) { - protocolIndex = parserUtil.getProtId(fsName, protCounter); // 1.4.0 - // (Return -1 - // if ID is - // not - // present) - name = parserUtil.getProtName(fsName, protCounter); - schema = parserUtil.getProtSchema(fsName, protCounter); - protocol = Protocol.getProtocol(schema); - protocol.setProtocolServiceName(name); - serviceHostName = parserUtil.getProtHost(fsName, protCounter); - servicePortValue = parserUtil.getProtPort(fsName, protCounter); - int portIntValue = -1; - service = null; - if (servicePortValue != null) { - try { - portIntValue = Integer.parseInt(servicePortValue); - service = new Authority(serviceHostName, portIntValue); - // log.debug("SERVICE PORT: "+service); - } catch (NumberFormatException nfe) { - log - .warn("to evaluate the environmental variable " + servicePortValue); - } - } else { - service = new Authority(serviceHostName); - // log.debug("SERVICE : "+service); - } - transportProt = new TransportProtocol(protocol, service); - transportProt.setProtocolID(protocolIndex); // 1.4.0 - verboseLog("VFS(" + fsName + ").Capabilities.protocol(" + protCounter - + ") = '" + transportProt + "'"); - cap.addTransportProtocolByScheme(protocol, transportProt); - cap.addTransportProtocol(transportProt); - if (protocolIndex != -1) { - cap.addTransportProtocolByID(protocolIndex, transportProt); - } - - } - - /** - * PROTOCOL POOL - */ - int nrPools = parserUtil.getNumberOfPool(fsName); - if (nrPools > 0) { - - for (int poolCounter = 0; poolCounter < nrPools; poolCounter++) { - BalancingStrategyType balanceStrategy = BalancingStrategyType - .getByValue(parserUtil.getBalancerStrategy(fsName, poolCounter)); // 1.4.0 - // (Return - // -1 - // if - // ID - // is - // not - // present) - ArrayList poolMembers = new ArrayList(); - int nrMembers = parserUtil.getNumberOfPoolMembers(fsName, poolCounter); - for (int i = 0; i < nrMembers; i++) { - int protIndex = parserUtil.getMemberID(fsName, poolCounter, i); - TransportProtocol tProtMember = cap.getProtocolByID(protIndex); // search - // for - // the - // member - // with - // specified - // ID - if (tProtMember != null) { // member found! - PoolMember poolMember; - if (balanceStrategy.requireWeight()) { // Check for the weight - int memberWeight = parserUtil.getMemberWeight(fsName, - poolCounter, i); - poolMember = new PoolMember(protIndex, tProtMember, memberWeight); - } else { - poolMember = new PoolMember(protIndex, tProtMember); - } - poolMembers.add(poolMember); - } else { // member pointed out doesn't exist!! - log.error("POOL Building: Protocol with index " + protIndex - + " does not exists in the VFS :" + fsName); - throw new NamespaceException("POOL Building: Protocol with index " - + protIndex + " does not exists in the VFS :" + fsName); - } - } - Protocol pooProtocol = poolMembers.get(0).getMemberProtocol() - .getProtocol(); - verifyPoolIsValid(poolMembers); - log.debug("Defined pool for protocol " + pooProtocol.toString() - + " with size " + poolMembers.size()); - cap.addProtocolPoolBySchema(pooProtocol, new ProtocolPool( - balanceStrategy, poolMembers)); - log.debug("PROTOCOL POOL: " + cap.getPoolByScheme(pooProtocol)); - } - } else { - log.debug("Pool is not defined in VFS " + fsName); - } - - return cap; - } - - /** - * @param poolMembers - * @throws NamespaceException - */ - private void verifyPoolIsValid(ArrayList poolMembers) - throws NamespaceException { - - if (poolMembers.isEmpty()) { - throw new NamespaceException("POOL Defined is EMPTY!"); - } - Protocol prot = poolMembers.get(0).getMemberProtocol().getProtocol(); - for (PoolMember member : poolMembers) { - if (!(member.getMemberProtocol().getProtocol().equals(prot))) { - throw new NamespaceException( - "Defined Pool is NOT HOMOGENEOUS! Protocols " + prot.toString() - + " and " + member.toString() + " differs"); - } - } - } - - // ******************* DEFAULT VALUES *************************** - - private DefaultValuesInterface buildDefaultValues(String fsName) - throws NamespaceException { - - DefaultValues def = new DefaultValues(); - if (parserUtil.isDefaultElementPresent(fsName)) { - setSpaceDef(fsName, def); - setFileDef(fsName, def); - } else { // Produce Default Values with default values :o ! - verboseLog("VFS(" + fsName - + ").DefaultValues is ABSENT. Using DEFAULT values."); - } - return def; - } - - private void setSpaceDef(String fsName, DefaultValues def) - throws NamespaceException { - - String spaceType = parserUtil.getDefaultSpaceType(fsName); - verboseLog("VFS(" + fsName + ").DefaultValues.space.type = '" + spaceType - + "'"); - long lifeTime = parserUtil.getDefaultSpaceLifeTime(fsName); - verboseLog("VFS(" + fsName + ").DefaultValues.space.lifeTime = '" - + lifeTime + "'"); - long guarSize = parserUtil.getDefaultSpaceGuarSize(fsName); - verboseLog("VFS(" + fsName + ").DefaultValues.space.guarSize = '" - + guarSize + "'"); - long totSize = parserUtil.getDefaultSpaceTotSize(fsName); - verboseLog("VFS(" + fsName + ").DefaultValues.space.totSize = '" + totSize - + "'"); - def.setSpaceDefaults(spaceType, lifeTime, guarSize, totSize); - } - - private void setFileDef(String fsName, DefaultValues def) - throws NamespaceException { - - String fileType = parserUtil.getDefaultFileType(fsName); - verboseLog("VFS(" + fsName + ").DefaultValues.file.type = '" + fileType - + "'"); - long lifeTime = parserUtil.getDefaultFileLifeTime(fsName); - verboseLog("VFS(" + fsName + ").DefaultValues.file.lifeTime = '" + lifeTime - + "'"); - def.setFileDefaults(fileType, lifeTime); - } - - // ******************* MAPPING RULE *************************** - - private void buildMapRules() throws NamespaceException { - - int numOfMapRules = parserUtil.getNumberOfMappingRule(); - String ruleName, stfnRoot, mappedFS; - MappingRule mapRule; - - for (int i = 0; i < numOfMapRules; i++) { - ruleName = parserUtil.getMapRuleName(i); - mappedFS = parserUtil.getMapRule_mappedFS(ruleName); - // Adding mapping rule to VFS within vfss; - if (vfss.containsKey(mappedFS)) { - verboseLog("VFS '" + mappedFS + "' pointed by RULE : '" + ruleName - + "' exists."); - stfnRoot = parserUtil.getMapRule_StFNRoot(ruleName); - VirtualFSInterface vfs = (VirtualFSInterface) vfss.get(mappedFS); - mapRule = new MappingRule(ruleName, stfnRoot, vfs/* , mappedFS */); - ((VirtualFS) vfs).addMappingRule(mapRule); - maprules.put(ruleName, mapRule); - } else { - log.error("VFS '" + mappedFS + "' pointed by RULE : '" + ruleName - + "' DOES NOT EXISTS."); - } - } - } - - // ******************* APPROACHABLE RULE *************************** - - private void buildAppRules() throws NamespaceException { - - int numOfAppRules = parserUtil.getNumberOfApproachRule(); - - verboseLog("Number of APP Rule : " + numOfAppRules); - String ruleName, dn, vo_name, relPath, anonymousHttpReadString; - List appFSList; - ApproachableRule appRule; - for (int i = 0; i < numOfAppRules; i++) { - ruleName = parserUtil.getApproachRuleName(i); - verboseLog(" APP rule nr:" + i + " is named : " + ruleName); - - dn = parserUtil.getAppRule_SubjectDN(ruleName); - vo_name = parserUtil.getAppRule_SubjectVO(ruleName); - SubjectRules subjectRules = new SubjectRules(dn, vo_name); - - relPath = parserUtil.getAppRule_RelativePath(ruleName); - - anonymousHttpReadString = parserUtil - .getAppRule_AnonymousHttpRead(ruleName); - if (anonymousHttpReadString != null - && !anonymousHttpReadString.trim().isEmpty()) { - appRule = new ApproachableRule(ruleName, subjectRules, relPath, - Boolean.parseBoolean(anonymousHttpReadString)); - } else { - appRule = new ApproachableRule(ruleName, subjectRules, relPath); - } - - appFSList = parserUtil.getAppRule_AppFS(ruleName); - for (String appFS : appFSList) { - if (vfss.containsKey(appFS)) { - verboseLog("VFS '" + appFS + "' pointed by RULE : '" + ruleName - + "' exists."); - VirtualFSInterface vfs = vfss.get(appFS); - ((VirtualFS) vfs).addApproachableRule(appRule); - appRule.addApproachableVFS(vfs); - } else { - log.error("VFS '" + appFS + "' pointed by RULE : '" + ruleName - + "' DOES NOT EXISTS."); - } - } - apprules.put(ruleName, appRule); - } - } - - /***************************************************************************** - * BUSINESS METHODs - ****************************************************************************/ - - public String getNamespaceVersion() { - - return version; - } - - public List getAllVFS_Roots() { - - Collection elem = vfss.values(); - Vector roots = new Vector(vfss.size()); - Iterator scan = elem.iterator(); - while (scan.hasNext()) { - String root = null; - root = scan.next().getRootPath(); - roots.add(root); - } - return roots; - } - - public Map getMapVFS_Root() { - - Hashtable result = new Hashtable(); - Collection elem = vfss.values(); - Iterator scan = elem.iterator(); - while (scan.hasNext()) { - String root = null; - VirtualFSInterface vfs = scan.next(); - root = vfs.getRootPath(); - result.put(root, vfs); - } - return result; - } - - public List getAllMappingRule_StFNRoots() { - - Collection elem = maprules.values(); - Vector roots = new Vector(maprules.size()); - Iterator scan = elem.iterator(); - String root = null; - while (scan.hasNext()) { - root = scan.next().getStFNRoot(); - roots.add(root); - } - return roots; - } - - public Map getMappingRuleMAP() { - - HashMap map = new HashMap(); - Collection elem = maprules.values(); - Iterator scan = elem.iterator(); - String root = null; - String name = null; - MappingRule rule; - while (scan.hasNext()) { - rule = scan.next(); - root = rule.getStFNRoot(); - name = rule.getRuleName(); - map.put(name, root); - } - return map; - } - - public VirtualFSInterface getVFS(String vfsName) { - - return vfss.get(vfsName); - } - -} +/* + * + * Copyright (c) Istituto Nazionale di Fisica Nucleare (INFN). 2006-2010. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of + * the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. + */ + +package it.grid.storm.namespace.config.xml; + +import it.grid.storm.balancer.BalancingStrategyType; +import it.grid.storm.check.sanity.filesystem.SupportedFSType; +import it.grid.storm.namespace.CapabilityInterface; +import it.grid.storm.namespace.DefaultValuesInterface; +import it.grid.storm.namespace.NamespaceDirector; +import it.grid.storm.namespace.NamespaceException; +import it.grid.storm.namespace.PropertyInterface; +import it.grid.storm.namespace.VirtualFSInterface; +import it.grid.storm.namespace.config.NamespaceCheck; +import it.grid.storm.namespace.config.NamespaceLoader; +import it.grid.storm.namespace.config.NamespaceParser; +import it.grid.storm.namespace.model.ACLEntry; +import it.grid.storm.namespace.model.ApproachableRule; +import it.grid.storm.namespace.model.Authority; +import it.grid.storm.namespace.model.Capability; +import it.grid.storm.namespace.model.DefaultValues; +import it.grid.storm.namespace.model.MappingRule; +import it.grid.storm.namespace.model.PermissionException; +import it.grid.storm.namespace.model.PoolMember; +import it.grid.storm.namespace.model.Property; +import it.grid.storm.namespace.model.Property.SizeUnitType; +import it.grid.storm.namespace.model.Protocol; +import it.grid.storm.namespace.model.ProtocolPool; +import it.grid.storm.namespace.model.Quota; +import it.grid.storm.namespace.model.QuotaType; +import it.grid.storm.namespace.model.SAAuthzType; +import it.grid.storm.namespace.model.StorageClassType; +import it.grid.storm.namespace.model.SubjectRules; +import it.grid.storm.namespace.model.TransportProtocol; +import it.grid.storm.namespace.model.VirtualFS; +import it.grid.storm.space.SpaceHelper; +import it.grid.storm.space.gpfsquota.GPFSFilesetQuotaInfo; +import it.grid.storm.space.gpfsquota.GetGPFSFilesetQuotaInfoCommand; +import it.grid.storm.srm.types.TSizeInBytes; +import it.grid.storm.srm.types.TSpaceToken; +import it.grid.storm.util.GPFSSizeHelper; + +import java.util.ArrayList; +import java.util.Collection; +import java.util.HashMap; +import java.util.Iterator; +import java.util.List; +import java.util.Map; +import java.util.Map.Entry; +import java.util.Observable; +import java.util.Observer; +import java.util.concurrent.locks.Lock; +import java.util.concurrent.locks.ReentrantLock; + +import org.apache.commons.configuration.ConfigurationException; +import org.apache.commons.configuration.XMLConfiguration; +import org.slf4j.Logger; + +/** + *

+ * Title: + *

+ * + *

+ * Description: + *

+ * + *

+ * Copyright: Copyright (c) 2006 + *

+ * + *

+ * Company: INFN-CNAF and ICTP/eGrid project + *

+ * + * @author Riccardo Zappi + * @version 1.0 + */ + +public class XMLNamespaceParser implements NamespaceParser, Observer { + + private final Logger log = NamespaceDirector.getLogger(); + + private String version; + private Map vfss; + private Map maprules; + private Map apprules; + + private XMLParserUtil parserUtil; + private final XMLConfiguration configuration; + private XMLNamespaceLoader xmlLoader; + + private final Lock refreshing = new ReentrantLock(); + + /** + * Constructor + * + * @param loader + * NamespaceLoader + */ + public XMLNamespaceParser(NamespaceLoader loader) { + + configuration = (XMLConfiguration) loader.getConfiguration(); + if (loader instanceof XMLNamespaceLoader) { + xmlLoader = (XMLNamespaceLoader) loader; + xmlLoader.setObserver(this); + } else { + log.error("XMLParser initialized with a non-XML Loader"); + } + + parserUtil = new XMLParserUtil(configuration); + + for (Iterator iter = parserUtil.getKeys(); iter.hasNext();) { + log.debug("current item: {}", iter.next()); + } + + vfss = new HashMap<>(); + maprules = new HashMap<>(); + apprules = new HashMap<>(); + + boolean validNamespaceConfiguration = refreshCachedData(); + if (!validNamespaceConfiguration) { + log.error(" ???????????????????????????????????? "); + log.error(" ???? NAMESPACE does not VALID ???? "); + log.error(" ???????????????????????????????????? "); + log.error(" Please see the log. "); + System.exit(0); + } + + } + + public Map getVFSs() { + + return vfss; + } + + public Map getApproachableRules() { + + return apprules; + } + + public Map getMappingRules() { + + return maprules; + } + + public long getLastUpdateTime() { + + return 0L; + } + + public void update(Observable observed, Object arg) { + + log.debug("{} Refreshing Namespace Memory Cache .. ", arg); + + XMLNamespaceLoader loader = (XMLNamespaceLoader) observed; + parserUtil = new XMLParserUtil(loader.getConfiguration()); + + if (loader.schemaValidity) { + refreshCachedData(); + } + + loader.setNotifyManaged(); + + log.debug(" ... Cache Refreshing ended"); + } + + /**************************************************************** + * PRIVATE METHODs + *****************************************************************/ + + private boolean refreshCachedData() { + + boolean result = false; + try { + refreshing.lock(); + configuration.clear(); + configuration.clearTree("filesystems"); + configuration.clearTree("mapping-rules"); + configuration.clearTree("approachable-rules"); + try { + configuration.load(); + log.debug(" ... reading and parsing the namespace configuration from file!"); + } catch (ConfigurationException ex) { + log.error(ex.getMessage(), ex); + } + log.debug("REFRESHING CACHE.."); + // Save the cache content + log.debug(" ..save the cache content before semantic check"); + Map vfssSAVED = vfss; + Map maprulesSAVED = maprules; + Map apprulesSAVED = apprules; + // Refresh the cache content with new values + + log.debug(" ..refresh the cache"); + refreshCache(); + + // Do the checking on Namespace + log.debug(" ..semantic check of namespace"); + NamespaceCheck checker = new NamespaceCheck(vfss, maprules, apprules); + boolean semanticCheck = checker.check(); + + // If there is an error restore old cache content + log.debug("REFRESHING ENDED."); + if (semanticCheck) { + log.debug("Namespace is semantically valid"); + result = true; + } else { + log + .warn("Namespace does not semantically valid!, so no load performed!"); + vfss = vfssSAVED; + maprules = maprulesSAVED; + apprules = apprulesSAVED; + result = false; + } + } finally { + refreshing.unlock(); + } + return result; + } + + private void refreshCache() { + + log + .info(" ############## REFRESHING NAMESPACE CONFIGURATION CACHE : start ###############"); + + /************************** + * Retrieve Version Number + *************************/ + try { + retrieveVersion(); + } catch (NamespaceException ex1) { + log + .warn( + "Namespace configuration does not contain a valid version number.", + ex1); + /** + * @todo Manage this exceptional status! + */ + } + + /************************** + * Building VIRTUAL FS + *************************/ + try { + buildVFSs(); + } catch (ClassNotFoundException ex) { + log + .error("Namespace Configuration ERROR in VFS-DRIVER specification", ex); + /** + * @todo Manage this exceptional status! + */ + } catch (NamespaceException ex) { + log + .error( + "Namespace Configuration ERROR in VFS definition, please check it.", + ex); + /** + * @todo Manage this exceptional status! + */ + } + + /************************** + * Building MAPPING RULES + *************************/ + try { + buildMapRules(); + } catch (NamespaceException ex1) { + log + .error( + "Namespace Configuration ERROR in MAPPING RULES definition, please check it.", + ex1); + /** + * @todo Manage this exceptional status! + */ + } + + /************************** + * Building APPROACHABLE RULES + *************************/ + try { + buildAppRules(); + } catch (NamespaceException ex2) { + log + .error( + "Namespace Configuration ERROR in APPROACHABLE RULES definition, please check it.", + ex2); + /** + * @todo Manage this exceptional status! + */ + } + log + .info(" ############## REFRESHING NAMESPACE CONFIGURATION CACHE : end ###############"); + + handleTotalOnlineSizeFromGPFSQuota(); + // Update SA within Reserved Space Catalog + updateSA(); + } + + private void handleTotalOnlineSizeFromGPFSQuota() { + + for (Entry entry : vfss.entrySet()) { + String storageAreaName = entry.getKey(); + VirtualFSInterface storageArea = entry.getValue(); + if (SupportedFSType.parseFS(storageArea.getFSType()) == SupportedFSType.GPFS) { + Quota quota = storageArea.getCapabilities().getQuota(); + if (quota != null && quota.getEnabled()) { + + GPFSFilesetQuotaInfo quotaInfo = getGPFSQuotaInfo(storageArea); + if (quotaInfo != null) { + updateTotalOnlineSizeFromGPFSQuota(storageAreaName, storageArea, + quotaInfo); + } + } + } + } + } + + private GPFSFilesetQuotaInfo getGPFSQuotaInfo(VirtualFSInterface storageArea) { + + GetGPFSFilesetQuotaInfoCommand cmd = new GetGPFSFilesetQuotaInfoCommand( + storageArea); + + try { + return cmd.call(); + } catch (Throwable t) { + log + .warn( + "Cannot get quota information out of GPFS. Using the TotalOnlineSize in namespace.xml " + + "for Storage Area {}. Reason: {}", storageArea.getAliasName(), + t.getMessage()); + return null; + } + } + + private void updateTotalOnlineSizeFromGPFSQuota(String storageAreaName, + VirtualFSInterface storageArea, GPFSFilesetQuotaInfo quotaInfo) { + + long gpfsTotalOnlineSize = GPFSSizeHelper.getBytesFromKIB(quotaInfo + .getBlockSoftLimit()); + Property newProperties = Property.from(storageArea.getProperties()); + try { + newProperties.setTotalOnlineSize(SizeUnitType.BYTE.getTypeName(), + gpfsTotalOnlineSize); + storageArea.setProperties(newProperties); + log.warn("TotalOnlineSize as specified in namespace.xml will be ignored " + + "since quota is enabled on the GPFS {} Storage Area.", + storageAreaName); + } catch (NamespaceException e) { + log + .warn( + "Cannot get quota information out of GPFS. Using the TotalOnlineSize in namespace.xml " + + "for Storage Area {}.", storageAreaName, e); + } + } + + // ******************* Update SA Catalog *************************** + private void updateSA() { + + TSpaceToken spaceToken = null; + // ReservedSpaceCatalog spaceCatalog = new ReservedSpaceCatalog(); + SpaceHelper spaceHelp = new SpaceHelper(); + log + .debug("Updating Space Catalog with Storage Area defined within NAMESPACE"); + VirtualFS vfs = null; + Iterator scan = vfss.values().iterator(); + while (scan.hasNext()) { + + vfs = (VirtualFS) scan.next(); + String vfsAliasName = vfs.getAliasName(); + log.debug(" Considering VFS : {}", vfsAliasName); + String aliasName = vfs.getSpaceTokenDescription(); + if (aliasName == null) { + // Found a VFS without the optional element Space Token Description + log.debug("XMLNamespaceParser.UpdateSA() : Found a VFS ('{}') without space-token-description. " + + "Skipping the Update of SA", vfsAliasName); + } else { + TSizeInBytes onlineSize = vfs.getProperties().getTotalOnlineSize(); + String spaceFileName = vfs.getRootPath(); + spaceToken = spaceHelp.createVOSA_Token(aliasName, onlineSize, + spaceFileName); + vfs.setSpaceToken(spaceToken); + + log.debug(" Updating SA ('{}'), token:'{}', onlineSize:'{}', spaceFileName:'{}'", + aliasName, spaceToken, onlineSize, spaceFileName); + } + + } + spaceHelp.purgeOldVOSA_token(); + log.debug("Updating Space Catalog... DONE!!"); + + } + + // ******************* VERSION NUMBER *************************** + private void retrieveVersion() throws NamespaceException { + + version = parserUtil.getNamespaceVersion(); + log.debug(" ==== NAMESPACE VERSION : '{}' ====", version); + } + + // ******************* VIRTUAL FS *************************** + + private void buildVFSs() throws ClassNotFoundException, NamespaceException { + + int nrOfVFS = 0; + + nrOfVFS = parserUtil.getNumberOfFS(); + // For each VFS within configuration build VFS class instance + VirtualFS vfs; + String spaceTokenDescription = null; + StorageClassType storageClass; + String root = null; + String name; + String fsType; + Class driver; + String storageAreaAuthz; + PropertyInterface prop; + CapabilityInterface cap; + DefaultValuesInterface defValues; + SAAuthzType saAuthzType; + + for (int i = 0; i < nrOfVFS; i++) { + // Building VFS + vfs = new VirtualFS(); + + name = parserUtil.getFSName(i); + vfs.setAliasName(name); + log.debug("VFS({}).name = '{}'", i, name); + + fsType = parserUtil.getFSType(name); + vfs.setFSType(fsType); + log.debug("VFS({}).fs_type = '{}'", name, fsType); + + spaceTokenDescription = parserUtil.getFSSpaceTokenDescription(name); + vfs.setSpaceTokenDescription(spaceTokenDescription); + log.debug("VFS({}).space-token-description = '{}'", name, spaceTokenDescription); + + storageClass = StorageClassType.getStorageClassType(parserUtil + .getStorageClass(name)); + vfs.setStorageClassType(storageClass); + log.debug("VFS({}).storage-class = '{}'", name, storageClass); + + root = parserUtil.getFSRoot(name); + vfs.setRoot(root); + log.debug("VFS({}).root = '{}'", name, root); + + driver = Class.forName(parserUtil.getFSDriver(name)); + vfs.setFSDriver(driver); + log.debug("VFS({}).fsDriver [CLASS Name] = '{}'", name, driver.getName()); + + driver = Class.forName(parserUtil.getSpaceDriver(name)); + vfs.setSpaceSystemDriver(driver); + log.debug("VFS({}).spaceDriver [CLASS Name] = '{}'", name, driver.getName()); + + saAuthzType = parserUtil.getStorageAreaAuthzType(name); + vfs.setSAAuthzType(saAuthzType); + log.debug("VFS({}).storage-area-authz.TYPE = '{}'", name, saAuthzType); + + storageAreaAuthz = parserUtil.getStorageAreaAuthz(name, saAuthzType); + vfs.setSAAuthzSource(storageAreaAuthz); + log.debug("VFS({}).storage-area-authz = '{}'", name, storageAreaAuthz); + + prop = buildProperties(name); + vfs.setProperties(prop); + + cap = buildCapabilities(name); + vfs.setCapabilities(cap); + + defValues = buildDefaultValues(name); + vfs.setDefaultValues(defValues); + + // Adding VFS + synchronized (this) { + vfss.remove(name); + vfss.put(name, vfs); + } + } + } + + // ******************* PROPERTY *************************** + private PropertyInterface buildProperties(String fsName) + throws NamespaceException { + + Property prop = new Property(); + + String accessLatency = parserUtil.getAccessLatencyType(fsName); + prop.setAccessLatency(accessLatency); + log.debug("VFS({}).Properties.AccessLatency = '{}'", fsName, accessLatency); + + String expirationMode = parserUtil.getExpirationModeType(fsName); + prop.setExpirationMode(expirationMode); + log.debug("VFS({}).Properties.ExpirationMode = '{}'", fsName, expirationMode); + + String retentionPolicy = parserUtil.getRetentionPolicyType(fsName); + prop.setRetentionPolicy(retentionPolicy); + log.debug("VFS({}).Properties.RetentionPolicy = '{}'", fsName, retentionPolicy); + + String unitType = parserUtil.getNearlineSpaceUnitType(fsName); + long nearLineSize = parserUtil.getNearlineSpaceSize(fsName); + prop.setTotalNearlineSize(unitType, nearLineSize); + log.debug("VFS({}).Properties.NearlineSpaceSize = '{} {}'", fsName, nearLineSize, unitType); + + unitType = parserUtil.getOnlineSpaceUnitType(fsName); + long onlineSize = parserUtil.getOnlineSpaceSize(fsName); + prop.setTotalOnlineSize(unitType, onlineSize); + log.debug("VFS({}).Properties.OnlineSpaceSize = '{} {}'", fsName, onlineSize, unitType); + + boolean hasLimitedSize = parserUtil.getOnlineSpaceLimitedSize(fsName); + prop.setLimitedSize(hasLimitedSize); + log.debug("VFS({}).Properties.OnlineSpaceLimitedSize = '{}'", fsName, hasLimitedSize); + + return prop; + } + + // ******************* CAPABILITY *************************** + + private CapabilityInterface buildCapabilities(String fsName) + throws NamespaceException { + + /** + * ACL MODE ELEMENT + */ + String aclMode = parserUtil.getACLMode(fsName); + Capability cap = new Capability(aclMode); + log.debug("VFS({}).Capabilities.aclMode = '{}'", fsName, aclMode); + + /** + * DEFAULT ACL + */ + boolean defaultACLDefined = parserUtil.getDefaultACLDefined(fsName); + log.debug("VFS({}).Capabilities.defaultACL [Defined?] = {}", fsName, defaultACLDefined); + if (defaultACLDefined) { + int nrACLEntries = parserUtil.getNumberOfACL(fsName); + String groupName = null; + String filePermString = null; + ACLEntry aclEntry = null; + for (int entryNumber = 0; entryNumber < nrACLEntries; entryNumber++) { + groupName = parserUtil.getGroupName(fsName, entryNumber); + filePermString = parserUtil.getPermissionString(fsName, entryNumber); + try { + aclEntry = new ACLEntry(groupName, filePermString); + cap.addACLEntry(aclEntry); + } catch (PermissionException permEx) { + log.error("Namespace XML Parser -- ERROR -- : {}", permEx.getMessage()); + } + } + log.debug("VFS({}).Capabilities.defaultACL = {}", fsName, cap.getDefaultACL()); + } + + /** + * QUOTA ELEMENT + */ + boolean quotaDefined = parserUtil.getQuotaDefined(fsName); + Quota quota = null; + if (quotaDefined) { + boolean quotaEnabled = parserUtil.getQuotaEnabled(fsName); + String device = parserUtil.getQuotaDevice(fsName); + + QuotaType quotaType; + String quotaValue = null; + + if (parserUtil.getQuotaFilesetDefined(fsName)) { + quotaType = QuotaType.buildQuotaType(QuotaType.FILESET); + quotaValue = parserUtil.getQuotaFileset(fsName); + } else { + if (parserUtil.getQuotaGroupIDDefined(fsName)) { + quotaType = QuotaType.buildQuotaType(QuotaType.GRP); + quotaValue = parserUtil.getQuotaGroupID(fsName); + } else { + if (parserUtil.getQuotaUserIDDefined(fsName)) { + quotaType = QuotaType.buildQuotaType(QuotaType.USR); + quotaValue = parserUtil.getQuotaUserID(fsName); + } else { + quotaType = QuotaType.buildQuotaType(QuotaType.UNKNOWN); + quotaValue = "unknown"; + } + } + } + + quotaType.setValue(quotaValue); + quota = new Quota(quotaEnabled, device, quotaType); + + } else { + quota = new Quota(); + } + cap.setQuota(quota); + + log.debug("VFS({}).Capabilities.quota = '{}'", fsName, quota); + + /** + * TRANSFER PROTOCOL + */ + int nrProtocols = parserUtil.getNumberOfProt(fsName); + Protocol protocol; + Authority service; + TransportProtocol transportProt; + int protocolIndex; + String serviceHostName; + String servicePortValue; + String schema; + String name; + for (int protCounter = 0; protCounter < nrProtocols; protCounter++) { + protocolIndex = parserUtil.getProtId(fsName, protCounter); + name = parserUtil.getProtName(fsName, protCounter); + schema = parserUtil.getProtSchema(fsName, protCounter); + protocol = Protocol.getProtocol(schema); + protocol.setProtocolServiceName(name); + serviceHostName = parserUtil.getProtHost(fsName, protCounter); + servicePortValue = parserUtil.getProtPort(fsName, protCounter); + int portIntValue = -1; + service = null; + if (servicePortValue != null) { + try { + portIntValue = Integer.parseInt(servicePortValue); + service = new Authority(serviceHostName, portIntValue); + // log.debug("SERVICE PORT: "+service); + } catch (NumberFormatException nfe) { + log + .warn("to evaluate the environmental variable " + servicePortValue); + } + } else { + service = new Authority(serviceHostName); + // log.debug("SERVICE : "+service); + } + transportProt = new TransportProtocol(protocol, service); + transportProt.setProtocolID(protocolIndex); // 1.4.0 + log.debug("VFS({}).Capabilities.protocol({}) = '{}'", fsName, protCounter, transportProt); + cap.addTransportProtocolByScheme(protocol, transportProt); + cap.addTransportProtocol(transportProt); + if (protocolIndex != -1) { + cap.addTransportProtocolByID(protocolIndex, transportProt); + } + + } + + /** + * PROTOCOL POOL + */ + int nrPools = parserUtil.getNumberOfPool(fsName); + if (nrPools > 0) { + + for (int poolCounter = 0; poolCounter < nrPools; poolCounter++) { + BalancingStrategyType balanceStrategy = BalancingStrategyType + .getByValue(parserUtil.getBalancerStrategy(fsName, poolCounter)); + ArrayList poolMembers = new ArrayList<>(); + int nrMembers = parserUtil.getNumberOfPoolMembers(fsName, poolCounter); + for (int i = 0; i < nrMembers; i++) { + int protIndex = parserUtil.getMemberID(fsName, poolCounter, i); + TransportProtocol tProtMember = cap.getProtocolByID(protIndex); + if (tProtMember != null) { + PoolMember poolMember; + if (balanceStrategy.requireWeight()) { + int memberWeight = parserUtil.getMemberWeight(fsName, + poolCounter, i); + poolMember = new PoolMember(protIndex, tProtMember, memberWeight); + } else { + poolMember = new PoolMember(protIndex, tProtMember); + } + poolMembers.add(poolMember); + } else { // member pointed out doesn't exist!! + String errorMessage = String.format("POOL Building: Protocol with index %d does not exists in the VFS : %s", protIndex, fsName); + log.error(errorMessage); + throw new NamespaceException(errorMessage); + } + } + Protocol pooProtocol = poolMembers.get(0).getMemberProtocol() + .getProtocol(); + verifyPoolIsValid(poolMembers); + log.debug("Defined pool for protocol {} with size {}", pooProtocol, poolMembers.size()); + cap.addProtocolPoolBySchema(pooProtocol, new ProtocolPool( + balanceStrategy, poolMembers)); + log.debug("PROTOCOL POOL: {}", cap.getPoolByScheme(pooProtocol)); + } + } else { + log.debug("Pool is not defined in VFS {}", fsName); + } + + return cap; + } + + /** + * @param poolMembers + * @throws NamespaceException + */ + private void verifyPoolIsValid(ArrayList poolMembers) + throws NamespaceException { + + if (poolMembers.isEmpty()) { + throw new NamespaceException("POOL Defined is EMPTY!"); + } + Protocol prot = poolMembers.get(0).getMemberProtocol().getProtocol(); + for (PoolMember member : poolMembers) { + if (!(member.getMemberProtocol().getProtocol().equals(prot))) { + throw new NamespaceException( + "Defined Pool is NOT HOMOGENEOUS! Protocols " + prot.toString() + + " and " + member.toString() + " differs"); + } + } + } + + // ******************* DEFAULT VALUES *************************** + + private DefaultValuesInterface buildDefaultValues(String fsName) + throws NamespaceException { + + DefaultValues def = new DefaultValues(); + if (parserUtil.isDefaultElementPresent(fsName)) { + setSpaceDef(fsName, def); + setFileDef(fsName, def); + } else { // Produce Default Values with default values :o ! + log.debug("VFS({}).DefaultValues is ABSENT. Using DEFAULT values.", fsName); + } + return def; + } + + private void setSpaceDef(String fsName, DefaultValues def) + throws NamespaceException { + + String spaceType = parserUtil.getDefaultSpaceType(fsName); + log.debug("VFS({}).DefaultValues.space.type = '{}'", fsName, spaceType); + long lifeTime = parserUtil.getDefaultSpaceLifeTime(fsName); + log.debug("VFS({}).DefaultValues.space.lifeTime = ''", fsName, lifeTime); + long guarSize = parserUtil.getDefaultSpaceGuarSize(fsName); + log.debug("VFS({}).DefaultValues.space.guarSize = '{}'", fsName, guarSize); + long totSize = parserUtil.getDefaultSpaceTotSize(fsName); + log.debug("VFS({}).DefaultValues.space.totSize = '{}'", fsName, totSize); + def.setSpaceDefaults(spaceType, lifeTime, guarSize, totSize); + } + + private void setFileDef(String fsName, DefaultValues def) + throws NamespaceException { + + String fileType = parserUtil.getDefaultFileType(fsName); + log.debug("VFS({}).DefaultValues.file.type = '{}'", fsName, fileType); + long lifeTime = parserUtil.getDefaultFileLifeTime(fsName); + log.debug("VFS({}).DefaultValues.file.lifeTime = '{}'", fsName, lifeTime); + def.setFileDefaults(fileType, lifeTime); + } + + // ******************* MAPPING RULE *************************** + + private void buildMapRules() throws NamespaceException { + + int numOfMapRules = parserUtil.getNumberOfMappingRule(); + String ruleName; + String stfnRoot; + String mappedFS; + MappingRule mapRule; + + for (int i = 0; i < numOfMapRules; i++) { + ruleName = parserUtil.getMapRuleName(i); + mappedFS = parserUtil.getMapRule_mappedFS(ruleName); + // Adding mapping rule to VFS within vfss; + if (vfss.containsKey(mappedFS)) { + log.debug("VFS '{}' pointed by RULE : '{}' exists.", mappedFS, ruleName); + stfnRoot = parserUtil.getMapRule_StFNRoot(ruleName); + VirtualFSInterface vfs = vfss.get(mappedFS); + mapRule = new MappingRule(ruleName, stfnRoot, vfs); + ((VirtualFS) vfs).addMappingRule(mapRule); + maprules.put(ruleName, mapRule); + } else { + log.error("VFS '{}' pointed by RULE : '{}' DOES NOT EXISTS.", mappedFS, ruleName); + } + } + } + + // ******************* APPROACHABLE RULE *************************** + + private void buildAppRules() throws NamespaceException { + + int numOfAppRules = parserUtil.getNumberOfApproachRule(); + + String ruleName; + String dn; + String vo_name; + String relPath; + String anonymousHttpReadString; + List appFSList; + ApproachableRule appRule; + + log.debug("Number of APP Rule : {}", numOfAppRules); + + + for (int i = 0; i < numOfAppRules; i++) { + ruleName = parserUtil.getApproachRuleName(i); + log.debug(" APP rule nr: {} is named : {}", i, ruleName); + + dn = parserUtil.getAppRule_SubjectDN(ruleName); + vo_name = parserUtil.getAppRule_SubjectVO(ruleName); + SubjectRules subjectRules = new SubjectRules(dn, vo_name); + + relPath = parserUtil.getAppRule_RelativePath(ruleName); + + anonymousHttpReadString = parserUtil + .getAppRule_AnonymousHttpRead(ruleName); + if (anonymousHttpReadString != null + && !anonymousHttpReadString.trim().isEmpty()) { + appRule = new ApproachableRule(ruleName, subjectRules, relPath, + Boolean.parseBoolean(anonymousHttpReadString)); + } else { + appRule = new ApproachableRule(ruleName, subjectRules, relPath); + } + + appFSList = parserUtil.getAppRule_AppFS(ruleName); + for (String appFS : appFSList) { + if (vfss.containsKey(appFS)) { + log.debug("VFS '{}' pointed by RULE : '{}' exists.", appFS, ruleName); + VirtualFSInterface vfs = vfss.get(appFS); + ((VirtualFS) vfs).addApproachableRule(appRule); + appRule.addApproachableVFS(vfs); + } else { + log.error("VFS '{}' pointed by RULE : '{}' DOES NOT EXISTS.", appFS, ruleName); + } + } + apprules.put(ruleName, appRule); + } + } + + /***************************************************************************** + * BUSINESS METHODs + ****************************************************************************/ + + public String getNamespaceVersion() { + + return version; + } + + public List getAllVFS_Roots() { + + Collection elem = vfss.values(); + List roots = new ArrayList<>(vfss.size()); + Iterator scan = elem.iterator(); + while (scan.hasNext()) { + String root = null; + root = scan.next().getRootPath(); + roots.add(root); + } + return roots; + } + + public Map getMapVFS_Root() { + + Map result = new HashMap<>(); + Collection elem = vfss.values(); + Iterator scan = elem.iterator(); + while (scan.hasNext()) { + String root = null; + VirtualFSInterface vfs = scan.next(); + root = vfs.getRootPath(); + result.put(root, vfs); + } + return result; + } + + public List getAllMappingRule_StFNRoots() { + + Collection elem = maprules.values(); + List roots = new ArrayList<>(maprules.size()); + Iterator scan = elem.iterator(); + String root = null; + while (scan.hasNext()) { + root = scan.next().getStFNRoot(); + roots.add(root); + } + return roots; + } + + public Map getMappingRuleMAP() { + + Map map = new HashMap<>(); + Collection elem = maprules.values(); + Iterator scan = elem.iterator(); + String root = null; + String name = null; + MappingRule rule; + while (scan.hasNext()) { + rule = scan.next(); + root = rule.getStFNRoot(); + name = rule.getRuleName(); + map.put(name, root); + } + return map; + } + + public VirtualFSInterface getVFS(String vfsName) { + + return vfss.get(vfsName); + } + +} diff --git a/src/main/java/it/grid/storm/namespace/config/xml/XMLParserUtil.java b/src/main/java/it/grid/storm/namespace/config/xml/XMLParserUtil.java index 3d56ec59..c1d34daf 100644 --- a/src/main/java/it/grid/storm/namespace/config/xml/XMLParserUtil.java +++ b/src/main/java/it/grid/storm/namespace/config/xml/XMLParserUtil.java @@ -452,7 +452,7 @@ public String getAppRule_SubjectVO(String nameOfAppRule) XMLConst.APP_VO_NAME)); } - public List getAppRule_AppFS(String nameOfAppRule) throws NamespaceException { + public List getAppRule_AppFS(String nameOfAppRule) throws NamespaceException { int numOfAppRule = retrieveNumberByName(nameOfAppRule, XMLConst.APP_RULE_BY_NAME); diff --git a/src/main/java/it/grid/storm/namespace/model/VirtualFS.java b/src/main/java/it/grid/storm/namespace/model/VirtualFS.java index 1188ded8..212d309c 100644 --- a/src/main/java/it/grid/storm/namespace/model/VirtualFS.java +++ b/src/main/java/it/grid/storm/namespace/model/VirtualFS.java @@ -112,12 +112,6 @@ public class VirtualFS implements VirtualFSInterface { // For debug purpose only public long creationTime = System.currentTimeMillis(); - public boolean testingMode = false; - - public VirtualFS(boolean testingMode) { - - this.testingMode = testingMode; - } /***************************************************************************** * BUILDING METHODs @@ -137,11 +131,8 @@ public void setFSType(String type) { public void setFSDriver(Class fsDriver) throws NamespaceException { this.fsDriver = fsDriver; - if (testingMode) { - this.genericFS = null; - } else { - this.genericFS = makeFSInstance(); - } + this.genericFS = makeFSInstance(); + fsWrapper = RandomWaitFilesystemAdapter.maybeWrapFilesystem(fsWrapper); this.fsWrapper = new MetricsFilesystemAdapter( new Filesystem(getFSDriverInstance()), @@ -327,7 +318,7 @@ public Class getFSDriver() throws NamespaceException { public genericfs getFSDriverInstance() throws NamespaceException { - if ((this.genericFS == null) && (!testingMode)) { + if (this.genericFS == null) { this.genericFS = makeFSInstance(); } return this.genericFS; @@ -435,7 +426,7 @@ public Class getSpaceSystemDriver() throws NamespaceException { public SpaceSystem getSpaceSystemDriverInstance() throws NamespaceException { - if ((this.spaceSystem == null) && (!testingMode)) { + if (this.spaceSystem == null) { this.spaceSystem = makeSpaceSystemInstance(); } return this.spaceSystem; diff --git a/src/main/java/it/grid/storm/scheduler/ChunkTask.java b/src/main/java/it/grid/storm/scheduler/ChunkTask.java index 372ade56..548a7df3 100644 --- a/src/main/java/it/grid/storm/scheduler/ChunkTask.java +++ b/src/main/java/it/grid/storm/scheduler/ChunkTask.java @@ -18,7 +18,6 @@ package it.grid.storm.scheduler; import it.grid.storm.asynch.BoL; -import it.grid.storm.asynch.Copy; import it.grid.storm.asynch.PtG; import it.grid.storm.asynch.PtP; import it.grid.storm.asynch.Request; @@ -183,9 +182,6 @@ private OperationType buildOperationType() { if (todo instanceof PtG) { return OperationType.PTG; } - if (todo instanceof Copy) { - return OperationType.COPY; - } if (todo instanceof BoL) { return OperationType.BOL; } diff --git a/src/test/java/it/grid/storm/tape/recalltable/resources/TaskResourceTest.java b/src/test/java/it/grid/storm/tape/recalltable/resources/TaskResourceTest.java index cf3597b9..5aefc6ad 100644 --- a/src/test/java/it/grid/storm/tape/recalltable/resources/TaskResourceTest.java +++ b/src/test/java/it/grid/storm/tape/recalltable/resources/TaskResourceTest.java @@ -1,5 +1,6 @@ package it.grid.storm.tape.recalltable.resources; +import static it.grid.storm.config.Configuration.CONFIG_FILE_PATH; import static it.grid.storm.tape.recalltable.resources.TaskInsertRequest.MAX_RETRY_ATTEMPTS; import static javax.ws.rs.core.Response.Status.BAD_REQUEST; import static javax.ws.rs.core.Response.Status.CREATED; @@ -64,6 +65,10 @@ public class TaskResourceTest { private TapeRecallCatalog RECALL_CATALOG = getTapeRecallCatalogInsertSuccess(groupTaskID); private TapeRecallCatalog BROKEN_RECALL_CATALOG = getTapeRecallCatalogInsertError(); + static { + System.setProperty(CONFIG_FILE_PATH, "storm.properties"); + } + private TapeRecallCatalog getTapeRecallCatalogInsertSuccess(UUID groupTaskId) { TapeRecallCatalog catalog = Mockito.mock(TapeRecallCatalog.class); diff --git a/src/test/resources/storm.properties b/src/test/resources/storm.properties new file mode 100644 index 00000000..8a617830 --- /dev/null +++ b/src/test/resources/storm.properties @@ -0,0 +1,64 @@ +storm.service.FE-public.hostname = storm.example +storm.service.FE-list.hostnames = storm.example +storm.service.port = 8444 +storm.service.SURL.endpoint = srm://storm.example:8444/srm/managerv2 +storm.service.SURL.default-ports = 8444 +storm.service.request-db.host = storm.example +storm.service.request-db.username = storm +storm.service.request-db.passwd = password +directory.automatic-creation = false +directory.writeperm = false +pinLifetime.default=259200 +pinLifetime.maximum=1814400 +extraslashes.file= +extraslashes.rfio= +extraslashes.gsiftp=/ +extraslashes.root= +fileLifetime.default=259200 +default.overwrite = A +default.storagetype = P +persistence.internal-db.connection-pool = true +persistence.internal-db.connection-pool.maxActive = 50 +persistence.internal-db.connection-pool.maxWait = 50 +scheduler.serial=false +scheduler.crusher.workerCorePoolSize=10 +scheduler.crusher.workerMaxPoolSize=50 +scheduler.crusher.queueSize=2000 +scheduler.chunksched.ptp.workerCorePoolSize=50 +scheduler.chunksched.ptp.workerMaxPoolSize=200 +scheduler.chunksched.ptp.queueSize=1000 +scheduler.chunksched.ptg.workerCorePoolSize=50 +scheduler.chunksched.ptg.workerMaxPoolSize=200 +scheduler.chunksched.ptg.queueSize=2000 +scheduler.chunksched.bol.workerCorePoolSize=50 +scheduler.chunksched.bol.workerMaxPoolSize=200 +scheduler.chunksched.bol.queueSize=2000 +scheduler.chunksched.copy.workerCorePoolSize=10 +scheduler.chunksched.copy.workerMaxPoolSize=50 +scheduler.chunksched.copy.queueSize=500 +asynch.db.ReconnectPeriod=18000 +asynch.db.DelayPeriod=30 +asynch.PickingInitialDelay=1 +asynch.PickingTimeInterval=2 +asynch.PickingMaxBatchSize=100 +synchcall.directoryManager.maxLsEntry=2000 +storm.rest.services.port=9998 +storm.rest.services.maxthreads=100 +storm.rest.services.max_queue_size=1000 +synchcall.xmlrpc.unsecureServerPort=8080 +synchcall.xmlrpc.maxthread=256 +synchcall.xmlrpc.max_queue_size=1000 +synchcall.xmlrpc.security.enabled=true +synchcall.xmlrpc.security.token= +gc.pinnedfiles.cleaning.delay = 10 +gc.pinnedfiles.cleaning.interval = 300 +tape.recalltable.service.param.retry-value=retry-value +tape.recalltable.service.param.status=status +tape.recalltable.service.param.takeover=first +purging=true +purge.interval=600 +purge.size=800 +expired.request.time=21600 +transit.interval = 300 +transit.delay = 10 +ptg.skip-acl-setup = false \ No newline at end of file