Example usage for org.apache.commons.lang.builder ToStringBuilder reflectionToString

List of usage examples for org.apache.commons.lang.builder ToStringBuilder reflectionToString

Introduction

In this page you can find the example usage for org.apache.commons.lang.builder ToStringBuilder reflectionToString.

Prototype

public static String reflectionToString(Object object, ToStringStyle style) 

Source Link

Document

Forwards to ReflectionToStringBuilder.

Usage

From source file:com.healthmarketscience.jackcess.impl.office.EncryptionHeader.java

@Override
public String toString() {
    return ToStringBuilder.reflectionToString(this, CustomToStringStyle.VALUE_INSTANCE);
}

From source file:com.gemini.provision.loadbalancer.openstack.LoadBalancerProviderOpenStackImpl.java

@Override
public List<GeminiLoadBalancerPool> listAllPools(GeminiTenant tenant, GeminiEnvironment env) {
    List<GeminiLoadBalancerPool> lbPools = Collections.synchronizedList(new ArrayList());

    //authenticate the session with the OpenStack installation
    OSClient os = OSFactory.builder().endpoint(env.getEndPoint())
            .credentials(env.getAdminUserName(), env.getAdminPassword()).tenantName(tenant.getName())
            .authenticate();/*w  w w.ja  v  a  2  s.c  om*/
    if (os == null) {
        Logger.error("Failed to authenticate Tenant: {}",
                ToStringBuilder.reflectionToString(tenant, ToStringStyle.MULTI_LINE_STYLE));
        return null;
    }
    List<? extends LbPool> osLbPools = os.networking().loadbalancers().lbPool().list();

    osLbPools.stream().filter(lbPool -> lbPool != null).forEach(lbPool -> {
        GeminiLoadBalancerPool loadBalancerPool = new GeminiLoadBalancerPool();
        loadBalancerPool.setCloudID(lbPool.getId());
        loadBalancerPool.setName(lbPool.getName());
        loadBalancerPool.setDescription(lbPool.getDescription());
        //TODO get the VpId from the pool
        loadBalancerPool.setVipID(lbPool.getVipId());
        loadBalancerPool.setProtocol(Protocol.fromString(lbPool.getProtocol()));
        loadBalancerPool.setLoadBalancerAlgorithm(LoadBalancerAlgorithm.fromString(lbPool.getLbMethod()));
        //TODO set the pool member
        loadBalancerPool.setAdminState(lbPool.isAdminStateUp() ? AdminState.ADMIN_UP : AdminState.ADMIN_DOWN);

        GeminiSubnet subnet = env.getApplications().stream().map(GeminiApplication::getNetworks)
                .flatMap(List::stream).map(GeminiNetwork::getSubnets).flatMap(List::stream)
                .filter(s -> s.getCloudID().equals(lbPool.getId())).findFirst().get();
        if (subnet == null) {
            Logger.info(
                    "Load Balancer cloud ID {} references a subnet not available in environment {}  Subnet ID: {}",
                    lbPool.getId(), env.getName(), lbPool.getSubnetId());
        } else {
            loadBalancerPool.setGeminiSubnet(subnet);
        }
        lbPools.add(loadBalancerPool);
    });

    return lbPools;
}

From source file:edu.harvard.iq.dvn.ingest.dsb.impl.DvnRGraphServiceImpl.java

/** *************************************************************
 * initialize the RServe connection and load the graph;
 * keep the open connection.//from   w ww  . j a va 2 s .c  om
 *
 * @param sro    a DvnRJobRequest object that contains various parameters
 * @return    a Map that contains various information about the results
 */

public Map<String, String> initializeConnection(DvnRJobRequest sro) throws DvnRGraphException {

    // set the return object
    Map<String, String> result = new HashMap<String, String>();

    try {

        if (sro != null) {
            dbgLog.fine(
                    "sro dump:\n" + ToStringBuilder.reflectionToString(sro, ToStringStyle.MULTI_LINE_STYLE));
        } else {
            throw new DvnRGraphException("init: NULL R JOB OBJECT");
        }

        String SavedRworkSpace = null;
        String CachedRworkSpace = sro.getCachedRworkSpace();

        Map<String, Object> SubsetParameters = sro.getParametersForGraphSubset();

        if (SubsetParameters != null) {
            SavedRworkSpace = (String) SubsetParameters.get(SAVED_RWORK_SPACE);
        }

        if (SavedRworkSpace != null) {
            myConnection = RConnectionPool.securePooledConnection(SavedRworkSpace, null, true, 0);
            RDataFileName = SavedRworkSpace;

        } else if (CachedRworkSpace != null) {
            myConnection = RConnectionPool.securePooledConnection(RDataFileName, CachedRworkSpace, false, 0);
        } else {
            throw new DvnRGraphException("Initialize method called without either local or remote RData file");
        }

        if (myConnection == 0) {
            throw new DvnRGraphException("failed to obtain an R connection");
        } else {
            DvnRConnection drc = RConnectionPool.getConnection(myConnection);
            if (drc == null) {
                throw new DvnRGraphException("failed to obtain an R connection");
            } else {
                // set the connection time stamp: 
                Date now = new Date();
                drc.setLastQueryTime(now.getTime());
                drc.unlockConnection();
            }
        }

        dbgLog.info("Initialize: obtained connection " + myConnection);

        result.put(SAVED_RWORK_SPACE, RDataFileName);

        result.put("dsbHost", RSERVE_HOST);
        result.put("dsbPort", DSB_HOST_PORT);
        result.put("IdSuffix", IdSuffix);
    } catch (DvnRGraphException dre) {
        throw dre;
    }

    return result;

}

From source file:com.gemini.provision.security.openstack.SecurityProviderOpenStackImpl.java

@Override
public List<GeminiSecurityGroupRule> listSecurityGroupRules(GeminiTenant tenant, GeminiEnvironment env,
        GeminiSecurityGroup securityGroup) {
    List<GeminiSecurityGroupRule> listSecGrpRules = Collections.synchronizedList(new ArrayList());

    //authenticate the session with the OpenStack installation
    OSClient os = OSFactory.builder().endpoint(env.getEndPoint())
            .credentials(env.getAdminUserName(), env.getAdminPassword()).tenantName(tenant.getName())
            .authenticate();/*  w  ww .  j a va  2s. c o m*/
    if (os == null) {
        Logger.error("Failed to authenticate Tenant: {}",
                ToStringBuilder.reflectionToString(tenant, ToStringStyle.MULTI_LINE_STYLE));
        return null;
    }

    List<? extends SecurityGroupRule> osSecGrpRules = null;
    try {
        osSecGrpRules = os.networking().securityrule().list();
    } catch (NullPointerException | ClientResponseException ex) {
        Logger.error("Failed to get rules for tenant: {} env: {} and security Group {}", tenant.getName(),
                env.getName(), securityGroup.getName());
        return null;
    }

    osSecGrpRules.stream().filter(osSecGrpRule -> osSecGrpRule != null).forEach(osSecGrpRule -> {
        //find the rule in the security group object and add it to list
        GeminiSecurityGroupRule gemSecGrpRule = null;
        try {
            gemSecGrpRule = securityGroup.getSecurityRules().stream()
                    .filter(sr -> sr.getCloudID().equals(osSecGrpRule.getId())) //check cloud id too to ensure the mapping on Gemini is complete
                    .findFirst().get();
        } catch (NoSuchElementException ex) {
            //not an error or even log worthy ... just signifies that the rule
            //on Gemini Side needs to be created
        }
        if (gemSecGrpRule == null) {
            //the rule has not been mapped on the Gemini side, so create it
            gemSecGrpRule = new GeminiSecurityGroupRule();
            gemSecGrpRule.setCloudID(osSecGrpRule.getId());
            gemSecGrpRule.setProvisioned(true);
            gemSecGrpRule.setPortRangeMin(osSecGrpRule.getPortRangeMin());
            gemSecGrpRule.setPortRangeMax(osSecGrpRule.getPortRangeMax());
            gemSecGrpRule.setProtocol(Protocol.fromString(osSecGrpRule.getProtocol()));
            //                gemSecGrpRule.setCidr(osSecGrpRule.getRange().getCidr());
            gemSecGrpRule.setDirection(
                    GeminiSecurityGroupRuleDirection.valueOf(osSecGrpRule.getDirection().toUpperCase()));
            gemSecGrpRule.setRemoteGroupId(osSecGrpRule.getRemoteGroupId());
            gemSecGrpRule.setRemoteIpPrefix(osSecGrpRule.getRemoteIpPrefix());
            gemSecGrpRule.setIpAddressType(IPAddressType.valueOf(osSecGrpRule.getEtherType()));
            gemSecGrpRule.setParent(securityGroup);
            securityGroup.addSecurityRule(gemSecGrpRule);
        }
        listSecGrpRules.add(gemSecGrpRule);
    });

    Logger.debug("Successfully retrieved security groups rules Tenant: {} Env: {} security group {}",
            tenant.getName(), env.getName(), securityGroup.getName());
    return listSecGrpRules;
}

