Esempio n. 1
0
ListObject* QueryProxy<QueryParameters, ListObject>::list() {

  //If the query uses the machineId (machineId not null)
  diet_profile_t* profile =NULL;
  if (! mmachineId.empty()) {
    profile = diet_profile_alloc(mserviceName, 3);
  } else {
    profile = diet_profile_alloc(mserviceName, 2);
  }

  std::string queryParmetersToString =  SerializeAdaptor<QueryParameters>::serialize(mparameters);

  // Set parameters
  diet_string_set(profile, 0, msessionProxy.getSessionKey());

  if (! mmachineId.empty()) {
    diet_string_set(profile, 1, mmachineId);
    diet_string_set(profile, 2, queryParmetersToString);
  } else {
    diet_string_set(profile, 1, queryParmetersToString);
  }

  if (diet_call(profile)) {
    raiseCommunicationMsgException("RPC call failed");
  }
  raiseExceptionOnErrorResult(profile);

  std::string listObjectInString;

  diet_string_get(profile,1, listObjectInString);
  parseEmfObject(listObjectInString, mlistObject, "Error by receiving List object serialized");

  return mlistObject;
}
Esempio n. 2
0
/**
 * \brief Function to change user password
 * \fn  int changePassword(const std::string& password, const std::string& newPassword)
 * \param oldPassword the old password of the user
 * \param newPassword the new password of the user
 * \return raises an exception on error
 */
int UserProxy::changePassword(const std::string& password, const std::string& newPassword)
{

  diet_profile_t* profile = NULL;
  char* errorInfo;
  std::string msg = "call of function diet_string_set is rejected ";
  std::string versionToString;

  UMS_Data::Version_ptr versionObj = vishnu::parseVersion(VISHNU_VERSION);
  if (versionObj == NULL) {
    throw UMSVishnuException(ERRCODE_INVALID_PARAM, "The format of the VISHNU VERSION is incorrect");
  } else {
    // SERIALIZE DATA MODEL
    ::ecorecpp::serializer::serializer _ser;
    //To serialize the version object in to versionToString
    versionToString =  _ser.serialize_str(versionObj);
  }
  profile = diet_profile_alloc("userPasswordChange", 3, 3, 4);

  //IN Parameters
  if(diet_string_set(diet_parameter(profile,0), strdup((muser.getUserId()).c_str()), DIET_VOLATILE)) {
    msg += "with sessionKey parameter "+msessionProxy->getSessionKey();
    raiseDietMsgException(msg);
  }

  if(diet_string_set(diet_parameter(profile,1), strdup(password.c_str()), DIET_VOLATILE)) {
    msg += "with password parameter "+password;
    raiseDietMsgException(msg);
  }

  if(diet_string_set(diet_parameter(profile,2), strdup(newPassword.c_str()), DIET_VOLATILE)) {
    msg += "with newPassword parameter "+newPassword;
    raiseDietMsgException(msg);
  }

  if(diet_string_set(diet_parameter(profile,3), strdup(versionToString.c_str()), DIET_VOLATILE)) {
      msg += "with version parameter "+versionToString;
      raiseDietMsgException(msg);
  }

  //OUT Parameters
  diet_string_set(diet_parameter(profile,4), NULL, DIET_VOLATILE);

  if(!diet_call(profile)) {
    if(diet_string_get(diet_parameter(profile,4), &errorInfo, NULL)){
      msg += "by receiving errorInfo message";
      raiseDietMsgException(msg);
    }
  }
  else {
    raiseDietMsgException("DIET call failure");
  }
  /*To raise a vishnu exception if the receiving message is not empty*/
  raiseExceptionIfNotEmptyMsg(errorInfo);

  diet_profile_free(profile);
  delete versionObj;

  return 0;
}
Esempio n. 3
0
/**
 * \brief Function to change user password
 * \param oldPassword the old password of the user
 * \param newPassword the new password of the user
 * \return raises an exception on error
 */
