cancel
Showing results for 
Search instead for 
Did you mean: 

Importing from command prompt - no error code

nanda_kumar21
Active Contributor
0 Kudos

Hi everyone,

Build version M33.104.

Following this thread, I'm trying to implement the CTS+ for tracking the transports between different Redwood landscapes.

I want to follow the loose coupling for the export and close coupling for import using the script deployment method.

for the script deployment to work, i should map the return codes of the import job with the deploy script so that CTS+ understands it.

Now, I tested the commands and found that, the command prompt doesn't return error code if the import fails, instead i have to go and check the Promotion-->Imports section to see whether the import job completed successfully or not.

The command returns/says upload complete, irrespective of the status of the import job. Screenshot below:

Can you please let me know of a way to output the error? or is there a command to query the status of the job from a remote server?

PS: using the -verbose option didn't help.

Thanks

Nanda

Accepted Solutions (1)

Accepted Solutions (1)

gmblom
Active Contributor
0 Kudos

Hello Nanda,

You can use jscript to gather some information on the import job. Or you can create your own importer that waits for the import to finish. Look at the api-tool.jar file that is in Configuration->Software. This lets you log into the server using a secret file as well.

Regards Gerben

nanda_kumar21
Active Contributor
0 Kudos

Hey Gerben,

Thanks a lot. When i contacted Redwood support, they asked to query the job id, so i developed the script to capture the job id from the import output and then connect to the DB and then query the JobStatus.

  • Jscript requires a platform agent to be present in the Transport Domain control, which is something out of our license scope.
  • If i use api-tool.jar to write my own import, how do i pass arguments to the script? because based on the landscape the SID, hostname and portname will change. Please let me know.

Thanks

Nanda

h_carpenter
Active Contributor
0 Kudos

Hi Nanda,

Here is an example:

import com.redwood.scheduler.api.tool.ToolConnection;

import com.redwood.scheduler.api.tool.ToolConnectionFactory;

import java.io.File;

import java.util.Collection;

import java.util.Map;

public class Uploader

{

  public static void main(String [] args)

  throws Exception

  {

  if (args.length > 1)

  {

  ToolConnection tConnection = ToolConnectionFactory.createConnection(args[0], 60000);

  if (args[1].toLowerCase().endsWith("car"))

  {

  System.out.println("Uploading CAR file");

  String importSet = "";

  if(args.length == 3)

  {

  importSet = args[2];

  }

  Map mp = tConnection.uploadCAR(new File(args[1]), importSet);

  if (mp.size() > 0)

  {

  Collection cl = mp.values();

  System.out.println("JobId: "+cl.iterator().next());

  }

  }

  else if (args[1].toLowerCase().endsWith("jar")&& args.length == 3)

  {

  System.out.println("Uploading JAR file");

  Map mp = tConnection.uploadJAR(new File(args[1]), args[2]);

  if (mp.size() > 0)

  {

  Collection cl = mp.values();

  System.out.println("JobId: "+cl.iterator().next());

  }

  }

  else

  {

  System.out.println("Invalid Arguments.");

  System.out.println("Usage: Main <connection_file> <car_file> [<importRuleSet>]");

  System.out.println(" Main <connection_file> <jar_file> <library>");

  }

  }

  else

  {

  System.out.println("Invalid Arguments.");

  System.out.println("Usage: Main <connection_file> <car_file> [<importRuleSet>]");

  System.out.println(" Main <connection_file> <jar_file> <library>");

  }

  }

}

Hope this helps.

After the tConnection.uploadCAR() I use the map to retrieve the job id, with that you could then check whether the JobStatusState is final or not every 10 seconds in a loop ... Depending on the size of the CAR files, you might want to increase that. If you are going to push CAR files with, say, 1000 objects, the time the job runs to import the car file can be quite long, several minutes ...

How to compile and run it:

$ javac -cp api-tool.jar Uploader.java

$ java -cp api-tool.jar:. Uploader <------- HERE I run it without arguments, so the program prints out which arguments it needs

Invalid Arguments.

Usage: Uploader <connection_file> <car_file> [<importRuleSet>]

  Uploader <connection_file> <jar_file> <library>

$ java -cp api-tool.jar:. Uploader net/connect.rw /tmp/JobDefinition_RS_MSLN_DB_Backup.car

$ java -cp api-tool.jar:. Uploader net/connect.rw /tmp/myJar.jar Custom_Masalan

Hope that helps ...

Regards,

HP

gmblom
Active Contributor
0 Kudos

Hello,

