UCMDB and UD Practitioners Forum (Previously CMS)
cancel
Showing results for 
Search instead for 
Did you mean: 

uCDMDB version 10.2 View Creation using JAVA API

Highlighted
sreekeshava
Acclaimed Contributor

uCDMDB version 10.2 View Creation using JAVA API

Hi am writing JAVA program using JAVA API provided by HP-uCMDB Version 10.2 to create and save a Simple uCMDB View.

Able to create view,write TQL and filter the results. But, while saving the view, am receiving the below error.

 

Have attached the program also. Need a sample JAVA program using uCMDB Java API to create and save a simple View in uCMDB

 

Exception in thread "main" com.hp.ucmdb.api.ExecutionException:
--- Start of server-side exception ---
com.mercury.topaz.cmdb.shared.base.CmdbException: [ErrorCode [110008] URM validation error occured after put/remove operations]
[ERROR CODE- 110008] appilog.common.system.exceptions.AppilogException: appilog.framework.shared.manage.impl.MamResponseException: [ErrorCode [110008] URM validation error occured after put/remove operations]
CMDB Operation Internal Error: class appilog.framework.shared.manage.impl.MamResponseException : appilog.framework.shared.manage.impl.MamResponseException: [ErrorCode [110008] URM validation error occured after put/remove operations]
CMDB Operation Internal Error: class com.mercury.topaz.cmdb.shared.base.CmdbException : URM transaction validation error: The resource key: {{},Topology_TQL} is referenced from resource: {{MyView},Topology_VIEW} but isn't exist in the URM!! : operation com.hp.ucmdb.view.facade.impl.ViewPersistenceManagerFacadeImpl$1ViewUpdateSaveViewOperation : class com.mercury.topaz.cmdb.shared.base.CmdbException :
CMDB Internal Error: Error while handling request: {request: ID='9e35489370f42f4203ee72ae6d49c465' Message='General CMDB request' Operation='com.hp.ucmdb.view.facade.impl.ViewPersistenceManagerFacadeImpl$1ViewUpdateSaveViewOperation@28d85587' Customer ID='1, id name: Default Client'
Context='CMDB Context: Customer id = '1, id name: Default Client' , User ID = '911' , Caller Application = 'Test,loggedInUser:{hpadmin}''} : operation appilog.common.foldering.impl.FoldersFacadeImpl$CreateOrUpdateDefinition : class com.mercury.topaz.cmdb.shared.base.CmdbException :
CMDB Internal Error: Error while handling request: {request: ID='f34b5a4065cc13b5091cc37a45596bf2' Message='General CMDB request' Operation='appilog.common.foldering.impl.FoldersFacadeImpl$CreateOrUpdateDefinition@26bd945d' Customer ID='1, id name: Default Client'

 Program is given below.

import com.hp.ucmdb.api.UcmdbService;
import com.hp.ucmdb.api.UcmdbServiceFactory;
import com.hp.ucmdb.api.UcmdbServiceProvider;
import com.hp.ucmdb.api.topology.*;
import com.hp.ucmdb.api.view.ViewService;
import com.hp.ucmdb.api.view.ViewWithFoldingDefinition;
import com.hp.ucmdb.api.view.foldingdefinition.FoldingDefinition;
import com.hp.ucmdb.api.view.foldingdefinition.FoldingDefinitionNodesFactory;
import com.hp.ucmdb.api.view.result.ViewResult;
import com.hp.ucmdb.api.view.result.ViewResultTreeNode;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.List;
import java.util.Properties;

import org.apache.commons.codec.binary.Base64;
import org.apache.log4j.PropertyConfigurator;
public class Sridhara_View1 {

/**
* @Param args
*/
final static org.apache.log4j.Logger logger = org.apache.log4j.Logger.getLogger("");
public static void main(String[] args) {
// TODO Auto-generated method stub
Properties log4jproperties = new Properties();
try {
log4jproperties.load(new FileInputStream(new File("Properties//log4j.properties")));
} catch (FileNotFoundException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
} catch (IOException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}

PropertyConfigurator.configure(log4jproperties);
if(args.length!=6)
{
logger.error("Incorrect Arguments .Arguments to be provided in the order ucmdbhost ucmdbport protocol ucmdbusername encrypteducmdbpassword tenantname");
System.out.println("View Execution failed");
return;
}

logger.debug("Connecting to uCMDB with servername "+args[0]+" , port "+args[1]+",protocol "+args[2]+", username "+args[3]+ " and password "+args[4]);
UcmdbService ucmdbService=null;
try
{
String username=null;
String password=null;
UcmdbServiceProvider provider =
UcmdbServiceFactory.getServiceProvider(args[2],args[0], Integer.parseInt(args[1]));

username=args[3];

//logger.debug("Decrypting Password "+args[4]);
password=args[4];
//logger.debug("Decrypted password "+password);

ucmdbService =
provider.connect(provider.createCredentials(username,
password), provider.createClientContext("Test"));
logger.debug("connected to ucmdb successfully");
}
catch (Exception e) {
// TODO: handle exception
logger.error("Error while connecting to Ucmdb "+e.getMessage());

e.printStackTrace();
return;
}
ViewService viewService = ucmdbService.getViewService();
//create new view definition
ViewWithFoldingDefinition newView =
viewService.getFactory().createViewWithFoldingDefinition("MyView");
// Get the folding definition of the view
FoldingDefinition definition = newView.foldingDefinition();

// Getting a factory of view nodes
FoldingDefinitionNodesFactory factory = definition.nodesFactory();


definition.addRoot(factory.createQueryNodeBasedFDN("hostname As Parent")).withQueryNodeName("nodename");
// Create the query which is going to be executed by the view
ExecutableQuery query = createQueryForView(ucmdbService,args[5]);

// Execute the view

ViewResult result = viewService.executeViewDefinition(newView, query);

// Get the roots of the result (the top most parents)
List<? extends ViewResultTreeNode> roots = result.roots();
// Go over the nodes and print the amount of IPs and their addresses
for (ViewResultTreeNode root : roots) {
System.out.println( root.label() );

}

viewService.saveView(newView);

}
private static ExecutableQuery createQueryForView(UcmdbService service,String tenantName){
// Getting the topology service
TopologyQueryService queryService = service.getTopologyQueryService();
// Get the query factory
TopologyQueryFactory queryFactory = queryService.getFactory();
// Create the query definition
QueryDefinition queryDefinition = queryFactory.createQueryDefinition("Get nodes with more than one network interface");
queryDefinition.addNode("nodename").ofType("node").queryProperty("display_label").property("TenantOwner").like(tenantName);

return queryDefinition.toExecutable();
}

}

 

 

 

//Add this to "OnDomLoad" event