int
UserProxy::changePassword(const std::string& password,
                          const std::string& newPassword) {

    std::string errorInfo;
    std::string msg = "call of function diet_string_set is rejected ";
    std::string versionToString;

    UMS_Data::Version_ptr versionObj = vishnu::parseVersion(VISHNU_VERSION);
    if (versionObj == NULL) {
        throw UMSVishnuException(ERRCODE_INVALID_PARAM, "The format of the VISHNU VERSION is incorrect");
    } else {
        // SERIALIZE DATA MODEL
        ::ecorecpp::serializer::serializer _ser;
        //To serialize the version object in to versionToString
        versionToString =  _ser.serialize_str(versionObj);
    }

    diet_profile_t* profile = diet_profile_alloc(SERVICES_UMS[USERPASSWORDCHANGE], 4);
    diet_string_set(profile,0, muser.getUserId());
    diet_string_set(profile,1, password);
    diet_string_set(profile,2, newPassword);
    diet_string_set(profile,3, versionToString);

    if (diet_call(profile)) {
        raiseCommunicationMsgException("RPC call failed");
    }
    raiseExceptionOnErrorResult(profile);

    diet_profile_free(profile);
    delete versionObj;

    return 0;
}
Esempio n. 4
0
  /**
   * \brief Main loop. receives data and deal with it if it isn't empty
   * Uses protected method doCall to provide implementation specific
   * behavior when recieving data.
   */
  void
  operator()() {
    Socket socket(*ctx_, ZMQ_REP);
    socket.connect(uriInproc_.c_str());
    std::string data;

    while (true) {
      //vishnu::exitProcessIfAnyZombieChild(-1);
      data.clear();
      try {
        data = socket.get();
      } catch (zmq::error_t &error) {
        LOG(boost::str(boost::format("[ERROR] %1%\n") % error.what()), LogErr);
        continue;
      }

      // Deserialize and call Method
      if (! data.empty()) {
        try {
          std::string resultSerialized = doCall(data);
          socket.send(resultSerialized);
        } catch (const VishnuException& ex) {
          diet_profile_t* profile = diet_profile_alloc("docall", 2);
          diet_string_set(profile, 0, "error");
          diet_string_set(profile, 1, ex.what());
          socket.send(JsonObject::serialize(profile));
          diet_profile_free(profile);
          LOG(boost::str(boost::format("[ERROR] %1%\n")%ex.what()), LogErr);
        }
      }
    }
  }
Esempio n. 5
0
/**
 * \brief Function to add new user
 * \param user The object which encapsulates the user information
 * \return raises an exception on error
 */
int
UserProxy::add(UMS_Data::User& user) {

    std::string sessionKey;
    std::string userInString;

    diet_profile_t* profile = diet_profile_alloc(SERVICES_UMS[USERCREATE], 2);
    sessionKey = msessionProxy->getSessionKey();

    ::ecorecpp::serializer::serializer _ser;
    //To serialize the user object in to userToString
    std::string userToString =  _ser.serialize_str(const_cast<UMS_Data::User_ptr>(&user));
    //IN Parameters
    diet_string_set(profile, 0, msessionProxy->getSessionKey());
    diet_string_set(profile, 1, userToString);

    if (diet_call(profile)) {
        raiseCommunicationMsgException("RPC call failed");
    }
    raiseExceptionOnErrorResult(profile);

    diet_string_get(profile,1, userInString);

    //To parse User object serialized
    UMS_Data::User_ptr user_ptr;
    parseEmfObject(userInString, user_ptr, "Error by receiving User object serialized");
    user = *user_ptr;
    muser = user;
    delete user_ptr;

    diet_profile_free(profile);

    return 0;
}
Esempio n. 6
0
/**
 * \brief Function to add new user
 * \fn  int add(UMS_Data::User& user)
 * \param user The object which encapsulates the user information
 * \return raises an exception on error
 */
