void solver(){ int instance; Graph G; instance = 1; G = inputInstance(); while(G != NULL){ outInstance(instance, processInstance(G)); instance++; GRAPHdestroy(G); G = inputInstance(); } }
void test14 (CIMClient & client) { CIMObjectPath instanceName; instanceName.setNameSpace (providerNamespace); instanceName.setClassName (CLASSNAME); Array < CIMParamValue > inParams; Array < CIMInstance> eObjs; Array < CIMParamValue > outParams; CIMValue retValue = client.invokeMethod (providerNamespace, instanceName, "returnInstance", inParams, outParams); PEGASUS_TEST_ASSERT (retValue.getType () == CIMTYPE_OBJECT); PEGASUS_TEST_ASSERT (!retValue.isArray ()); PEGASUS_TEST_ASSERT (!retValue.isNull ()); CIMObject result; retValue.get (result); CIMObjectPath objPath = result.getPath(); CIMInstance inputInstance(result); CIMInstance outputInstance; eObjs.append(inputInstance); eObjs.append(inputInstance); eObjs.append(inputInstance); inParams.append ( CIMParamValue(String("inputInstances"), CIMValue(eObjs))); retValue = client.invokeMethod (providerNamespace, instanceName, "processArrayEmbeddedInstance", inParams, outParams); // First test the return value PEGASUS_TEST_ASSERT(retValue.getType() == CIMTYPE_INSTANCE); PEGASUS_TEST_ASSERT(!retValue.isArray()); PEGASUS_TEST_ASSERT(!retValue.isNull()); retValue.get(outputInstance); PEGASUS_TEST_ASSERT(objPath.toString() == outputInstance.getPath().toString()); PEGASUS_TEST_ASSERT(outputInstance.getPropertyCount() == inputInstance.getPropertyCount()); for(unsigned int i = 0, n = outputInstance.getPropertyCount(); i < n; ++i) { CIMProperty outputProp(outputInstance.getProperty(i)); CIMProperty inputProp(inputInstance.getProperty(i)); PEGASUS_TEST_ASSERT(outputProp.getName() == inputProp.getName()); PEGASUS_TEST_ASSERT(outputProp.getValue() == inputProp.getValue()); } // Now test the output parameters PEGASUS_TEST_ASSERT(outParams.size() == 3); CIMValue outParamValue = outParams[0].getValue(); PEGASUS_TEST_ASSERT(outParamValue.isArray()); PEGASUS_TEST_ASSERT(!outParamValue.isNull()); Array<CIMInstance> instances; outParamValue.get(instances); for (unsigned int j = 0; j < instances.size () ; ++j) { outputInstance = instances[j]; PEGASUS_TEST_ASSERT(objPath.toString() == outputInstance.getPath().toString()); PEGASUS_TEST_ASSERT(outputInstance.getPropertyCount() == eObjs[j].getPropertyCount()); for(unsigned int i = 0, n = outputInstance.getPropertyCount(); i < n; ++i) { CIMProperty outputProp(outputInstance.getProperty(i)); CIMProperty inputProp(eObjs[j].getProperty(i)); PEGASUS_TEST_ASSERT(outputProp.getName() == inputProp.getName()); PEGASUS_TEST_ASSERT(outputProp.getValue() == inputProp.getValue()); } } outParamValue = outParams[1].getValue(); PEGASUS_TEST_ASSERT(outParamValue.isArray()); PEGASUS_TEST_ASSERT(!outParamValue.isNull()); Array<CIMObject> objs; outParamValue.get(objs); for (unsigned int j = 0; j < objs.size () ; ++j) { outputInstance = CIMInstance(objs[j]); PEGASUS_TEST_ASSERT(objPath.toString() == outputInstance.getPath().toString()); PEGASUS_TEST_ASSERT(outputInstance.getPropertyCount() == eObjs[j].getPropertyCount()); for(unsigned int i = 0, n = outputInstance.getPropertyCount(); i < n; ++i) { CIMProperty outputProp(outputInstance.getProperty(i)); CIMProperty inputProp(eObjs[j].getProperty(i)); PEGASUS_TEST_ASSERT(outputProp.getName() == inputProp.getName()); PEGASUS_TEST_ASSERT(outputProp.getValue() == inputProp.getValue()); } } outParamValue = outParams[2].getValue(); PEGASUS_TEST_ASSERT(outParamValue.isArray()); PEGASUS_TEST_ASSERT(!outParamValue.isNull()); outParamValue.get(objs); for (Uint32 j = 0, m = objs.size(); j < m ; ++j) { outputInstance = CIMInstance(objs[j]); Uint32 id; CIMInstance emInstance; CIMObject emObject; outputInstance.getProperty( outputInstance.findProperty("id")).getValue().get(id); outputInstance.getProperty( outputInstance.findProperty("emInstance")). getValue().get(emInstance); outputInstance.getProperty( outputInstance.findProperty("emObject")).getValue().get(emObject); PEGASUS_TEST_ASSERT(eObjs[j].identical(emInstance)); PEGASUS_TEST_ASSERT(eObjs[j].identical(CIMInstance(emObject))); PEGASUS_TEST_ASSERT(id == j+1); } }
boost::shared_ptr< LogicalQueryPlanNode> Optimizer::logicalRewriteIfNeeded(const boost::shared_ptr<Query>& query, boost::shared_ptr< LogicalQueryPlanNode> instance) { //rewrite load(array,'filename') into store(input(array,'filename'),array) //Note: this rewrite mechanism should be // 1. generic // 2. user-extensible //Note: optimizer also performs rewrites like "sum" -> "sum2(sum)" but we can't do these here because: // 1. they are physical; not logical // 2. they are recursive. We don't want logical rewrites to be recursive. OperatorLibrary *olib = OperatorLibrary::getInstance(); if (instance->getLogicalOperator()->getLogicalName()=="load") { boost::shared_ptr< LogicalOperator> loadOperator = instance->getLogicalOperator(); LogicalOperator::Parameters loadParameters = loadOperator->getParameters(); ArrayDesc outputSchema = loadOperator->getSchema(); boost::shared_ptr< LogicalOperator> inputOperator = olib->createLogicalOperator("input"); inputOperator->setParameters(loadParameters); inputOperator->setSchema(outputSchema); boost::shared_ptr< OperatorParam> paramArrayName = loadParameters[0]; if ( query->getInstancesCount() == 1) { boost::shared_ptr< LogicalOperator> storeOperator = olib->createLogicalOperator("store"); storeOperator->addParameter(paramArrayName); std::vector< ArrayDesc> storeInputSchemas; storeInputSchemas.push_back(inputOperator->getSchema()); storeOperator->setSchema(storeOperator->inferSchema(storeInputSchemas, query)); boost::shared_ptr< LogicalQueryPlanNode> inputInstance( new LogicalQueryPlanNode (instance->getParsingContext(), inputOperator)); boost::shared_ptr< LogicalQueryPlanNode> storeInstance( new LogicalQueryPlanNode (instance->getParsingContext(), storeOperator)); //load instance does not have any children. so the input instance will also have none. assert(instance->getChildren().size()==0); storeInstance->addChild(inputInstance); return storeInstance; } else { LogicalOperator::Parameters sgParams(3); Value ival(TypeLibrary::getType(TID_INT32)); ival.setInt32(psRoundRobin); sgParams[0] = boost::shared_ptr<OperatorParam>( new OperatorParamLogicalExpression(instance->getParsingContext(), boost::shared_ptr<LogicalExpression>(new Constant(instance->getParsingContext(), ival, TID_INT32)), TypeLibrary::getType(TID_INT32), true)); ival.setInt32(-1); sgParams[1] = boost::shared_ptr<OperatorParam>( new OperatorParamLogicalExpression(instance->getParsingContext(), boost::shared_ptr<LogicalExpression>(new Constant(instance->getParsingContext(), ival, TID_INT32)), TypeLibrary::getType(TID_INT32), true)); sgParams[2] = paramArrayName; boost::shared_ptr< LogicalOperator> sgOperator = olib->createLogicalOperator("sg"); sgOperator->setParameters(sgParams); std::vector< ArrayDesc> sgInputSchemas; sgInputSchemas.push_back(inputOperator->getSchema()); sgOperator->setSchema(sgOperator->inferSchema(sgInputSchemas,query)); boost::shared_ptr< LogicalQueryPlanNode> inputInstance( new LogicalQueryPlanNode (instance->getParsingContext(), inputOperator)); boost::shared_ptr< LogicalQueryPlanNode> sgInstance( new LogicalQueryPlanNode (instance->getParsingContext(), sgOperator)); //load instance does not have any children. so the input instance will also have none. assert(instance->getChildren().size()==0); sgInstance->addChild(inputInstance); return sgInstance; } } else if (instance->getLogicalOperator()->getLogicalName()=="sum" || instance->getLogicalOperator()->getLogicalName()=="avg" || instance->getLogicalOperator()->getLogicalName()=="min" || instance->getLogicalOperator()->getLogicalName()=="max" || instance->getLogicalOperator()->getLogicalName()=="stdev" || instance->getLogicalOperator()->getLogicalName()=="var" || instance->getLogicalOperator()->getLogicalName()=="count") { boost::shared_ptr< LogicalOperator> oldStyleOperator = instance->getLogicalOperator(); boost::shared_ptr< LogicalOperator> aggOperator = olib->createLogicalOperator("aggregate"); aggOperator->setSchema(oldStyleOperator->getSchema()); LogicalOperator::Parameters oldStyleParams = oldStyleOperator->getParameters(); if (instance->getLogicalOperator()->getLogicalName()=="count") { shared_ptr<OperatorParam> asterisk (new OperatorParamAsterisk(instance->getParsingContext())); shared_ptr<OperatorParam> aggCall ( new OperatorParamAggregateCall (instance->getParsingContext(), instance->getLogicalOperator()->getLogicalName(), asterisk, "")); aggOperator->addParameter(aggCall); } else if (oldStyleParams.size() == 0) { ArrayDesc const& inputSchema = instance->getChildren()[0]->getLogicalOperator()->getSchema(); shared_ptr<OperatorParamReference> attRef ( new OperatorParamAttributeReference(instance->getParsingContext(), inputSchema.getName(), inputSchema.getAttributes()[0].getName(), true)); attRef->setInputNo(0); attRef->setObjectNo(0); shared_ptr<OperatorParam> aggCall ( new OperatorParamAggregateCall (instance->getParsingContext(), instance->getLogicalOperator()->getLogicalName(), attRef, "")); aggOperator->addParameter(aggCall); } for (size_t i =0; i<oldStyleParams.size(); i++) { if (oldStyleParams[i]->getParamType() == PARAM_ATTRIBUTE_REF) { shared_ptr<OperatorParam> aggCall ( new OperatorParamAggregateCall (oldStyleParams[i]->getParsingContext(), instance->getLogicalOperator()->getLogicalName(), oldStyleParams[i], "")); aggOperator->addParameter(aggCall); } else if (oldStyleParams[i]->getParamType() == PARAM_DIMENSION_REF) { aggOperator->addParameter(oldStyleParams[i]); } } boost::shared_ptr< LogicalQueryPlanNode> aggInstance( new LogicalQueryPlanNode (instance->getParsingContext(), aggOperator)); assert(instance->getChildren().size() == 1); aggInstance->addChild(instance->getChildren()[0]); return aggInstance; } else { return instance; } }
/** * This tests the embedded instance functionality through the CMPI Test * Method Provider. It first invokes the returnInstance() method to retrieve * an instance that can be used */ void test09 (CIMClient & client) { CIMObjectPath instanceName; instanceName.setNameSpace (providerNamespace); instanceName.setClassName (CLASSNAME); Array < CIMParamValue > inParams; Array < CIMParamValue > outParams; /* [EmbeddedObject] String returnInstance(); */ CIMValue retValue = client.invokeMethod (providerNamespace, instanceName, "returnInstance", inParams, outParams); PEGASUS_TEST_ASSERT (retValue.getType () == CIMTYPE_OBJECT); PEGASUS_TEST_ASSERT (!retValue.isArray ()); PEGASUS_TEST_ASSERT (!retValue.isNull ()); CIMObject result; retValue.get (result); CIMObjectPath objPath = result.getPath(); CIMInstance inputInstance(result); CIMInstance outputInstance; inParams.append( CIMParamValue(String("inputInstance"), CIMValue(inputInstance))); retValue = client.invokeMethod (providerNamespace, instanceName, "processEmbeddedInstance", inParams, outParams); // First test the return value PEGASUS_TEST_ASSERT(retValue.getType() == CIMTYPE_INSTANCE); PEGASUS_TEST_ASSERT(!retValue.isArray()); PEGASUS_TEST_ASSERT(!retValue.isNull()); retValue.get(outputInstance); PEGASUS_TEST_ASSERT(objPath.toString() == outputInstance.getPath().toString()); PEGASUS_TEST_ASSERT(outputInstance.getPropertyCount() == inputInstance.getPropertyCount()); for(unsigned int i = 0, n = outputInstance.getPropertyCount(); i < n; ++i) { CIMProperty outputProp(outputInstance.getProperty(i)); CIMProperty inputProp(inputInstance.getProperty(i)); PEGASUS_TEST_ASSERT(outputProp.getName() == inputProp.getName()); PEGASUS_TEST_ASSERT(outputProp.getValue() == inputProp.getValue()); } // Now test the output parameter PEGASUS_TEST_ASSERT(outParams.size() == 1); retValue = outParams[0].getValue(); PEGASUS_TEST_ASSERT(retValue.getType() == CIMTYPE_INSTANCE); PEGASUS_TEST_ASSERT(!retValue.isArray()); PEGASUS_TEST_ASSERT(!retValue.isNull()); retValue.get(outputInstance); PEGASUS_TEST_ASSERT(objPath.toString() == outputInstance.getPath().toString()); PEGASUS_TEST_ASSERT(outputInstance.getPropertyCount() == inputInstance.getPropertyCount()); for(unsigned int i = 0, n = outputInstance.getPropertyCount(); i < n; ++i) { CIMProperty outputProp(outputInstance.getProperty(i)); CIMProperty inputProp(inputInstance.getProperty(i)); PEGASUS_TEST_ASSERT(outputProp.getName() == inputProp.getName()); PEGASUS_TEST_ASSERT(outputProp.getValue() == inputProp.getValue()); } }