From source file:com.alibaba.otter.shared.common.utils.meta.DdlUtils.java

private static Table readTable(DatabaseMetaDataWrapper metaData, Map<String, Object> values)
        throws SQLException {
    String tableName = (String) values.get("TABLE_NAME");
    Table table = null;//from w w  w .j av a 2s. co  m

    if ((tableName != null) && (tableName.length() > 0)) {
        table = new Table();
        table.setName(tableName);
        table.setType((String) values.get("TABLE_TYPE"));
        table.setCatalog((String) values.get("TABLE_CAT"));
        table.setSchema((String) values.get("TABLE_SCHEM"));
        table.setDescription((String) values.get("REMARKS"));
        table.addColumns(readColumns(metaData, tableName));

        Collection<String> primaryKeys = readPrimaryKeyNames(metaData, tableName);

        for (Object key : primaryKeys) {
            Column col = table.findColumn((String) key, true);

            if (col != null) {
                col.setPrimaryKey(true);
            } else {
                throw new NullPointerException(String.format("%s pk %s is null - %s %s", tableName, key,
                        ToStringBuilder.reflectionToString(metaData, ToStringStyle.SIMPLE_STYLE),
                        ToStringBuilder.reflectionToString(values, ToStringStyle.SIMPLE_STYLE)));
            }
        }
    }

    return table;
}

From source file:com.gemini.provision.network.openstack.NetworkProviderOpenStackImpl.java

@Override
public ProvisioningProviderResponseType createNetwork(GeminiTenant tenant, GeminiEnvironment env,
        GeminiNetwork newNetwork) {/*  ww w .  j  av a  2  s  .com*/
    //authenticate the session with the OpenStack installation
    OSClient os = OSFactory.builder().endpoint(env.getEndPoint())
            .credentials(env.getAdminUserName(), env.getAdminPassword()).tenantName(tenant.getName())
            .authenticate();
    if (os == null) {
        Logger.error("Failed to authenticate Tenant: {}",
                ToStringBuilder.reflectionToString(tenant, ToStringStyle.MULTI_LINE_STYLE));
        return ProvisioningProviderResponseType.CLOUD_AUTH_FAILURE;
    }

    //check to see if this network exists
    List<? extends Network> networks = os.networking().network().list();
    if (networks.stream().anyMatch(n -> n.getName().equals(newNetwork.getName()))) {
        Logger.error("Failed to create network - already exists. Tenant: {} Environment: {} Network: {}",
                tenant.getName(), env.getName(),
                ToStringBuilder.reflectionToString(newNetwork, ToStringStyle.MULTI_LINE_STYLE));
        return ProvisioningProviderResponseType.OBJECT_EXISTS;
    }

    //create the network
    Network network;
    try {
        network = os.networking().network()
                .create(Builders.network().tenantId(tenant.getTenantID()).name(newNetwork.getName()).build());
    } catch (ClientResponseException ex) {
        Logger.error("Cloud exception, failed to create network: status code {} tenant: {}, env: {} network {}",
                ex.getStatusCode(), tenant.getName(), env.getName(), newNetwork.getName());
        return ProvisioningProviderResponseType.CLOUD_EXCEPTION;
    }

    //TODO: Need to get detailed error codes for the call above. Research the StatusCode class
    if (network == null) {
        Logger.error(
                "Failed to create network, failure in Cloud provider. Tenant: {} Environment: {} Network: {}",
                tenant.getName(), env.getName(),
                ToStringBuilder.reflectionToString(newNetwork, ToStringStyle.MULTI_LINE_STYLE));
        return ProvisioningProviderResponseType.CLOUD_FAILURE;
    }

    //copy the cloud ID to the Gemini object as it is required later
    newNetwork.setCloudID(network.getId());

    //now create subnets in network
    newNetwork.getSubnets().stream().forEach(gs -> {
        //create the subnet
        Subnet subnet = null;
        try {
            subnet = os.networking().subnet().create(Builders.subnet().tenantId(tenant.getTenantID())
                    .gateway(InetAddresses.toAddrString(gs.getGateway())).enableDHCP(gs.isEnableDHCP())
                    .ipVersion(gs.getNetworkType() == IPAddressType.IPv6 ? IPVersionType.V6 : IPVersionType.V4)
                    .name(gs.getName()).networkId(newNetwork.getCloudID()).cidr(gs.getCidr()).build());
            gs.setCloudID(subnet.getId());
        } catch (ClientResponseException ex) {
            Logger.error(
                    "Cloud exception, failed to create subnet. status code {} tenant: {} env: {} network: {} subnet: {}",
                    ex.getStatusCode(), tenant.getName(), env.getName(), newNetwork.getName(), gs.getName());
        }

        if (subnet == null) {
            Logger.error("Cloud failure, failed to create subnet. tenant: {} env: {} network: {} subnet: {}",
                    tenant.getName(), env.getName(), newNetwork.getName(), gs.getName());
        }
    });

    Logger.debug("Successfully created network and it's subnets - Tenant: {} Environment: {} Network: {}",
            tenant.getName(), env.getName(),
            ToStringBuilder.reflectionToString(newNetwork, ToStringStyle.MULTI_LINE_STYLE));
    return ProvisioningProviderResponseType.SUCCESS;
}

From source file:com.all.downloader.download.DownloadStatusImpl.java

@Override
public String toString() {
    return ToStringBuilder.reflectionToString(this, ToStringStyle.NO_FIELD_NAMES_STYLE);
}

From source file:edu.harvard.iq.dvn.ingest.dsb.impl.DvnRDataAnalysisServiceImpl.java

/** *************************************************************
 * Execute an R-based dvn statistical analysis request 
 *
 * @param sro    a DvnRJobRequest object that contains various parameters
 * @return    a Map that contains various information about results
 *///from  w ww.j  a v a  2s  .c  om