int UserProxy::add(UMS_Data::User& user)
{
  diet_profile_t* profile = NULL;
  std::string sessionKey;
  char* userToString;
  char* errorInfo;
  char* userInString;
  std::string msg = "call of function diet_string_set is rejected ";

  profile = diet_profile_alloc("userCreate", 1, 1, 3);
  sessionKey = msessionProxy->getSessionKey();

  ::ecorecpp::serializer::serializer _ser;
  //To serialize the user object in to userToString
  userToString =  strdup(_ser.serialize_str(const_cast<UMS_Data::User_ptr>(&user)).c_str());
  //IN Parameters
  if(diet_string_set(diet_parameter(profile,0), strdup(sessionKey.c_str()), DIET_VOLATILE)) {
    msg += "with sessionKey parameter "+sessionKey;
    raiseDietMsgException(msg);
  }
  if(diet_string_set(diet_parameter(profile,1), userToString, DIET_VOLATILE)) {
    msg += "with userToString parameter "+std::string(userToString);
    raiseDietMsgException(msg);
  }

  //OUT Parameters
  diet_string_set(diet_parameter(profile,2), NULL, DIET_VOLATILE);
  diet_string_set(diet_parameter(profile,3), NULL, DIET_VOLATILE);

  if(!diet_call(profile)) {
    if(diet_string_get(diet_parameter(profile,2), &userInString, NULL)){
      msg += " by receiving User serialized  message";
      raiseDietMsgException(msg);
    }
    if(diet_string_get(diet_parameter(profile,3), &errorInfo, NULL)){
      msg += " by receiving errorInfo message";
      raiseDietMsgException(msg);
    }
  }
  else {
    raiseDietMsgException("DIET call failure");
  }

  /*To raise a vishnu exception if the receiving message is not empty*/
  raiseExceptionIfNotEmptyMsg(errorInfo);

  UMS_Data::User_ptr user_ptr;

  //To parse User object serialized
  parseEmfObject(std::string(userInString), user_ptr, "Error by receiving User object serialized");
  user = *user_ptr;
  muser = user;
  delete user_ptr;

  diet_profile_free(profile);

  return 0;
}
Esempio n. 7
0
/**
 * \brief Function to update machine description
 * \fn  int update()
 * \return raises an exception on error
 */
int MachineProxy::update()
{
  diet_profile_t* updateProfile = NULL;
  std::string sessionKey;
  std::string machineToString;
  char* errorInfo;
  std::string msg = "call of function diet_string_set is rejected ";

  updateProfile = diet_profile_alloc("machineUpdate", 1, 1, 2);
  sessionKey = msessionProxy.getSessionKey();

  ::ecorecpp::serializer::serializer _ser;
  //To serialize the mmachine object in to machineToString
  machineToString =  _ser.serialize_str(const_cast<UMS_Data::Machine_ptr>(&mmachine));

  std::string sshKeyFilePath = mmachine.getSshPublicKey();
  if(sshKeyFilePath.find("\"")!=std::string::npos) {
    throw UMSVishnuException(ERRCODE_INVALID_PARAM, " The machine SshPublicKey contains special character double quote \"");
  }

  //IN Parameters
  if(diet_string_set(diet_parameter(updateProfile,0), strdup(sessionKey.c_str()), DIET_VOLATILE)) {
    msg += "with sessionKey parameter "+sessionKey;
    raiseDietMsgException(msg);
  }
  if(diet_string_set(diet_parameter(updateProfile,1), strdup(machineToString.c_str()), DIET_VOLATILE)) {
    msg += "with machineToString parameter "+machineToString;
    raiseDietMsgException(msg);
  }

  //OUT Parameters
  diet_string_set(diet_parameter(updateProfile,2), NULL, DIET_VOLATILE);

  if(!diet_call(updateProfile)) {
    if(diet_string_get(diet_parameter(updateProfile,2), &errorInfo, NULL)){
      msg += "by receiving errorInfo message";
      raiseDietMsgException(msg);
    }
  }
  else {
    raiseDietMsgException("DIET call failure");
  }

  /*To raise a vishnu exception if the receiving message is not empty*/
  raiseExceptionIfNotEmptyMsg(errorInfo);

  diet_profile_free(updateProfile);

  return 0;
}
Esempio n. 8
0
/**
 * \brief Function to reset user password
 * \fn  int resetPassword(UMS_Data::User& user)
 * \param user The object which encapsulates the user information
 * \return raises an exception on error
 */