You do not have to poll for the job. You can also use executeScript method on the ToolConnection and then lookup the job for the found job id, and then execute a waitForJob on it instead of polling for it.

Regards Gerben

nanda_kumar21
Active Contributor
0 Kudos

Hi HP,

Thanks a lot for providing such a detailed solution.

I was able to compile the java file successfully, however, the execution fails with the below error:

I also tried:

java -cp api-tool.jar:. Uploader connect.rw JobDefinition_CTS_TEST.car CTS_TEST_IMPORT


didnt work.


the api-tool.jar, is in the same folder as the java file, so is the class file,also the connection file. I know this is something silly that i'm missing, but not able to figure out.


I tried with eclipse IDE and it works, but not from CMD.


Thanks

Nanda

h_carpenter
Active Contributor
0 Kudos

Hi Nanda,

You MUST specify the jar file in your classpath, even if it is in the same directory.

Damn, sorry, on Windows you must use ; (semi-colon) instead of : (colon) in the classpath:

java -cp api-tool.jar;. Uploader connect.rw JobDefinition_CTS_TEST.car CTS_TEST_IMPORT



Regards,


HP

nanda_kumar21
Active Contributor
0 Kudos

That did the trick.

Thanks HP.

Regards

Nanda

nanda_kumar21
Active Contributor
0 Kudos

Hi HP/Gerben,

I just realized that api-tool.jar doesn't include SchedulerSession class or Job class, hence, i cannot execute waitforJob() or directly get the job status.

I can use executeQuery(String query,  Map options,  Map parameters) , but i can get only job status.

I was kind of hoping to get the output file of the import job and print it on the console, so that the list of objects that were affected by the import can be passed on to CTS+. Since the output is a flatfile, query is out of question.

One workaround i could think of is to ftp the CPS server, navigate to the logs folder and search for the filename with the job id and then print the file content to the console. Is there an better alternate? Is there another library that i can make use of?

thanks

Nanda

gmblom
Active Contributor
0 Kudos

Hi Nanda,

You can do an executeScript to get the jcsSession. You can try something like this, if you want to get the output file, just add that in.


static String WAIT_FOR_JOB = "{\n" +

  "  String jobId = \"@jobId\";\n" +

  "  jcsOut.println(\"The Job id of the Import is: \" + jobId);\n" +

  "  Job j = jcsSession.getJobByJobId(new Long(jobId));\n" +

  "  jcsSession.waitForJob(j);\n" +

  "  jcsSession.refreshObjects(new SchedulerEntity [] {j});\n" +

  "  if (!j.getStatus().equals(com.redwood.scheduler.api.model.enumeration.JobStatus.Completed))\n" +

  "  {\n" +

  "    jcsOut.println(\"Import job finished with Errors\");\n" +

  "    jcsErr.print(\"1\");\n" +

  "  }\n" +

  "  else\n" +

  "  {\n" +

  "    jcsOut.println(\"Import job finished without Errors\");\n" +

  "    jcsErr.print(\"0\");\n" +

  "  }\n"

  "}";

OutputStreamOutputHandler jcsOut = new OutputStreamOutputHandler(System.out);

StringBufferOutputHandler jcsErr = new StringBufferOutputHandler(new StringBuffer());

con.executeScript(WAIT_FOR_JOB.replaceAll("@jobId", jobId), jcsOut, jcsErr);

String returnCode = jcsErr.getStringBuffer().toString();

if (!returnCode.startsWith("0"))

{

  System.exit(new Long(returnCode).intValue());

}

Regards Gerben

h_carpenter
Active Contributor
0 Kudos

Hi Nanda,

You can retrieve the output file using a link.

http://pr1.masalan.com:50200/scheduler/jobfile/download/jobid=81086/fileno=1/Job_81086_stdout.log

You can find examples of how to login and download this file here:

How do I connect to a URL using Basic authentication? - Web Tutorials - avajava.com

You simply replace the URL with the link above. The example even prints out the page ....

BTW, I found the link by downloading a file and displaying the download link in the browser, make sure you download a file from the job that was generated by the Uploader.

Regards,

HP

nanda_kumar21
Active Contributor
0 Kudos

Thanks a lot Gerben.

I will test and update this thread.

Thanks

Nanda

Answers (1)

Answers (1)

abhishek_singh29
Active Participant
0 Kudos

Hi Nanda,

Can you please try - right click on job and click on GET SUPPORT FILES.

Regards,

Abhishek

nanda_kumar21
Active Contributor
0 Kudos

hey Abhishek,

My issue is in the command prompt, not in redwood.

I know why the import failed, i want the command prompt to say that import failed.

Thanks

Nanda