How to retire a lifecycle asset using java api?
In order to retire it using the java api i used the actions available on the asset.
After setting the action as retire it goes to the pre retired state,so i tried setting the same action again but that did not make any difference.
Code snippet used :
for (RAMAction action : actions) {
if (action.getName() != null
&& RAMConfig.RETIRE_ACTION.equalsIgnoreCase(action
.getName())) {
asset.setAction(action);
session.put(asset, new RAMStatusMonitor());
asset.setAction(action);
session.put(asset, new RAMStatusMonitor());
}
}
Could you please tell me if this is not correct?
2 answers
For lifecycle assets you have to use available actions. But after every put of an asset you need to get the available actions again since the set of available actions is different for every state of the asset. When you move into a new state, such as pre-retire there is a new set of available actions that you must use. The old set is now invalid.
RAMSession session = null;
try {
session = new RAMSession(RAM_URL, RAM_UID, RAM_PASSWD);
session.setWebServiceTimeout(10000);
RAMAsset asset = session.getAsset(new AssetIdentification(RAM_GUID, RAM_VER));
if (asset == null) {
System.out.println("Could not find Asset("+RAM_GUID+","+RAM_VER+")");
System.exit(1);
}
RAMAction[] actions = asset.getAvailableActions();
RAMAction action = null;
for (int i = 0; i < actions.length; i++) {
// Note taht RAMAction.RETIRE is a legacy action,
// but its name and the name for the typical lifecycle is the same
if (actions[i].getName().equals(RAMAction.RETIRE.getName()))
action = actions[i];
}
if (action!=null) {
System.out.println("Driving Action: "+action.getName());
asset.setAction(action);
session.put(asset, new NullProgressMonitor());
}
else
System.out.println(RAMAction.RETIRE+" is not available");
}
catch (Throwable e) {
e.printStackTrace();
}
finally {
if (session != null)
session.release();
}
Note also that there is a defect around driving a retire from API: Java API to retire an asset (drive the Retire action) will not work properly (79583)
Check your ramDebug.log for exception ... if you get one when you drive this API and require this fix. Contact IBM's service and support.
Comments
Hi Gill,
Thanks for the reply.
I was able to get it working the way Rich suggested.
Could you please elaborate more on the defect that you mentioned as i could not get a clear picture of it from the description mentioned in the defect?
Thanks
There is a bug in the Retire didn't work for lifecycle assets. It threw an exception on the host.
Can you tell me what exception i should look for?
Drive the retire action, and to to the Administrator -> tools, and click on the ramDebug.log ... scroll down to the bottom. See if you have a new "present" for ya.
There was no such thing in the logs after driving the retire action.
So does this mean we are good or do we still need the fix to be applied so that in future we don't encounter this problem?
If you have no exceptions in the log after driving the action, and asset indeed moves to the retire state; you are fine.
Thanks Gili.
Comments
Manjiri Kamat
Jan 28 '13, 11:43 p.m.I just tried using RAMAction.RETIRE followed by RAMAction.Archive for the asset it did set the asset to retired.
I believe we should use this for a lifecycle asset and use the available action of the asset only when the asset is in pre retired to set it to retired.
Do let me know if my understanding is correct?