public Map<String, String> execute(DvnRJobRequest sro) {

    // Step 1. Copy of Rdata file
    // Step 2. Subset Rdata file
    // Step 3. Return the subsetted Rdata file instead of the original

    // set the return object
    Map<String, String> result = new HashMap<String, String>();
    // temporary result
    Map<String, String> tmpResult = new HashMap<String, String>();

    try {
        // Set up an Rserve connection
        dbgLog.info("sro dump:\n" + ToStringBuilder.reflectionToString(sro, ToStringStyle.MULTI_LINE_STYLE));

        dbgLog.fine("RSERVE_USER=" + RSERVE_USER + "[default=rserve]");
        dbgLog.fine("RSERVE_PWD=" + RSERVE_PWD + "[default=rserve]");
        dbgLog.fine("RSERVE_PORT=" + RSERVE_PORT + "[default=6311]");

        RConnection c = new RConnection(RSERVE_HOST, RSERVE_PORT);
        dbgLog.fine("hostname=" + RSERVE_HOST);

        c.login(RSERVE_USER, RSERVE_PWD);
        dbgLog.info("R Version = " + c.eval("R.version$version.string").asString() + "<");
        dbgLog.info("SRO request type: " + sro.getRequestType());

        // check working directories
        // This needs to be done *before* we try to create any files 
        // there!
        setupWorkingDirectories(c);

        // save the data file at the Rserve side
        String infile = sro.getSubsetFileName();

        InputStream inb = new BufferedInputStream(new FileInputStream(infile));

        int bufsize;
        byte[] bffr = new byte[1024];

        RFileOutputStream os = c.createFile(tempFileName);
        while ((bufsize = inb.read(bffr)) != -1) {
            os.write(bffr, 0, bufsize);
        }
        os.close();
        inb.close();

        // save the original data file on the server-side

        // WORKS STARTS HERE
        // os = c.createFile(tempOriginalFileName);

        // Rserve code starts here
        dbgLog.fine("DvnRserveComm: " + "wrkdir=" + wrkdir);
        //dbgLog.fine("DvnRserveComm: "+librarySetup);
        //historyEntry.add(librarySetup);
        //c.voidEval(librarySetup);

        Properties p = System.getProperties();
        String domainRoot = p.getProperty("com.sun.aas.instanceRoot");
        String rFunctionsFileName = domainRoot + "/config/" + DVN_R_DATA_FUNCTIONS;

        dbgLog.fine("Source code for the custom DVN R functions: " + rFunctionsFileName);

        File rFunctionsFile = new File(rFunctionsFileName);
        if (!rFunctionsFile.exists()) {
            throw new IOException("Could not find R source code file " + rFunctionsFileName);
        }

        /* 
         * Send the R code file across:
         */

        inb = new BufferedInputStream(new FileInputStream(rFunctionsFile));

        os = c.createFile(tempRCodeFileName);
        while ((bufsize = inb.read(bffr)) != -1) {
            os.write(bffr, 0, bufsize);
        }
        os.close();
        inb.close();

        /* 
         * And read it in: 
         */

        String newLibrarySetup = "source(\"" + tempRCodeFileName + "\");";
        dbgLog.fine("DvnRserveComm: " + newLibrarySetup);
        historyEntry.add(newLibrarySetup);
        c.voidEval(newLibrarySetup);
        dbgLog.fine("DVN R Code library has been read.");

        // variable type
        /* 
        vartyp <-c(1,1,1)
        */
        // java side
        // int [] jvartyp  = {1,1,1};// = mp.get("vartyp").toArray()
        // int [] jvartyp  = sro.getVariableTypes();
        /*
                    StringBuilder sb = new StringBuilder();
                    for (int i = 0 ; i< jvartyp.length; i++){
        if (i == (jvartyp.length -1)){
            sb.append(String.valueOf(jvartyp[i]));
        } else {
            sb.append(String.valueOf(jvartyp[i])+", ");
        }
                    }
                            
                    // R side
                    historyEntry.add("vartyp<-c(" + sb.toString()+")");
        */

        //c.assign("vartyp", new REXPInteger(jvartyp));
        if ("Download".equals(sro.getRequestType())) {
            /*
             * Note that we want to use the "getVariableTypesWithBoolean method 
             * when the subset is being created for download/conversion; when 
             * we create a SRO object for analysis, we'll still be using 
             * the old getVariableTypes
             * method, that don't recognize Booleans as a distinct class. 
             * So they will be treated simply as numeric categoricals 
             * (factors) with the "TRUE" and "FALSE" labels. But for the purposes
             * of saving the subset in R format, we want to convert these into
             * R "logical" vectors.
             * 
             * TODO: verify what's going to happen to these "logical"
             * variables when we call R package Foreign to convert the 
             * dataset into STATA format. -- L.A. 
             */

            dbgLog.fine("raw variable type=" + sro.getVariableTypesWithBoolean());
            c.assign("vartyp", new REXPInteger(sro.getVariableTypesWithBoolean()));
            String[] tmpt = c.eval("vartyp").asStrings();
            dbgLog.fine("vartyp length=" + tmpt.length + "\t " + StringUtils.join(tmpt, ","));

        } else {
            historyEntry.add("vartyp<-c(" + StringUtils.join(sro.getVariableTypesAsString(), ",") + ")");
            dbgLog.fine("DvnRserveComm: " + "vartyp<-c(" + StringUtils.join(sro.getVariableTypesAsString(), ",")
                    + ")");

            dbgLog.fine("raw variable type=" + sro.getVariableTypes());
            c.assign("vartyp", new REXPInteger(sro.getVariableTypes()));
            String[] tmpt = c.eval("vartyp").asStrings();
            dbgLog.fine(
                    "DvnRserveComm: " + "vartyp length=" + tmpt.length + "\t " + StringUtils.join(tmpt, ","));
        }

        // variable format (date/time)
        /* 
        varFmt<-list();
        c.voidEval("varFmt<-list()");
        */

        Map<String, String> tmpFmt = sro.getVariableFormats();
        dbgLog.fine("DvnRserveComm: " + "tmpFmt=" + tmpFmt);
        if (tmpFmt != null) {
            Set<String> vfkeys = tmpFmt.keySet();
            String[] tmpfk = (String[]) vfkeys.toArray(new String[vfkeys.size()]);
            String[] tmpfv = getValueSet(tmpFmt, tmpfk);
            historyEntry.add("tmpfk<-c(" + StringUtils.join(tmpfk, ", ") + ")");
            dbgLog.fine("DvnRserveComm: " + "tmpfk<-c(" + StringUtils.join(tmpfk, ", ") + ")");

            c.assign("tmpfk", new REXPString(tmpfk));
            historyEntry.add("tmpfv<-c(" + StringUtils.join(tmpfv, ", ") + ")");
            dbgLog.fine("DvnRserveComm: " + "tmpfv<-c(" + StringUtils.join(tmpfv, ", ") + ")");
            c.assign("tmpfv", new REXPString(tmpfv));
            String fmtNamesLine = "names(tmpfv)<- tmpfk";
            historyEntry.add(fmtNamesLine);

            dbgLog.fine("DvnRserveComm: " + fmtNamesLine);
            c.voidEval(fmtNamesLine);

            String fmtValuesLine = "varFmt<- as.list(tmpfv)";
            historyEntry.add(fmtValuesLine);

            dbgLog.fine("DvnRserveComm: " + fmtValuesLine);
            c.voidEval(fmtValuesLine);
        } else {
            String[] varFmtN = {};
            List<String> varFmtV = new ArrayList<String>();
            historyEntry.add("varFmt <- list()");

            dbgLog.fine("DvnRserveComm: " + "varFmt <- list()");
            c.assign("varFmt", new REXPList(new RList(varFmtV, varFmtN)));
        }
        /*
        vnames<-c("race","age","vote")
        */

        // variable names
        // String [] jvnames = {"race","age","vote"};

        String[] jvnamesRaw = sro.getVariableNames();
        String[] jvnames = null;

        //VariableNameFilterForR nf = new VariableNameFilterForR(jvnamesRaw);

        if (sro.hasUnsafedVariableNames) {
            // create  list
            jvnames = sro.safeVarNames;
            dbgLog.fine("renamed=" + StringUtils.join(jvnames, ","));
        } else {
            jvnames = jvnamesRaw;
        }
        //historyEntry.add("vnamnes<-c("+ StringUtils.join(jvnames, ", ")+")");
        String vnQList = DvnDSButil.joinNelementsPerLine(jvnames, true);
        historyEntry.add("vnames<-c(" + vnQList + ")");

        c.assign("vnames", new REXPString(jvnames));

        // confirmation
        String[] tmpjvnames = c.eval("vnames").asStrings();
        dbgLog.fine("DvnRserveComm: " + "vnames:" + StringUtils.join(tmpjvnames, ","));

        /*
        x<-read.table141vdc(file="/tmp/VDC/t.28948.1.tab", 
            col.names=vnames, colClassesx=vartyp, varFormat=varFmt)
        */

        //String datafilename = "/nfs/home/A/asone/java/rcode/t.28948.1.tab";

        // tab-delimited file name = tempFileName

        // vnames = Arrays.deepToString(new REXPString(jvnames).asStrings())
        // vartyp = Arrays.deepToString(new REXPInteger(sro.getUpdatedVariableTypes()).asStrings())
        // varFmt = 
        dbgLog.fine("col names ..... " + Arrays.deepToString(jvnames));
        dbgLog.fine("colClassesX ... " + Arrays.toString(sro.getVariableTypesWithBoolean()));
        dbgLog.fine("varFormat ..... " + tmpFmt);

        String readtableline = "x<-read.table141vdc(file='" + tempFileName
                + "', col.names=vnames, colClassesx=vartyp, varFormat=varFmt )";

        historyEntry.add(readtableline);
        dbgLog.fine("DvnRserveComm: " + "readtable=" + readtableline);

        c.voidEval(readtableline);

        // safe-to-raw variable name
        /* 
          attr(x, "Rsafe2raw")<-list();
        */
        //if (nf.hasRenamedVariables()){
        if (sro.hasUnsafedVariableNames) {
            dbgLog.fine("unsafeVariableNames exist");
            // create  list
            //jvnames = nf.getFilteredVarNames();
            jvnames = sro.safeVarNames;
            String[] rawNameSet = sro.renamedVariableArray;
            String[] safeNameSet = sro.renamedResultArray;

            historyEntry.add("tmpRN<-c(" + StringUtils.join(rawNameSet, ", ") + ")");
            c.assign("tmpRN", new REXPString(rawNameSet));
            historyEntry.add("tmpSN<-c(" + StringUtils.join(safeNameSet, ", ") + ")");
            c.assign("tmpSN", new REXPString(safeNameSet));

            String raw2safevarNameTableLine = "names(tmpRN)<- tmpSN";
            historyEntry.add(raw2safevarNameTableLine);
            c.voidEval(raw2safevarNameTableLine);
            String attrRsafe2rawLine = "attr(x, 'Rsafe2raw')<- as.list(tmpRN)";
            historyEntry.add(attrRsafe2rawLine);
            c.voidEval(attrRsafe2rawLine);
        } else {
            String attrRsafe2rawLine = "attr(x, 'Rsafe2raw')<-list();";
            historyEntry.add(attrRsafe2rawLine);
            c.voidEval(attrRsafe2rawLine);
        }

        //Map<String, String> Rsafe2raw = sro.getRaw2SafeVarNameTable();

        // asIs
        /* 
        for (i in 1:dim(x)[2]){if (attr(x,"var.type")[i] == 0) {
        x[[i]]<-I(x[[i]]);  x[[i]][ x[[i]] == '' ]<-NA  }}
        */

        /* 
         * Commenting out the fragment below: 
         * - this is now being done early on in the read.table141vdc
         *   R function:
                 
        String asIsline  = "for (i in 1:dim(x)[2]){ "+
        "if (attr(x,'var.type')[i] == 0) {" +
        "x[[i]]<-I(x[[i]]);  x[[i]][ x[[i]] == '' ]<-NA  }}";
        historyEntry.add(asIsline);
        c.voidEval(asIsline);
        */

        // replication: copy the data.frame
        String repDVN_Xdupline = "dvnData<-x";
        c.voidEval(repDVN_Xdupline);
        tmpResult.put("dvn_dataframe", "dvnData");

        // recoding line
        if (sro.hasRecodedVariables()) {

            // subsetting 

            // For operations on time values during recoding we need
            // to set the following option (this is to enable millisecond
            // precision time): 
            //      -- L.A., v3.6

            c.voidEval("saved.options <- options(digits.secs = 3)");

            List<String> scLst = sro.getSubsetConditions();
            if (scLst != null) {
                for (String sci : scLst) {
                    dbgLog.fine("sci:" + sci);
                    historyEntry.add(sci);
                    c.voidEval(sci);
                }
                tmpResult.put("subset", "T");
            }
            // recoding

            List<String> rcLst = sro.getRecodeConditions();
            if (rcLst != null) {
                for (String rci : rcLst) {
                    dbgLog.fine("rci:" + rci);

                    historyEntry.add(rci);
                    c.voidEval(rci);
                }

                // subsetting (mutating the data.frame strips non-default attributes 
                // 
                // variable type must be re-attached

                if (!"Download".equals(sro.getRequestType())) {
                    String varTypeNew = "vartyp<-c("
                            + StringUtils.join(sro.getUpdatedVariableTypesAsString(), ",") + ")";
                    historyEntry.add(varTypeNew);
                    dbgLog.fine("updated var Type =" + sro.getUpdatedVariableTypesAsString());
                    c.assign("vartyp", new REXPInteger(sro.getUpdatedVariableTypes()));
                } else {
                    dbgLog.fine("updated var Type =" + sro.getUpdatedVariableTypesWithBooleanAsString());
                    c.assign("vartyp", new REXPInteger(sro.getUpdatedVariableTypesWithBoolean()));
                }

                String reattachVarTypeLine = "attr(x, 'var.type') <- vartyp";
                historyEntry.add(reattachVarTypeLine);

                dbgLog.fine("DvnRserveComm: " + reattachVarTypeLine);
                c.voidEval(reattachVarTypeLine);

                // replication: variable type
                String repDVN_vt = "attr(dvnData, 'var.type') <- vartyp";

                dbgLog.fine("DvnRserveComm: " + repDVN_vt);
                c.voidEval(repDVN_vt);

                // new (recoded) variable names: 
                String varNamesRecoded = "recodedvnames<-c(" + StringUtils.join(sro.getRecodedVarNameSet(), ",")
                        + ")";
                historyEntry.add(varNamesRecoded);
                dbgLog.fine("recoded var names =" + StringUtils.join(sro.getRecodedVarNameSet(), ","));
                c.assign("recodedvnames", sro.getRecodedVarNameSet());

                tmpFmt = sro.getUpdatedVariableFormats();
                dbgLog.fine("DvnRserveComm: " + "(recoded)tmpFmt=" + tmpFmt);
                if (tmpFmt != null) {
                    Set<String> vfkeys = tmpFmt.keySet();
                    String[] tmpfk = (String[]) vfkeys.toArray(new String[vfkeys.size()]);
                    String[] tmpfv = getValueSet(tmpFmt, tmpfk);
                    historyEntry.add("tmpfk<-c(" + StringUtils.join(tmpfk, ", ") + ")");
                    dbgLog.fine("DvnRserveComm: " + "(recoded)tmpfk<-c(" + StringUtils.join(tmpfk, ", ") + ")");

                    c.assign("tmpfk", new REXPString(tmpfk));
                    historyEntry.add("tmpfv<-c(" + StringUtils.join(tmpfv, ", ") + ")");
                    dbgLog.fine("DvnRserveComm: " + "(recoded)tmpfv<-c(" + StringUtils.join(tmpfv, ", ") + ")");
                    c.assign("tmpfv", new REXPString(tmpfv));
                    String fmtNamesLine = "names(tmpfv)<- tmpfk";
                    historyEntry.add(fmtNamesLine);

                    dbgLog.fine("DvnRserveComm: (recoded)" + fmtNamesLine);
                    c.voidEval(fmtNamesLine);

                    String fmtValuesLine = "varFmt<- as.list(tmpfv)";
                    historyEntry.add(fmtValuesLine);

                    dbgLog.fine("DvnRserveComm: (recoded)" + fmtValuesLine);
                    c.voidEval(fmtValuesLine);
                } else {
                    String[] varFmtN = {};
                    List<String> varFmtV = new ArrayList<String>();
                    historyEntry.add("varFmt <- list()");

                    dbgLog.fine("DvnRserveComm: (recoded)" + "varFmt <- list()");
                    c.assign("varFmt", new REXPList(new RList(varFmtV, varFmtN)));
                }

                // run post-processing on the newly created recode variables:
                dbgLog.fine("running transformrecoded()");

                historyEntry.add("transformrecoded()");
                int recodedVarsStartIndex = sro.getVariableNames().length + 1;
                dbgLog.fine("recoded variables start at " + recodedVarsStartIndex);
                c.voidEval("x<-transformrecoded(x, recodedvarsindx=" + recodedVarsStartIndex
                        + ", col.names=c(vnames,recodedvnames), colClassesx=vartyp, varFormat=varFmt)");
            }

            // reset the milliseconds option: 

            c.voidEval("options(saved.options)");
        }

        // variable Id
        /* 
        attr(x, "var.nmbr")<-c("v198057","v198059","v198060")
        */

        // String[] jvarnmbr = {"v198057","v198059","v198060"};
        //String[] jvarnmbr = sro.getVariableIds();
        // after recoding 
        String[] jvarnmbr = sro.getUpdatedVariableIds();

        String viQList = DvnDSButil.joinNelementsPerLine(jvarnmbr, true);
        historyEntry.add("varnmbr <-c(" + viQList + ")");
        c.assign("varnmbr", new REXPString(jvarnmbr));

        String attrVarNmbrLine = "attr(x, 'var.nmbr')<-varnmbr";
        historyEntry.add(attrVarNmbrLine);

        dbgLog.fine("DvnRserveComm: (varnmbr) " + attrVarNmbrLine);
        c.voidEval(attrVarNmbrLine);

        // confirmation
        String[] vno = c.eval("attr(x, 'var.nmbr')").asStrings();
        dbgLog.fine("varNo=" + StringUtils.join(vno, ","));

        // replication: variable number
        String repDVN_vn = "attr(dvnData, 'var.nmbr') <- varnmbr";

        dbgLog.fine("DvnRserveComm: " + repDVN_vn);
        c.voidEval(repDVN_vn);

        // variable labels
        /* 
        attr(x, "var.labels")<-c("race","age","vote")
        */

        // String[] jvarlabels = {"race","age","vote"};
        // String[] jvarlabels = sro.getVariableLabels();
        // after recoding
        String[] jvarlabels = sro.getUpdatedVariableLabels();

        String vlQList = DvnDSButil.joinNelementsPerLine(jvarlabels, true);

        historyEntry.add("varlabels <-c(" + vlQList + ")");

        dbgLog.fine("DvnRserveComm: " + "varlabels <-c(" + vlQList + ")");
        c.assign("varlabels", new REXPString(jvarlabels));

        String attrVarLabelsLine = "attr(x, 'var.labels')<-varlabels";
        historyEntry.add(attrVarLabelsLine);

        dbgLog.fine("DvnRserveComm: " + attrVarLabelsLine);
        c.voidEval(attrVarLabelsLine);

        // confirmation
        String[] vlbl = c.eval("attr(x, 'var.labels')").asStrings();
        dbgLog.fine("varlabels=" + StringUtils.join(vlbl, ","));

        // replication: 
        String repDVN_vl = "attr(dvnData, 'var.labels') <- varlabels";

        dbgLog.fine("DvnRserveComm: " + repDVN_vl);
        c.voidEval(repDVN_vl);

        // --------- start: block to be used for the production code
        // value-label table
        /* 
        VALTABLE<-list()
        VALTABLE[["1"]]<-list(
        "2"="white",
        "1"="others")
        attr(x, 'val.table')<-VALTABLE
        */

        // create the VALTABLE
        String vtFirstLine = "VALTABLE<-list()";
        historyEntry.add(vtFirstLine);

        dbgLog.fine("DvnRserveComm: " + vtFirstLine);
        c.voidEval(vtFirstLine);

        c.voidEval("VALORDER<-list()");

        // vltbl includes both base and recoded cases when it was generated
        Map<String, Map<String, String>> vltbl = sro.getValueTable();
        Map<String, List<String>> orderedCategoryValues = sro.getCategoryValueOrders();
        Map<String, String> rnm2vi = sro.getRawVarNameToVarIdTable();
        String[] updatedVariableIds = sro.getUpdatedVariableIds();

        //for (int j=0;j<jvnamesRaw.length;j++){
        for (int j = 0; j < updatedVariableIds.length; j++) {
            // if this variable has its value-label table,
            // pass its key and value arrays to the Rserve
            // and finalize a value-table at the Rserve

            //String varId = rnm2vi.get(jvnamesRaw[j]);
            String varId = updatedVariableIds[j];

            if (vltbl.containsKey(varId)) {

                Map<String, String> tmp = (HashMap<String, String>) vltbl.get(varId);
                Set<String> vlkeys = tmp.keySet();
                String[] tmpk = (String[]) vlkeys.toArray(new String[vlkeys.size()]);
                String[] tmpv = getValueSet(tmp, tmpk);
                // debug
                dbgLog.fine("tmp:k=" + StringUtils.join(tmpk, ","));
                dbgLog.fine("tmp:v=" + StringUtils.join(tmpv, ","));

                // index number starts from 1(not 0)
                int indx = j + 1;
                dbgLog.fine("index=" + indx);

                if (tmpv.length > 0) {

                    historyEntry.add("tmpk<-c(" + DvnDSButil.joinNelementsPerLine(tmpk, true) + ")");
                    c.assign("tmpk", new REXPString(tmpk));

                    historyEntry.add("tmpv<-c(" + DvnDSButil.joinNelementsPerLine(tmpv, true) + ")");
                    c.assign("tmpv", new REXPString(tmpv));

                    String namesValueLine = "names(tmpv)<- tmpk";
                    historyEntry.add(namesValueLine);
                    c.voidEval(namesValueLine);

                    String sbvl = "VALTABLE[['" + Integer.toString(indx) + "']]" + "<- as.list(tmpv)";
                    dbgLog.fine("frag=" + sbvl);
                    historyEntry.add(sbvl);
                    c.voidEval(sbvl);

                    // confirmation test for j-th variable name
                    REXP jl = c.parseAndEval(sbvl);
                    dbgLog.fine("jl(" + j + ") = " + jl);
                }
            }

            if (orderedCategoryValues != null && orderedCategoryValues.containsKey(varId)) {
                int indx = j + 1;
                List<String> orderList = orderedCategoryValues.get(varId);
                if (orderList != null) {
                    String[] ordv = (String[]) orderList.toArray(new String[orderList.size()]);
                    dbgLog.fine("ordv=" + StringUtils.join(ordv, ","));
                    c.assign("ordv", new REXPString(ordv));
                    String sbvl = "VALORDER[['" + Integer.toString(indx) + "']]" + "<- as.list(ordv)";
                    dbgLog.fine("VALORDER[...]=" + sbvl);
                    historyEntry.add(sbvl);
                    c.voidEval(sbvl);
                } else {
                    dbgLog.fine("NULL orderedCategoryValues list.");
                }
            }
        }

        // debug: confirmation test for value-table
        dbgLog.fine("length of vl=" + c.eval("length(VALTABLE)").asInteger());
        String attrValTableLine = "attr(x, 'val.table')<-VALTABLE";
        historyEntry.add(attrValTableLine);
        c.voidEval(attrValTableLine);

        // replication: value-label table
        String repDVN_vlt = "attr(dvnData, 'val.table') <- VALTABLE";
        c.voidEval(repDVN_vlt);

        // --------- end: block to be used for the production code

        // missing-value list: TO DO
        /*
        MSVLTBL<-list(); attr(x, 'missval.table')<-MSVLTBL
        */
        String msvStartLine = "MSVLTBL<-list();";
        historyEntry.add(msvStartLine);
        c.voidEval(msvStartLine);
        // data structure
        String attrMissvalLine = "attr(x, 'missval.table')<-MSVLTBL";
        historyEntry.add(attrMissvalLine);
        c.voidEval(attrMissvalLine);

        // replication: missing value table
        String repDVN_mvlt = "attr(dvnData, 'missval.table') <- MSVLTBL";
        c.voidEval(repDVN_mvlt);

        // attach attributes(tables) to the data.frame
        /*
        x<-createvalindex(dtfrm=x, attrname='val.index')
        x<-createvalindex(dtfrm=x, attrname='missval.index')
        */
        String createVIndexLine = "x<-createvalindex(dtfrm=x, attrname='val.index');";
        historyEntry.add(createVIndexLine);
        c.voidEval(createVIndexLine);
        String createMVIndexLine = "x<-createvalindex(dtfrm=x, attrname='missval.index');";
        historyEntry.add(createMVIndexLine);
        c.voidEval(createMVIndexLine);

        // reflection block: start ------------------------------------------>

        String requestTypeToken = sro.getRequestType();// (Download|EDA|Xtab|Zelig)
        dbgLog.fine("requestTypeToken=" + requestTypeToken);
        historyEntry.add("#### The Request is " + requestTypeToken + " ####");
        // get a test method
        Method mthd = runMethods.get(requestTypeToken);
        dbgLog.fine("method=" + mthd);

        try {
            // invoke this method
            result = (Map<String, String>) mthd.invoke(this, sro, c);
        } catch (InvocationTargetException e) {
            //Throwable cause = e.getCause();
            //err.format(cause.getMessage());
            e.printStackTrace();
        } catch (IllegalAccessException e) {
            e.printStackTrace();
        }

        // add the variable list
        result.put("variableList", joinNelementsPerLine(jvnamesRaw, 5, null, false, null, null));

        //result.put("variableList",StringUtils.join(jvnamesRaw, ", "));

        // replication: var-level unf
        String repDVN_varUNF = "attr(dvnData, 'variableUNF') <- paste(unf(dvnData,version=3))";
        c.voidEval(repDVN_varUNF);

        // calculate the file-leve UNF

        String fileUNFline = "fileUNF <- paste(summary(unf(dvnData, version=3)))";
        c.voidEval(fileUNFline);
        String fileUNF = c.eval("fileUNF").asString();
        if (fileUNF == null) {
            fileUNF = "NA";
        }

        // replication: file-level unf
        String repDVN_fileUNF = "attr(dvnData, 'fileUNF') <- fileUNF";
        c.voidEval(repDVN_fileUNF);

        String RversionLine = "R.Version()$version.string";
        String Rversion = c.eval(RversionLine).asString();

        dbgLog.fine(String.format("R-version String = %s", Rversion));

        // replication: R version
        String repDVN_Rversion = "attr(dvnData, 'R.version') <- R.Version()$version.string";
        c.voidEval(repDVN_Rversion);

        String zeligVersionLine = "packageDescription('Zelig')$Version";
        String zeligVersion = c.eval(zeligVersionLine).asString();

        //String RexecDate = c.eval("date()").asString();
        String RexecDate = c.eval("as.character(as.POSIXct(Sys.time()))").asString();
        // replication: date
        String repDVN_date = "attr(dvnData, 'date') <- as.character(as.POSIXct(Sys.time()))";
        c.voidEval(repDVN_date);

        String repDVN_dfOrigin = "attr(dvnData, 'data.frame.origin')<- "
                + "list('provider'='Dataverse Network Project',"
                + "'format' = list('name' = 'DVN data.frame', 'version'='1.3'))";
        c.voidEval(repDVN_dfOrigin);
        /*
        if (result.containsKey("option")){
        result.put("R_run_status", "T");
        } else {
        result.put("option", requestTypeToken.toLowerCase()); //download  zelig eda xtab
        result.put("R_run_status", "F");
        }
        */
        if (sro.hasRecodedVariables()) {
            if (sro.getSubsetConditions() != null) {
                result.put("subsettingCriteria", StringUtils.join(sro.getSubsetConditions(), "\n"));
                // replication: subset lines
                String[] sbst = null;
                sbst = (String[]) sro.getSubsetConditions()
                        .toArray(new String[sro.getSubsetConditions().size()]);

                c.assign("sbstLines", new REXPString(sbst));

                String repDVN_sbst = "attr(dvnData, 'subsetLines') <- sbstLines";
                c.voidEval(repDVN_sbst);
            }
            /* to be used in the future? */
            if (sro.getRecodeConditions() != null) {
                result.put("recodingCriteria", StringUtils.join(sro.getRecodeConditions(), "\n"));
                String[] rcd = null;
                rcd = (String[]) sro.getRecodeConditions()
                        .toArray(new String[sro.getRecodeConditions().size()]);

                c.assign("rcdtLines", new REXPString(rcd));

                String repDVN_rcd = "attr(dvnData, 'recodeLines') <- rcdtLines";
                c.voidEval(repDVN_rcd);
            }

        }

        // save workspace as a replication data set

        String RdataFileName = "DVNdataFrame." + PID + ".RData";
        result.put("Rdata", "/" + requestdir + "/" + RdataFileName);

        String saveWS = "save('dvnData', file='" + wrkdir + "/" + RdataFileName + "')";
        dbgLog.fine("save the workspace=" + saveWS);
        c.voidEval(saveWS);

        // write back the R workspace to the dvn 

        String wrkspFileName = wrkdir + "/" + RdataFileName;
        dbgLog.fine("wrkspFileName=" + wrkspFileName);

        int wrkspflSize = getFileSize(c, wrkspFileName);

        File wsfl = writeBackFileToDvn(c, wrkspFileName, RWRKSP_FILE_PREFIX, "RData", wrkspflSize);

        result.put("dvn_RData_FileName", wsfl.getName());

        if (wsfl != null) {
            result.put("wrkspFileName", wsfl.getAbsolutePath());
            dbgLog.fine("wrkspFileName=" + wsfl.getAbsolutePath());
        } else {
            dbgLog.fine("wrkspFileName is null");
        }

        result.put("library_1", "VDCutil");

        result.put("fileUNF", fileUNF);
        result.put("dsbHost", RSERVE_HOST);
        result.put("dsbPort", DSB_HOST_PORT);
        result.put("dsbContextRootDir", DSB_CTXT_DIR);
        result.put("PID", PID);
        result.put("Rversion", Rversion);
        result.put("zeligVersion", zeligVersion);
        result.put("RexecDate", RexecDate);
        result.put("RCommandHistory", StringUtils.join(historyEntry, "\n"));

        result.putAll(tmpResult);
        dbgLog.fine("result object (before closing the Rserve):\n" + result);

        // reflection block: end

        // create a zip file of the directory created: 

        //String zipTmpDir = "system(\"(cd "+DSB_TMP_DIR+"; zip -r /tmp/"+requestdir+".zip "+requestdir+")\")";
        //c.voidEval(zipTmpDir);        

        // transfer the zip file to the application side: 

        //RFileInputStream ris = null;
        //OutputStream outbr   = null;

        //int zipSize = getFileSize(c,"/tmp/"+requestdir+".zip");

        String listAnalysisFiles = "list.files('" + DSB_TMP_DIR + "/" + requestdir + "', recursive=TRUE)";
        dbgLog.fine("looking up the analysis result files on the DSB/Rserve side: " + listAnalysisFiles);
        String[] analysisReportFiles = c.eval(listAnalysisFiles).asStrings();
        RFileInputStream ris = null;
        OutputStream outbr = null;

        try {
            File localReportDir = new File(TEMP_DIR + "/DVN", requestdir);
            if (!localReportDir.exists()) {
                localReportDir.mkdir();
            }

            for (int i = 0; i < analysisReportFiles.length; i++) {
                String reportFile = analysisReportFiles[i];
                int reportFileSize = getFileSize(c, DSB_TMP_DIR + "/" + requestdir + "/" + reportFile);
                dbgLog.fine("DvnRData: transferring file " + reportFile);
                dbgLog.fine("DvnRData: file size: " + reportFileSize);

                if (reportFile.lastIndexOf("/") > 0) {
                    File localReportSubDir = new File(TEMP_DIR + "/DVN/" + requestdir,
                            reportFile.substring(0, reportFile.lastIndexOf("/")));
                    if (!localReportSubDir.exists()) {
                        localReportSubDir.mkdirs();
                    }
                }

                ris = c.openFile(DSB_TMP_DIR + "/" + requestdir + "/" + reportFile);
                outbr = new BufferedOutputStream(
                        new FileOutputStream(new File(TEMP_DIR + "/DVN/" + requestdir, reportFile)));

                byte[] obuf = new byte[reportFileSize];
                int obufsize = 0;

                while ((obufsize = ris.read(obuf)) != -1) {
                    outbr.write(obuf, 0, reportFileSize);
                }

                ris.close();
                outbr.close();
            }

            //String unZipCmd = "/usr/bin/unzip "+TEMP_DIR+"/DVN/"+requestdir+".zip -d "+TEMP_DIR+"/DVN";
            //int exitValue = 1;

            //dbgLog.fine("attempting to execute "+unZipCmd);

            //try {
            //Runtime runtime = Runtime.getRuntime();
            //Process process = runtime.exec(unZipCmd);
            //exitValue = process.waitFor();
            //} catch (Exception e) {
            //e.printStackTrace();
            //exitValue = 1;
            //}

            //if (exitValue == 0) {
            //result.put("webFolderArchived",TEMP_DIR+"/DVN/"+requestdir+".zip");
            //}

        } catch (FileNotFoundException fe) {
            fe.printStackTrace();
        } catch (IOException ie) {
            ie.printStackTrace();
        } finally {
            if (ris != null) {
                ris.close();
            }
            if (outbr != null) {
                outbr.close();
            }
        }

        // // move the temp dir to the web-temp root dir
        //String mvTmpDir = "file.rename('"+wrkdir+"','"+webwrkdir+"')";
        //dbgLog.fine("web-temp_dir="+mvTmpDir);
        //c.voidEval(mvTmpDir);        

        // close the Rserve connection
        c.close();

    } catch (RserveException rse) {
        // RserveException (Rserve is not running)
        rse.printStackTrace();

        result.put("dsbContextRootDir", DSB_CTXT_DIR);
        result.put("PID", PID);
        result.put("RCommandHistory", StringUtils.join(historyEntry, "\n"));
        result.put("option", sro.getRequestType().toLowerCase());

        result.put("RexecError", "true");
        return result;

    } catch (REXPMismatchException mme) {

        // REXP mismatch exception (what we got differs from what we expected)
        mme.printStackTrace();

        result.put("dsbContextRootDir", DSB_CTXT_DIR);
        result.put("PID", PID);
        result.put("RCommandHistory", StringUtils.join(historyEntry, "\n"));
        result.put("option", sro.getRequestType().toLowerCase());

        result.put("RexecError", "true");
        return result;

    } catch (IOException ie) {
        ie.printStackTrace();

        result.put("dsbContextRootDir", DSB_CTXT_DIR);
        result.put("PID", PID);
        result.put("RCommandHistory", StringUtils.join(historyEntry, "\n"));
        result.put("option", sro.getRequestType().toLowerCase());

        result.put("RexecError", "true");
        return result;

    } catch (Exception ex) {
        ex.printStackTrace();

        result.put("dsbContextRootDir", DSB_CTXT_DIR);
        result.put("PID", PID);

        result.put("RCommandHistory", StringUtils.join(historyEntry, "\n"));
        result.put("option", sro.getRequestType().toLowerCase());

        result.put("RexecError", "true");
        return result;
    }

    return result;

}

