Skip to content

Commit

Permalink
fixed all the necessary to remove bug on ChaosCLI with the new mds
Browse files Browse the repository at this point in the history
  • Loading branch information
Claudio authored and Claudio committed Jul 16, 2015
1 parent 0b6fad1 commit 1f77226
Show file tree
Hide file tree
Showing 29 changed files with 406 additions and 132 deletions.
10 changes: 5 additions & 5 deletions CHAOSFramework.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -3294,17 +3294,17 @@
32C7B8FA16DD35D7005B3B21 /* api */ = {
isa = PBXGroup;
children = (
325D2FD91AFB65DE00B2A706 /* healt */,
324EF3DA1AE922B1000837AF /* data_service */,
32362C171ADC0FA1000CA079 /* control_unit */,
328E77FC1A7A937D0008C070 /* node */,
3235FDC41A6FF40100EC83A9 /* unit_server */,
328E78051A7A9FE40008C070 /* AbstractApi.cpp */,
32FC7EE11A701BE40029C2A2 /* AbstractApi.h */,
328E78031A7A9F430008C070 /* AbstractApiGroup.cpp */,
32FC7EE21A701D8E0029C2A2 /* AbstractApiGroup.h */,
32FC7EE31A70FDB70029C2A2 /* ApiManagment.cpp */,
32FC7EE41A70FDB70029C2A2 /* ApiManagment.h */,
325D2FD91AFB65DE00B2A706 /* healt */,
324EF3DA1AE922B1000837AF /* data_service */,
32362C171ADC0FA1000CA079 /* control_unit */,
328E77FC1A7A937D0008C070 /* node */,
3235FDC41A6FF40100EC83A9 /* unit_server */,
);
path = api;
sourceTree = "<group>";
Expand Down
2 changes: 1 addition & 1 deletion ChaosMetadataService/api/AbstractApi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ NamedService(name),
subservice(NULL){}

//default destructor
AbstractApi::~AbstractApi(){}
AbstractApi::~AbstractApi(){deinit();}

void AbstractApi::init(void *init_data) throw (chaos::CException) {
subservice = static_cast<ApiSubserviceAccessor*>(init_data);
Expand Down
4 changes: 4 additions & 0 deletions ChaosMetadataService/api/AbstractApi.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,16 +35,20 @@ namespace chaos {
x *v = getPersistenceDriver()->getDataAccess<x>();\
if(v == NULL) throw CException(err, "Error allocating " #x, __PRETTY_FUNCTION__);

class AbstractApiGroup;

//! Api abstraction
/*!
This class define the rule for the api development
*/
class AbstractApi:
public chaos::common::utility::NamedService,
public chaos::common::utility::InizializableService {
friend class AbstractApiGroup;
//! the instace of the persistence driver
ApiSubserviceAccessor *subservice;

AbstractApiGroup *parent_group;
protected:
service_common::persistence::data_access::AbstractPersistenceDriver *getPersistenceDriver();
batch::MDSBatchExecutor *getBatchExecutor();
Expand Down
21 changes: 13 additions & 8 deletions ChaosMetadataService/api/AbstractApiGroup.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,21 +37,26 @@ void AbstractApiGroup::init(void *init_data) throw (chaos::CException) {
it != api_instance.end();
it++) {
boost::shared_ptr<AbstractApi> api = *it;

//initilize api
InizializableService::initImplementation(api.get(),
static_cast<void*>(subservice),
api->getName(),
__PRETTY_FUNCTION__);
//connect parent group to api
api->parent_group = this;
}
}

void AbstractApiGroup::deinit() throw (chaos::CException) {
for(ApiListIterator it = api_instance.begin();
it != api_instance.end();
it++) {
boost::shared_ptr<AbstractApi> api = *it;
InizializableService::deinitImplementation(api.get(),
api->getName(),
__PRETTY_FUNCTION__);
}
//the deinit phase is called into destructor of api class
// for(ApiListIterator it = api_instance.begin();
// it != api_instance.end();
// it++) {
// boost::shared_ptr<AbstractApi> api = *it;
// InizializableService::deinitImplementation(api.get(),
// api->getName(),
// __PRETTY_FUNCTION__);
// }

}
30 changes: 26 additions & 4 deletions ChaosMetadataService/api/AbstractApiGroup.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
#include <chaos/common/utility/ObjectInstancer.h>
#include <chaos/common/action/DeclareAction.h>
#include <chaos/common/utility/ObjectFactoryRegister.h>

#include <chaos/common/chaos_types.h>
#include <vector>

#include <boost/shared_ptr.hpp>
Expand All @@ -37,18 +37,39 @@ namespace chaos {
namespace metadata_service {
namespace api {

typedef std::vector< boost::shared_ptr<AbstractApi> > ApiList;
typedef std::vector< boost::shared_ptr<AbstractApi> >::iterator ApiListIterator;

CHAOS_DEFINE_VECTOR_FOR_TYPE(boost::shared_ptr<AbstractApi>, ApiList)

class AbstractApiGroup:
public common::utility::NamedService,
public chaos::common::utility::InizializableService,
public chaos::DeclareAction {
friend class AbstractApi;
//! the instace of the persistence driver
ApiSubserviceAccessor *subservice;

//! list of all installed api in the group
ApiList api_instance;
protected:
//! install a class as api
/*!
The alias of the action to be call si got by api itself
*/
template<typename T>
boost::shared_ptr<T> getNewApiInstance() {
//allcoate the instsancer for the AbstractApi depending by the template
std::auto_ptr<INSTANCER(T, AbstractApi)> i(ALLOCATE_INSTANCER(T, AbstractApi));

//get api instance
boost::shared_ptr<T> instance((T*)i->getInstance());
if(instance.get()) {
//we have an instance so we can initilize it
InizializableService::initImplementation(instance.get(),
static_cast<void*>(subservice),
instance->getName(),
__PRETTY_FUNCTION__);
}
}

public:
AbstractApiGroup(const std::string& name);

Expand Down Expand Up @@ -76,6 +97,7 @@ namespace chaos {
}
}


void init(void *init_data) throw (chaos::CException);

void deinit() throw (chaos::CException);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ using namespace chaos::metadata_service::api::data_service;
DEFINE_CLASS_FACTORY_NO_ALIAS(DataServiceApiGroup, chaos::metadata_service::api::AbstractApiGroup);

DataServiceApiGroup::DataServiceApiGroup():
AbstractApiGroup("data_service"){
AbstractApiGroup(DataServiceNodeDomainAndActionRPC::RPC_DOMAIN){
//add api for DataService api
addApi<NewDS>();
addApi<UpdateDS>();
Expand Down
2 changes: 1 addition & 1 deletion ChaosMetadataService/api/node/NodeGroup.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ using namespace chaos::metadata_service::api::node;
DEFINE_CLASS_FACTORY_NO_ALIAS(NodeGroup, chaos::metadata_service::api::AbstractApiGroup);

NodeGroup::NodeGroup():
AbstractApiGroup("system"){
AbstractApiGroup(NodeDomainAndActionRPC::RPC_DOMAIN){
//add api for UnitServer registration
addApi<NodeSearch>();
addApi<NodeRegister>();
Expand Down
1 change: 1 addition & 0 deletions ChaosMetadataService/api/node/NodeRegister.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ namespace chaos {
//! perform registration for specific unit server
chaos::common::data::CDataWrapper *unitServerRegistration(chaos::common::data::CDataWrapper *api_data,
bool& detach_data) throw(chaos::CException);

//! perform specific registration for control unit
chaos::common::data::CDataWrapper *controlUnitRegistration(chaos::common::data::CDataWrapper *api_data,
bool& detach_data) throw(chaos::CException);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ DEFINE_CLASS_FACTORY_NO_ALIAS(UnitServerApiGroup,
chaos::metadata_service::api::AbstractApiGroup);

UnitServerApiGroup::UnitServerApiGroup():
AbstractApiGroup("unit_server"){
AbstractApiGroup(UnitServerNodeDomainAndActionRPC::RPC_DOMAIN){
//add api for producer registration
addApi<GetDescription>();
addApi<LoadUnloadControlUnit>();
Expand Down
128 changes: 109 additions & 19 deletions ChaosMetadataService/batch/unit_server/UnitServerAckBatchCommand.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,51 +31,141 @@ DEFINE_MDS_COMAMND_ALIAS(UnitServerAckCommand)

UnitServerAckCommand::UnitServerAckCommand():
MDSBatchCommand(),
message_data(NULL){
message_data(NULL),
phase(USAP_ACK_US){
//set default scheduler delay 1 second
setFeatures(common::batch_command::features::FeaturesFlagTypes::FF_SET_SCHEDULER_DELAY, (uint64_t)1000000);
setFeatures(common::batch_command::features::FeaturesFlagTypes::FF_SET_SCHEDULER_DELAY, (uint64_t)100000);
//set the timeout to 10 seconds
setFeatures(common::batch_command::features::FeaturesFlagTypes::FF_SET_COMMAND_TIMEOUT, (uint64_t)10000000);
//setFeatures(common::batch_command::features::FeaturesFlagTypes::FF_SET_COMMAND_TIMEOUT, (uint64_t)10000000);
}

UnitServerAckCommand::~UnitServerAckCommand() {}

// inherited method
void UnitServerAckCommand::setHandler(CDataWrapper *data) {
MDSBatchCommand::setHandler(data);
if(data && data->hasKey(chaos::NodeDefinitionKey::NODE_RPC_ADDR)) {
request = createRequest(data->getStringValue(chaos::NodeDefinitionKey::NODE_RPC_ADDR),
UnitServerNodeDomainAndActionRPC::RPC_DOMAIN,
UnitServerNodeDomainAndActionRPC::ACTION_UNIT_SERVER_REG_ACK);
message_data = data;
} else throw chaos::CException(-1, "No unit server address has been set", __PRETTY_FUNCTION__);
CHECK_CDW_THROW_AND_LOG(data, USAC_ERR, -1, "No parameter found")
CHECK_KEY_THROW_AND_LOG(data, chaos::NodeDefinitionKey::NODE_UNIQUE_ID, USAC_ERR, -2, "The unique id of unit server is mandatory")
CHECK_KEY_THROW_AND_LOG(data, chaos::NodeDefinitionKey::NODE_RPC_ADDR, USAC_ERR, -3, "The rpc address of unit server is mandatory")
//CHECK_KEY_THROW_AND_LOG(data, chaos::NodeDefinitionKey::NODE_RPC_DOMAIN, USAC_ERR, -4, "The rpc domain of unit server is mandatory")

unit_server_uid = data->getStringValue(chaos::NodeDefinitionKey::NODE_UNIQUE_ID);

request = createRequest(data->getStringValue(chaos::NodeDefinitionKey::NODE_RPC_ADDR),
UnitServerNodeDomainAndActionRPC::RPC_DOMAIN,
UnitServerNodeDomainAndActionRPC::ACTION_UNIT_SERVER_REG_ACK);
message_data = data;
}

// inherited method
void UnitServerAckCommand::acquireHandler() {
MDSBatchCommand::acquireHandler();
switch(phase) {
case USAP_ACK_US:
break;
case USAP_CU_AUTOLOAD:
break;
case USAP_CU_FECTH_NEXT:
break;
case USAP_END:
break;
}
}

// inherited method
void UnitServerAckCommand::ccHandler() {
MDSBatchCommand::ccHandler();
switch(request->phase) {
case MESSAGE_PHASE_UNSENT:
sendRequest(*request,
message_data);
int err = 0;
switch(phase) {
case USAP_ACK_US: {
switch(request->phase) {
case MESSAGE_PHASE_UNSENT:
sendRequest(*request,
message_data);
break;

case MESSAGE_PHASE_SENT:
manageRequestPhase(*request);
break;

case MESSAGE_PHASE_COMPLETED:{
//after terminate the control unit ack try to fetch cu autoload
phase = USAP_CU_FECTH_NEXT;
break;
}

case MESSAGE_PHASE_TIMEOUT:
//terminate job
BC_END_RUNNIG_PROPERTY
break;
}
break;
}
case USAP_CU_FECTH_NEXT: {
if(list_autoload_cu_current == list_autoload_cu.end()) {
if(!(err = getDataAccess<mds_data_access::ControlUnitDataAccess>()->getControlUnitWithAutoFlag(unit_server_uid,
chaos::metadata_service::persistence::AUTO_LOAD,
0,
list_autoload_cu))) {

if(list_autoload_cu.size() == 0) {
//terminate job
BC_END_RUNNIG_PROPERTY
} else {
//we need to check if
list_autoload_cu_current = list_autoload_cu.begin();
phase = USAP_CU_AUTOLOAD;

//terminate for testing
BC_END_RUNNIG_PROPERTY

break;
}
} else {
break;
}
} else {
list_autoload_cu_current++;
phase = USAP_CU_AUTOLOAD;

//terminate for testing
BC_END_RUNNIG_PROPERTY

break;
}
}

case MESSAGE_PHASE_SENT:
manageRequestPhase(*request);
break;
case USAP_CU_AUTOLOAD: {
switch(request->phase) {
case MESSAGE_PHASE_UNSENT:
sendRequest(*request,
message_data);
break;

case MESSAGE_PHASE_SENT:
manageRequestPhase(*request);
break;

case MESSAGE_PHASE_COMPLETED:{
//after terminate the control unit ack try to fetch cu autoload
phase = USAP_CU_FECTH_NEXT;
break;
}

case MESSAGE_PHASE_TIMEOUT:
//terminate job
BC_END_RUNNIG_PROPERTY
break;
}

case MESSAGE_PHASE_COMPLETED:
case MESSAGE_PHASE_TIMEOUT:{
BC_END_RUNNIG_PROPERTY
break;
}

case USAP_END: {
break;
}
}

}

// inherited method
Expand Down
14 changes: 14 additions & 0 deletions ChaosMetadataService/batch/unit_server/UnitServerAckBatchCommand.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
#define __CHAOSFramework__UnitServerAckCommand__

#include "../mds_service_batch.h"
#include <chaos/common/chaos_types.h>

namespace chaos {
namespace metadata_service{
Expand All @@ -29,14 +30,27 @@ namespace chaos {

namespace unit_server {

typedef enum UnitServerAckPhase {
USAP_ACK_US,
USAP_CU_AUTOLOAD,
USAP_CU_FECTH_NEXT,
USAP_END
} UnitServerAckPhase;

CHAOS_DEFINE_VECTOR_FOR_TYPE(chaos::metadata_service::persistence::NodeSearchIndex, AutoloadCUList)

class UnitServerAckCommand:
public metadata_service::batch::MDSBatchCommand {
DECLARE_MDS_COMMAND_ALIAS

std::string unit_server_uid;
UnitServerAckPhase phase;
std::auto_ptr<RequestInfo> request;
chaos::common::data::CDataWrapper *message_data;


AutoloadCUList list_autoload_cu;
AutoloadCUListIterator list_autoload_cu_current;
public:
UnitServerAckCommand();
~UnitServerAckCommand();
Expand Down
Loading

0 comments on commit 1f77226

Please sign in to comment.