How to retire a lifecycle asset using java api?
I have a lifecycle asset which is in the approved state.
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?
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
RAMAction.RETIRE and RAMAction.Archive are only valid for legacy assets. These do not work on lifecycle assets.
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.
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.
Typically this is the way you do it:
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.
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
showing 5 of 7
show 2 more comments
Comments
Manjiri Kamat
Jan 28 '13, 11:43 p.m.