From source file:edu.harvard.iq.dvn.ingest.dsb.impl.DvnRGraphServiceImpl.java

/** *************************************************************
 * Execute an R-based dvn analysis request on a Graph object
 * using an open connection created during the Initialize call. 
 *
 * @param sro    a DvnJobRequest object that contains various parameters
 * @return    a Map that contains various information about the results
 *///w ww.  j av a 2  s  . c om

public Map<String, String> liveConnectionExecute(DvnRJobRequest sro) throws DvnRGraphException {

    // set the return object
    Map<String, String> result = new HashMap<String, String>();

    if (sro != null) {
        dbgLog.fine(
                "LCE sro dump:\n" + ToStringBuilder.reflectionToString(sro, ToStringStyle.MULTI_LINE_STYLE));
    } else {
        throw new DvnRGraphException("execute method called with a NULL job ob ject.");

    }

    String SavedRworkSpace = null;

    Map<String, Object> SubsetParameters = sro.getParametersForGraphSubset();

    if (SubsetParameters != null) {
        SavedRworkSpace = (String) SubsetParameters.get(SAVED_RWORK_SPACE);
    } else {
        throw new DvnRGraphException("execute method called with a null parameters object");

    }

    DvnRConnection drc = null;

    try {
        // let's see if we have a connection that we can use: 

        if (myConnection == 0) {
            throw new DvnRGraphException("execute method called without securing a connection first");
        }

        myConnection = RConnectionPool.securePooledConnection(SavedRworkSpace, null, true, myConnection);
        dbgLog.info("Execute: obtained connection " + myConnection);

        drc = RConnectionPool.getConnection(myConnection);

        String GraphSubsetType = (String) SubsetParameters.get(RSUBSETFUNCTION);

        if (GraphSubsetType != null) {

            if (GraphSubsetType.equals(MANUAL_QUERY_SUBSET)) {

                String manualQueryType = (String) SubsetParameters.get(MANUAL_QUERY_TYPE);
                String manualQuery = (String) SubsetParameters.get(MANUAL_QUERY);

                String subsetCommand = null;

                if (manualQueryType != null) {
                    if (manualQueryType.equals(EDGE_SUBSET)) {
                        String dropDisconnected = (String) SubsetParameters.get(ELIMINATE_DISCONNECTED);
                        if (dropDisconnected != null) {
                            subsetCommand = "edge_subset(g, '" + manualQuery + "', TRUE)";
                        } else {
                            subsetCommand = "edge_subset(g, '" + manualQuery + "')";
                        }

                    } else if (manualQueryType.equals(VERTEX_SUBSET)) {
                        subsetCommand = "vertex_subset(g, '" + manualQuery + "')";
                    } else {
                        throw new DvnRGraphException("execute: unsupported manual query subset");

                    }

                    dbgLog.fine("LCE: manualQuerySubset=" + subsetCommand);
                    historyEntry.add(subsetCommand);
                    String cmdResponse = safeEval(drc.Rcon, subsetCommand).asString();

                }

            } else if (GraphSubsetType.equals(NETWORK_MEASURE)) {
                String networkMeasureType = (String) SubsetParameters.get(NETWORK_MEASURE_TYPE);
                String networkMeasureCommand = null;
                if (networkMeasureType != null) {
                    List<NetworkMeasureParameter> networkMeasureParameterList = (List<NetworkMeasureParameter>) SubsetParameters
                            .get(NETWORK_MEASURE_PARAMETER);
                    networkMeasureCommand = networkMeasureType + "(g"
                            + buildParameterComponent(networkMeasureParameterList) + ")";
                }

                if (networkMeasureCommand == null) {
                    throw new DvnRGraphException("ILLEGAL OR UNSUPPORTED NETWORK MEASURE QUERY");

                }

                historyEntry.add(networkMeasureCommand);
                String addedColumn = safeEval(drc.Rcon, networkMeasureCommand).asString();

                if (addedColumn != null) {
                    result.put(NETWORK_MEASURE_NEW_COLUMN, addedColumn);
                } else {
                    throw new DvnRGraphException("FAILED TO READ ADDED COLUMN NAME");

                }

            } else if (GraphSubsetType.equals(AUTOMATIC_QUERY_SUBSET)) {
                String automaticQueryType = (String) SubsetParameters.get(AUTOMATIC_QUERY_TYPE);
                String autoQueryCommand = null;
                if (automaticQueryType != null) {
                    String n = (String) SubsetParameters.get(AUTOMATIC_QUERY_N_VALUE);
                    autoQueryCommand = automaticQueryType + "(g, " + n + ")";

                }

                if (autoQueryCommand == null) {
                    throw new DvnRGraphException("NULL OR UNSUPPORTED AUTO QUERY");
                }

                historyEntry.add(autoQueryCommand);
                String cEval = safeEval(drc.Rcon, autoQueryCommand).asString();

            } else if (GraphSubsetType.equals(UNDO)) {
                String cEval = safeEval(drc.Rcon, "undo()").asString();
            } else if (GraphSubsetType.equals(RESET)) {
                dbgLog.info("resetting the workspace; using reset(" + SavedRworkSpace + ")");

                String cEval = safeEval(drc.Rcon, "reset('" + SavedRworkSpace + "')").asString();

            }

        }

        // get the vertices and edges counts: 

        String countCommand = "vcount(g)";
        int countResponse = safeEval(drc.Rcon, countCommand).asInteger();
        result.put(NUMBER_OF_VERTICES, Integer.toString(countResponse));

        countCommand = "ecount(g)";
        countResponse = safeEval(drc.Rcon, countCommand).asInteger();
        result.put(NUMBER_OF_EDGES, Integer.toString(countResponse));

        result.put(SAVED_RWORK_SPACE, RDataFileName);

        // we're done; let's add some potentially useful 
        // information to the result and return: 

        String RexecDate = drc.Rcon.eval("as.character(as.POSIXct(Sys.time()))").asString();
        String RversionLine = "R.Version()$version.string";
        String Rversion = drc.Rcon.eval(RversionLine).asString();

        result.put("dsbHost", RSERVE_HOST);
        result.put("dsbPort", DSB_HOST_PORT);
        result.put("IdSuffix", IdSuffix);
        result.put("Rversion", Rversion);
        result.put("RexecDate", RexecDate);
        result.put("RCommandHistory", StringUtils.join(historyEntry, "\n"));

        if (!SavedRworkSpace.equals(drc.getWorkSpace())) {
            throw new DvnRGraphException("Could not execute query: connection lost");
        }

    } catch (DvnRGraphException dre) {
        throw dre;
    } catch (RException re) {
        throw new DvnRGraphException(re.getMessage());

    } catch (RserveException rse) {

        dbgLog.info("LCE: rserve exception message: " + rse.getMessage());
        dbgLog.info("LCE: rserve exception description: " + rse.getRequestErrorDescription());
        throw new DvnRGraphException("RServe failure: " + rse.getMessage());

    } catch (REXPMismatchException mme) {

        throw new DvnRGraphException("REXPmismatchException occured");

    } catch (Exception ex) {

        throw new DvnRGraphException("Execute: unknown exception occured: " + ex.getMessage());

    } finally {
        if (drc != null) {
            // set the connection time stamp: 
            Date now = new Date();
            drc.setLastQueryTime(now.getTime());

            drc.unlockConnection();
        }
    }

    return result;

}