int UserProxy::resetPassword(UMS_Data::User& user)
{

  diet_profile_t* profile = NULL;
  char* tmpPassword;
  char* errorInfo;
  std::string msg = "call of function diet_string_set is rejected ";

  profile = diet_profile_alloc("userPasswordReset", 1, 1, 3);

  //IN Parameters
  if(diet_string_set(diet_parameter(profile,0), strdup((msessionProxy->getSessionKey()).c_str()), DIET_VOLATILE)) {
    msg += "with sessionKey parameter "+msessionProxy->getSessionKey();
    raiseDietMsgException(msg);
  }

  if(diet_string_set(diet_parameter(profile,1), strdup((user.getUserId()).c_str()), DIET_VOLATILE)) {
    msg += "with userId parameter "+user.getUserId();
    raiseDietMsgException(msg);
  }

  //OUT Parameters
  diet_string_set(diet_parameter(profile,2), NULL, DIET_VOLATILE);
  diet_string_set(diet_parameter(profile,3), NULL, DIET_VOLATILE);

  if(!diet_call(profile)) {
    if(diet_string_get(diet_parameter(profile,2), &tmpPassword, NULL)){
      msg += "by receiving tmpPassWord message";
      raiseDietMsgException(msg);
    }
    if(diet_string_get(diet_parameter(profile,3), &errorInfo, NULL)){
      msg += "by receiving errorInfo message";
      raiseDietMsgException(msg);
    }
  }
  else {
    raiseDietMsgException("DIET call failure");
  }
  /*To raise a vishnu exception if the receiving message is not empty*/
  raiseExceptionIfNotEmptyMsg(errorInfo);

  /*To set the temporary password*/
  muser.setUserId(user.getUserId());
  muser.setPassword(std::string(tmpPassword));

  diet_profile_free(profile);

  return 0;
}
Esempio n. 9
0
/**
 * \brief Function to update an authentication system
 * \return raises an exception on error
 */
int
AuthSystemProxy::update() {
  diet_profile_t* profile = NULL;
  std::string sessionKey;
  std::string authSystemToString;
  char* errorInfo;
  std::string msg = "call of function diet_string_set is rejected ";

  profile = diet_profile_alloc("authSystemUpdate", 1, 1, 2);

  sessionKey = msessionProxy.getSessionKey();

  ::ecorecpp::serializer::serializer _ser;
  //To serialize the mauthSystem object in to authSystemToString
  authSystemToString =  _ser.serialize_str(const_cast<UMS_Data::AuthSystem_ptr>(&mauthSystem));

  //IN Parameters
  if(diet_string_set(diet_parameter(profile,0), strdup(sessionKey.c_str()), DIET_VOLATILE)) {
    msg += "with sessionKey parameter "+sessionKey;
    raiseDietMsgException(msg);
  }
  if(diet_string_set(diet_parameter(profile,1), strdup(authSystemToString.c_str()), DIET_VOLATILE)) {
    msg += "with authSystemToString parameter "+authSystemToString;
    raiseDietMsgException(msg);
  }

  //OUT Parameters
  diet_string_set(diet_parameter(profile,2), NULL, DIET_VOLATILE);

  if(!diet_call(profile)) {

    if(diet_string_get(diet_parameter(profile,2), &errorInfo, NULL)){
      msg += "by receiving errorInfo message";
      raiseDietMsgException(msg);
    }
  }
  else {
    raiseDietMsgException("DIET call failure");
  }

  /*To raise a vishnu exception if the receiving message is not empty*/
  raiseExceptionIfNotEmptyMsg(errorInfo);

  diet_profile_free(profile);

  return 0;
}
Esempio n. 10
0
/**
 * \brief Function to remove user information
 * \param user The object which encapsulates the user information
 * \return raises an exception on error
 */
