Esempio n. 1
0
/** Initialize worker thread communication resources.
 * 
 * @param[in] ws - a pointer to a worker thread's status data structure.
 * 
 * @return Zero on success, or a non-zero error value.
 */
static int initWorkerComm(DnxWorkerStatus * ws)
{
   char szChanDisp[64];
   char szChanColl[64];
   int ret;

   // create a channel for sending job requests (named after its memory address)
   sprintf(szChanDisp, "Dispatch:%lx", ws);
   if ((ret = dnxChanMapAdd(szChanDisp, ws->iwlm->cfg.dispatcher)) != DNX_OK)
   {
      dnxLog("WLM: Failed to initialize dispatcher channel: %s.", dnxErrorString(ret));
      return ret;
   }
   if ((ret = dnxConnect(szChanDisp, 1, &ws->dispatch)) != DNX_OK)
   {
      dnxLog("WLM: Failed to open dispatcher channel: %s.", dnxErrorString(ret));
      dnxChanMapDelete(szChanDisp);
      return ret;
   }

   // create a channel for sending job results (named after its memory address)
   sprintf(szChanColl, "Collect:%lx", ws);
   if ((ret = dnxChanMapAdd(szChanColl, ws->iwlm->cfg.collector)) != DNX_OK)
   {
      dnxLog("WLM: Failed to initialize collector channel: %s.", dnxErrorString(ret));
      dnxDisconnect(ws->dispatch);
      dnxChanMapDelete(szChanDisp);
      return ret;
   }
   if ((ret = dnxConnect(szChanColl, 1, &ws->collect)) != DNX_OK)
   {
      dnxLog("WLM: Failed to open collector channel: %s.", dnxErrorString(ret));
      dnxChanMapDelete(szChanColl);
      dnxDisconnect(ws->dispatch);
      dnxChanMapDelete(szChanDisp);
      return ret;
   }
   return 0;
}
Esempio n. 2
0
int dnxInitAgent(char * agentUrl, DnxCfgParser * parser)
{
   int ret;

   s_shutdown = 0;
   s_agentTid = 0;
   s_parser = parser;

   if ((ret = dnxChanMapAdd(s_agentName, agentUrl)) != DNX_OK)
      dnxLog("AGENT channel init failed: %s.", dnxErrorString(ret));
   else if ((ret = dnxConnect(s_agentName, DNX_MODE_PASSIVE, &s_agent)) != DNX_OK)
   {
      dnxLog("AGENT channel connect failed: %s.", dnxErrorString(ret));
      dnxChanMapDelete(s_agentName);
   }
   else if ((ret = pthread_create(&s_agentTid, 0, dnxAgentServer, 0)) != 0)
   {
      dnxLog("AGENT server init failed: %s.", strerror(ret));
      dnxDisconnect(s_agent);
      dnxChanMapDelete(s_agentName);
      ret = DNX_ERR_THREAD;
   }
   return ret;
}
Esempio n. 3
0
/** The main program entry point for the dnx management client.
 * 
 * @param[in] argc - the number of elements in the @p argv array.
 * @param[in] argv - a null-terminated array of command-line arguments.
 * 
 * @return Zero on success, or a non-zero error code that is returned to the
 * shell. Any non-zero codes should be values between 1 and 127.
 */
int main(int argc, char ** argv)
{
   extern char * optarg;
   extern int optind, opterr, optopt;
   gTopDCS = dnxComStatCreateDCS("127.0.0.1");
   int ch, ret;
   char * cp, * prog, * cmdstr;
   char * hoststr, * portstr;

   // get program base name
   prog = (char *)((cp = strrchr(argv[0], '/')) != 0 ? (cp + 1) : argv[0]);

   // parse arguments
   hoststr = "localhost";
   portstr = "12482";
   opterr = 0;
   cmdstr = 0;
   while ((ch = getopt(argc, argv, "hvc:s:p:")) != -1)
   {
      switch (ch)
      {
         case 's':
            hoststr = optarg;
            break;

         case 'p':
            portstr = optarg;
            break;

         case 'c': 
            cmdstr = optarg; 
            break;

         case 'v':
            printf("\n  %s version %s\n  Bug reports: %s.\n\n", 
                  prog, VERSION, PACKAGE_BUGREPORT);
            exit(0);

         case 'h': 
         default :
            usage(prog);
      }
   }

   // ensure we've been given a command
   if (!cmdstr)
   {
      fprintf(stderr, "%s: No command string specified.\n", prog);
      usage(prog);
   }

   // init comm sub-system; send command; wait for response
   if ((ret = dnxChanMapInit(0)) != 0)
      fprintf(stderr, "%s: Error initializing channel map: %s.\n", 
            prog, dnxErrorString(ret));
   else
   {
      char url[1024];

      snprintf(url, sizeof url, "udp://%s:%s", hoststr, portstr);

      if ((ret = dnxChanMapAdd("MgmtClient", url)) != 0)
         fprintf(stderr, "%s: Error adding channel (%s): %s.\n", 
               prog, url, dnxErrorString(ret));
      else
      {
         DnxChannel * channel;

         if ((ret = dnxConnect("MgmtClient", 1, &channel)) != 0)
            fprintf(stderr, "%s: Error connecting to server (%s): %s.\n", 
                  prog, url, dnxErrorString(ret));
         else
         {
            DnxMgmtRequest req;

            memset(&req, 0, sizeof req);
            dnxMakeXID(&req.xid, DNX_OBJ_MANAGER, 0, 0);
            req.action = cmdstr;

            if ((ret = dnxSendMgmtRequest(channel, &req, 0)) != 0)
               fprintf(stderr, "%s: Error sending request: %s.\n", 
                     prog, dnxErrorString(ret));
            else
            {
               DnxMgmtReply rsp;

               if ((ret = dnxWaitForMgmtReply(channel, &rsp, 0, 10)) != 0)
                  fprintf(stderr, "%s: Error receiving response: %s.\n", 
                        prog, dnxErrorString(ret));
               else
               {
                  if (rsp.status == DNX_REQ_ACK)
                     printf("%s\n", rsp.reply);
                  else
                     fprintf(stderr, "%s: Request failed on server.\nResponse was (%s)\n", prog,rsp.reply);
      
               }
            }
            dnxDisconnect(channel);
         }
         dnxChanMapDelete("MgmtClient");
      }
      dnxChanMapRelease();
   }

   xheapchk();

   return ret? -1: 0;
}