From source file:com.gemini.provision.loadbalancer.openstack.LoadBalancerProviderOpenStackImpl.java

@Override
public List<GeminiPoolMember> getPoolMembers(GeminiTenant tenant, GeminiEnvironment env,
        GeminiLoadBalancerPool pool) {/*from   w w  w  .ja va2 s .c o  m*/
    List<GeminiPoolMember> lbPools = Collections.synchronizedList(new ArrayList());

    //authenticate the session with the OpenStack installation
    OSClient os = getOSClient(tenant, env);
    if (os == null) {
        Logger.error("Failed to authenticate Tenant: {}",
                ToStringBuilder.reflectionToString(tenant, ToStringStyle.MULTI_LINE_STYLE));
        return null;
    }
    List<? extends Member> members = os.networking().loadbalancers().member().list();
    members.stream().filter(member -> member != null).forEach(member -> {
        GeminiPoolMember geminiPoolMember = new GeminiPoolMember();
        geminiPoolMember.setCloudID(member.getId());
        geminiPoolMember.setAdminState(member.isAdminStateUp() ? AdminState.ADMIN_UP : AdminState.ADMIN_DOWN);
        geminiPoolMember.setProvisionState(ProvisionState.fromString(member.getStatus()));
        geminiPoolMember.setIpAddress(member.getAddress());
        geminiPoolMember.setProtocolPort(member.getProtocolPort());
        geminiPoolMember.setWeight(member.getWeight());
        geminiPoolMember.setPoolId(member.getPoolId());
        lbPools.add(geminiPoolMember);
    });
    return lbPools;
}