int
UserProxy::deleteUser(const UMS_Data::User& user) {

    diet_profile_t* profile = diet_profile_alloc(SERVICES_UMS[USERDELETE], 2);

    //IN Parameters
    diet_string_set(profile, 0, msessionProxy->getSessionKey());
    diet_string_set(profile, 1, user.getUserId());

    if (diet_call(profile)) {
        raiseCommunicationMsgException("RPC call failed");
    }
    raiseExceptionOnErrorResult(profile);

    diet_profile_free(profile);

    return 0;
}
Esempio n. 11
0
/**
 * \brief Function to removes an authentication system
 * \return raises an exception on error
 */
int
AuthSystemProxy::deleteAuthSystem()
{
  diet_profile_t* profile = NULL;
  std::string sessionKey;
  std::string sysId;
  char* errorInfo;
  std::string msg = "call of function diet_string_set is rejected ";

  profile = diet_profile_alloc("authSystemDelete", 1, 1, 2);
  sessionKey = msessionProxy.getSessionKey();
  sysId = mauthSystem.getAuthSystemId();

  //IN Parameters
  if(diet_string_set(diet_parameter(profile,0), strdup(sessionKey.c_str()), DIET_VOLATILE)) {
    msg += "with sessionKey parameter "+sessionKey;
    raiseDietMsgException(msg);
  }
  if(diet_string_set(diet_parameter(profile,1), strdup(sysId.c_str()), DIET_VOLATILE)) {
    msg += "with systemId parameter "+sysId;
    raiseDietMsgException(msg);
  }

  //OUT Parameters
  diet_string_set(diet_parameter(profile,2), NULL, DIET_VOLATILE);

  if(!diet_call(profile)) {
    if(diet_string_get(diet_parameter(profile,2), &errorInfo, NULL)){
      msg += "by receiving errorInfo message";
      raiseDietMsgException(msg);
    }
  }
  else {
    raiseDietMsgException("DIET call failure");
  }

  /*To raise a vishnu exception if the receiving message is not empty*/
  raiseExceptionIfNotEmptyMsg(errorInfo);

  diet_profile_free(profile);

  return 0;
}
Esempio n. 12
0
/**
 * \brief Function to update user information
 * \param user The object which encapsulates the user information
 * \return raises an exception on error
 */
int
UserProxy::update(const UMS_Data::User& user) {

    diet_profile_t* profile = diet_profile_alloc(SERVICES_UMS[USERUPDATE], 2);
    //To serialize the user object in to userToString
    ::ecorecpp::serializer::serializer _ser;
    std::string userToString =  _ser.serialize_str(const_cast<UMS_Data::User_ptr>(&user));

    //IN Parameters
    diet_string_set(profile, 0, msessionProxy->getSessionKey());
    diet_string_set(profile, 1, userToString);

    if (diet_call(profile)) {
        raiseCommunicationMsgException("RPC call failed");
    }
    raiseExceptionOnErrorResult(profile);

    diet_profile_free(profile);
    return 0;
}
Esempio n. 13
0
/**
 * \brief Function to reset user password
 * \param user The object which encapsulates the user information
 * \return raises an exception on error
 */
int
UserProxy::resetPassword(UMS_Data::User& user) {

    diet_profile_t* profile = diet_profile_alloc(SERVICES_UMS[USERPASSWORDRESET], 2);
    diet_string_set(profile, 0, msessionProxy->getSessionKey());
    diet_string_set(profile, 1, user.getUserId());

    if (diet_call(profile)) {
        raiseCommunicationMsgException("RPC call failed");
    }
    raiseExceptionOnErrorResult(profile);

    std::string tmpPassword;
    diet_string_get(profile, 1, tmpPassword);

    /*To set the temporary password*/
    muser.setUserId(user.getUserId());
    muser.setPassword(tmpPassword);

    diet_profile_free(profile);

    return 0;
}