adb_ncStartNetworkResponse_t* ncStartNetworkMarshal (adb_ncStartNetwork_t* ncStartNetwork, const axutil_env_t *env) 
{
    pthread_mutex_lock(&ncHandlerLock);
    adb_ncStartNetworkType_t * input          = adb_ncStartNetwork_get_ncStartNetwork(ncStartNetwork, env);
    adb_ncStartNetworkResponse_t * response   = adb_ncStartNetworkResponse_create(env);
    adb_ncStartNetworkResponseType_t * output = adb_ncStartNetworkResponseType_create(env);

    // get standard fields from input
    axis2_char_t * correlationId = adb_ncStartNetworkType_get_correlationId(input, env);
    axis2_char_t * userId = adb_ncStartNetworkType_get_userId(input, env);

    // get operation-specific fields from input
    int port = adb_ncStartNetworkType_get_remoteHostPort(input, env);
    int vlan = adb_ncStartNetworkType_get_vlan(input, env);
    int peersLen = adb_ncStartNetworkType_sizeof_remoteHosts(input, env);
    char ** peers = malloc(sizeof(char *) * peersLen);
    int i;
    for (i=0; i<peersLen; i++) {
        peers[i] = adb_ncStartNetworkType_get_remoteHosts_at(input, env, i);
    }

    eventlog("NC", userId, correlationId, "StartNetwork", "begin");
    { // do it
        ncMetadata meta = { correlationId, userId };

        int error = doStartNetwork (&meta, peers, peersLen, port, vlan);

        if (error) {
            logprintfl (EUCAERROR, "ERROR: doStartNetwork() failed error=%d\n", error);
            adb_ncStartNetworkResponseType_set_return(output, env, AXIS2_FALSE);

            // set operation-specific fields in output
            adb_ncStartNetworkResponseType_set_networkStatus(output, env, "FAIL");
            adb_ncStartNetworkResponseType_set_statusMessage(output, env, 2);

        } else {
            // set standard fields in output
            adb_ncStartNetworkResponseType_set_return(output, env, AXIS2_TRUE);
            adb_ncStartNetworkResponseType_set_correlationId(output, env, correlationId);
            adb_ncStartNetworkResponseType_set_userId(output, env, userId);

            // set operation-specific fields in output
            adb_ncStartNetworkResponseType_set_networkStatus(output, env, "SUCCESS");
            adb_ncStartNetworkResponseType_set_statusMessage(output, env, 0);
        }

        if (peersLen) 
            free (peers);
    }

    // set response to output
    adb_ncStartNetworkResponse_set_ncStartNetworkResponse(response, env, output);
    pthread_mutex_unlock(&ncHandlerLock);
    
    eventlog("NC", userId, correlationId, "StartNetwork", "end");
    return response;
}
示例#2
0
adb_StartNetworkResponse_t *StartNetworkMarshal(adb_StartNetwork_t *startNetwork, const axutil_env_t *env) {  
  // output vars
  adb_StartNetworkResponse_t *ret=NULL;
  adb_startNetworkResponseType_t *snrt=NULL;

  //input vars
  adb_startNetworkType_t *snt=NULL;

  // working vars
  int rc, i;
  axis2_bool_t status=AXIS2_TRUE;
  char statusMessage[256];

  char *netName=NULL, **clusterControllers=NULL, *nameserver=NULL, *uuid=NULL, *accountId=NULL;
  
  int vlan, clusterControllersLen=0;
  ncMetadata ccMeta;
  
  snt = adb_StartNetwork_get_StartNetwork(startNetwork, env);
  EUCA_MESSAGE_UNMARSHAL(startNetworkType, snt, (&ccMeta));
  
  vlan = adb_startNetworkType_get_vlan(snt, env);
  netName = adb_startNetworkType_get_netName(snt, env);
  nameserver = adb_startNetworkType_get_nameserver(snt, env);
  uuid = adb_startNetworkType_get_uuid(snt, env);
  accountId = adb_startNetworkType_get_accountId(snt, env);
  if (!accountId) {
    accountId = ccMeta.userId;
  }

  clusterControllersLen = adb_startNetworkType_sizeof_clusterControllers(snt, env);
  clusterControllers = malloc(sizeof(char *) * clusterControllersLen);
  for (i=0; i<clusterControllersLen; i++) {
    clusterControllers[i] = host2ip(adb_startNetworkType_get_clusterControllers_at(snt, env, i));
  }
    
  snrt = adb_startNetworkResponseType_create(env);
  status = AXIS2_TRUE;
  if (!DONOTHING) {
    rc = doStartNetwork(&ccMeta, accountId, uuid, netName, vlan, nameserver, clusterControllers, clusterControllersLen);
    if (rc) {
      logprintf("ERROR: doStartNetwork() returned fail %d\n", rc);
      status = AXIS2_FALSE;
      snprintf(statusMessage, 255, "ERROR");
    }
  }

  for (i=0; i<clusterControllersLen; i++) {
    if (clusterControllers[i]) free(clusterControllers[i]);
  }
  if (clusterControllers) free(clusterControllers);
  
  adb_startNetworkResponseType_set_return(snrt, env, status);
  if (status == AXIS2_FALSE) {
    adb_startNetworkResponseType_set_statusMessage(snrt, env, statusMessage);
  }
  
  adb_startNetworkResponseType_set_correlationId(snrt, env, ccMeta.correlationId);
  adb_startNetworkResponseType_set_userId(snrt, env, ccMeta.userId);
  
  ret = adb_StartNetworkResponse_create(env);
  adb_StartNetworkResponse_set_StartNetworkResponse(ret, env, snrt);
  
  return(ret);
}