Example #1
0
int resumeJob (char* jobId) {
	if (debug) {
		printf ("**DEBUG: Resuming job.\n");
	}
	
	if (registered == 0) {
		if (registerWithJob (jobId) < 0) {
			return -1;
		}
		
		registered = 1;
	}
	
	/* Write Resume Job code */
	if (writen (fd, &RESUME, sizeof (RESUME)) < 0) {
		errorMessage = "Error while writing code for Resume Job to socket stream";
		return -1;
	}
	
	if (writeUTF (fd, jobId) < 0) {
		errorMessage = "Error while writing job id for Resume Job to socket stream";
		return -1;
	}
	
	if (debug) {
		printf ("**DEBUG: Job resumed.\n");
	}
	
	return 0;
}
Example #2
0
int cancelJob (char* jobId) {
	if (debug) {
		printf ("**DEBUG: Canceling job.\n");
	}
	
	if (registered == 0) {
		if (registerWithJob (jobId) < 0) {
			return -1;
		}
		
		registered = 1;
	}
	
	/* Write Cancel Job code */
	if (writen (fd, &CANCEL_JOB, sizeof (CANCEL_JOB)) < 0) {
		errorMessage = "Error while writing code for Cancel Job to socket stream";
		return -1;
	}
	
	if (writeUTF (fd, jobId) < 0) {
		errorMessage = "Error while writing job id for Cancel Job to socket stream";
		return -1;
	}
	
	if (debug) {
		printf ("**DEBUG: Job canceled.\n");
	}
	
	return 0;
}
Example #3
0
int suspendJob (char* jobId) {
	if (debug) {
		printf ("**DEBUG: Suspending job.\n");
	}
	
	if (registered == 0) {
		if (registerWithJob (jobId) < 0) {
			return -1;
		}
		
		registered = 1;
	}
	
	/* Write Suspend Job code */
	if (writen (fd, &SUSPEND, sizeof (SUSPEND)) < 0) {
		errorMessage = "Error while writing code for Suspend Job to socket stream";
		return -1;
	}
	
	if (writeUTF (fd, jobId) < 0) {
		errorMessage = "Error while writing job id for Suspend Job to socket stream";
		return -1;
	}
	
	if (debug) {
		printf ("**DEBUG: Job suspended.\n");
	}
	
	return 0;
}
Example #4
0
int submitJob () {
	char* job = malloc (MAX_BUFFER);
	
	if (debug) {
		printf ("**DEBUG: Submitting job.\n");
	}
	
	/* Write Submit Job code */
	if (writen (fd, &SUBMIT_JOB, sizeof (SUBMIT_JOB)) < 0) {
		errorMessage = "Error while writing code for Submit Job to socket stream";
		return -1;
	}
	
	/* Write serialized job filename */
	if (writeUTF (fd, filename) < 0) {
		errorMessage = "Error while writing job location for Submit Job to socket stream";
		return -1;
	}
	
	registered = 1;
	
	if (debug) {
		printf ("**DEBUG: Job submitted.\n");
	}
	
	return 0;
}
Example #5
0
/**
 * Send an MQTT unsubscribe packet down a socket.
 * @param topics list of topics
 * @param msgid the MQTT message id to use
 * @param dup boolean - whether to set the MQTT DUP flag
 * @param socket the open socket to send the data to
 * @param clientID the string client identifier, only used for tracing
 * @return the completion code (e.g. TCPSOCKET_COMPLETE)
 */
int MQTTPacket_send_unsubscribe(List* topics, int msgid, int dup, int socket, char* clientID)
{
	Header header;
	char *data, *ptr;
	int rc = -1;
	ListElement *elem = NULL;
	int datalen;

	FUNC_ENTRY;
	header.bits.type = UNSUBSCRIBE;
	header.bits.dup = dup;
	header.bits.qos = 1;
	header.bits.retain = 0;

	datalen = 2 + topics->count * 2; // utf length == 2
	while (ListNextElement(topics, &elem))
		datalen += strlen((char*)(elem->content));
	ptr = data = malloc(datalen);

	writeInt(&ptr, msgid);
	elem = NULL;
	while (ListNextElement(topics, &elem))
		writeUTF(&ptr, (char*)(elem->content));
	rc = MQTTPacket_send(socket, header, data, datalen);
	Log(LOG_PROTOCOL, 25, NULL, socket, clientID, msgid, rc);
	free(data);
	FUNC_EXIT_RC(rc);
	return rc;
}
Example #6
0
int checkpointJob (char* jobId) {
	if (debug) {
		printf ("**DEBUG: Checkpointing job.\n");
	}
	
	if (registered == 0) {
		if (registerWithJob (jobId) < 0) {
			return -1;
		}
		
		registered = 1;
	}
	
	/* Write Checkpoint Job code */
	if (writen (fd, &CHECKPOINT_JOB, sizeof (CHECKPOINT_JOB)) < 0) {
		errorMessage = "Error while writing code for Checkpoint Job to socket stream";
		return -1;
	}
	
	if (writeUTF (fd, jobId) < 0) {
		errorMessage = "Error while writing job id for Checkpoint Job to socket stream";
		return -1;
	}
	
	if (debug) {
		printf ("**DEBUG: Job checkpointed.\n");
	}
	
	return 0;
}
Example #7
0
/**
 * Send an MQTT unsubscribe packet down a socket.
 * @param topics list of topics
 * @param msgid the MQTT message id to use
 * @param dup boolean - whether to set the MQTT DUP flag
 * @param socket the open socket to send the data to
 * @param clientID the string client identifier, only used for tracing
 * @return the completion code (e.g. TCPSOCKET_COMPLETE)
 */
int MQTTPacket_send_unsubscribe(List* topics, int msgid, int dup, networkHandles* net, const char* clientID)
{
	Header header;
	char *data, *ptr;
	int rc = -1;
	ListElement *elem = NULL;
	int datalen;

	FUNC_ENTRY;
	header.bits.type = UNSUBSCRIBE;
	header.bits.dup = dup;
	header.bits.qos = 1;
	header.bits.retain = 0;

	datalen = 2 + topics->count * 2; /* utf length == 2 */
	while (ListNextElement(topics, &elem))
		datalen += (int)strlen((char*)(elem->content));
	ptr = data = malloc(datalen);

	writeInt(&ptr, msgid);
	elem = NULL;
	while (ListNextElement(topics, &elem))
		writeUTF(&ptr, (char*)(elem->content));
	rc = MQTTPacket_send(net, header, data, datalen, 1);
	Log(LOG_PROTOCOL, 25, NULL, net->socket, clientID, msgid, rc);
	if (rc != TCPSOCKET_INTERRUPTED)
		free(data);
	FUNC_EXIT_RC(rc);
	return rc;
}
Example #8
0
int registerWithJob (char* jobId) {
	/* Write Register code */
	if (writen (fd, &REGISTER, sizeof (REGISTER)) < 0) {
		errorMessage = "Error while writing code for Register to socket stream";
		return -1;
	}

	if (writeUTF (fd, jobId) < 0) {
		errorMessage = "Error while writing job id Register to socket stream";
		return -1;
	}
	
	return 0;
}
Example #9
0
/**
 * Send an MQTT subscribe packet down a socket.
 * @param topics list of topics
 * @param qoss list of corresponding QoSs
 * @param msgid the MQTT message id to use
 * @param dup boolean - whether to set the MQTT DUP flag
 * @param socket the open socket to send the data to
 * @param clientID the string client identifier, only used for tracing
 * @return the completion code (e.g. TCPSOCKET_COMPLETE)
 */
int MQTTPacket_send_subscribe(List* topics, List* qoss, uint64_t msgid, int dup, networkHandles* net, const char* clientID)
{
	Header header;
	char *data, *ptr;
	int rc = -1;
	ListElement *elem = NULL, *qosElem = NULL;
	int datalen;
    int mqtt_version = get_client_mqtt_version_from_network_handler(net);

	FUNC_ENTRY;
	header.bits.type = SUBSCRIBE;
	header.bits.dup = dup;
	header.bits.qos = 1;
	header.bits.retain = 0;

    //8 -> 64 bit msg id. if the msgid is 2 Byte, datalen will be decresed
	datalen = 8 + topics->count * 3; // utf length + char qos == 3
	while (ListNextElement(topics, &elem))
		datalen += strlen((char*)(elem->content));

	ptr = data = malloc(datalen);

    if(mqtt_version == MQTTVERSION_YUNBA_3_1)
    {
        writeInt64(&ptr, msgid);
    }else{
        msgid = (int)msgid;
        writeInt(&ptr, msgid);
        //make sure the datalen is adjusted
        datalen -= 6;
    }
	elem = NULL;
	while (ListNextElement(topics, &elem))
	{
		ListNextElement(qoss, &qosElem);
		writeUTF(&ptr, (char*)(elem->content));
		writeChar(&ptr, *(int*)(qosElem->content));
	}
	rc = MQTTPacket_send(net, header, data, datalen, 1);
	Log(LOG_PROTOCOL, 22, NULL, net->socket, clientID, msgid, rc);
	if (rc != TCPSOCKET_INTERRUPTED)
		free(data);
	FUNC_EXIT_RC(rc);
	return rc;
}
Example #10
0
/**
 * Send an MQTT unsubscribe packet down a socket.
 * @param topics list of topics
 * @param msgid the MQTT message id to use
 * @param dup boolean - whether to set the MQTT DUP flag
 * @param socket the open socket to send the data to
 * @param clientID the string client identifier, only used for tracing
 * @return the completion code (e.g. TCPSOCKET_COMPLETE)
 */
int MQTTPacket_send_unsubscribe(List* topics, uint64_t msgid, int dup, networkHandles* net, const char* clientID)
{
	Header header;
	char *data, *ptr;
	int rc = -1;
	ListElement *elem = NULL;
	int datalen;
    int mqtt_version = get_client_mqtt_version_from_network_handler(net);

	FUNC_ENTRY;
	header.bits.type = UNSUBSCRIBE;
	header.bits.dup = dup;
	header.bits.qos = 1;
	header.bits.retain = 0;

	datalen = 8 + topics->count * 2; // utf length == 2
	while (ListNextElement(topics, &elem))
		datalen += strlen((char*)(elem->content));
	ptr = data = malloc(datalen);

    if(MQTTVERSION_YUNBA_3_1 == mqtt_version)
    {
        writeInt64(&ptr, msgid);
    }else{
        writeInt(&ptr, msgid);
        datalen -= 6;
    }
	elem = NULL;
	while (ListNextElement(topics, &elem))
		writeUTF(&ptr, (char*)(elem->content));
	rc = MQTTPacket_send(net, header, data, datalen, 1);
	Log(LOG_PROTOCOL, 25, NULL, net->socket, clientID, msgid, rc);
	if (rc != TCPSOCKET_INTERRUPTED)
		free(data);
	FUNC_EXIT_RC(rc);
	return rc;
}
Example #11
0
bool FlowFileRecord::Serialize() {
  io::DataStream outStream;

  int ret;

  ret = write(this->event_time_, &outStream);
  if (ret != 8) {
    return false;
  }

  ret = write(this->entry_date_, &outStream);
  if (ret != 8) {
    return false;
  }

  ret = write(this->lineage_start_date_, &outStream);
  if (ret != 8) {
    return false;
  }

  ret = writeUTF(this->uuidStr_, &outStream);
  if (ret <= 0) {
    return false;
  }

  ret = writeUTF(this->uuid_connection_, &outStream);
  if (ret <= 0) {
    return false;
  }
  // write flow attributes
  uint32_t numAttributes = this->attributes_.size();
  ret = write(numAttributes, &outStream);
  if (ret != 4) {
    return false;
  }

  for (auto itAttribute : attributes_) {
    ret = writeUTF(itAttribute.first, &outStream, true);
    if (ret <= 0) {
      return false;
    }
    ret = writeUTF(itAttribute.second, &outStream, true);
    if (ret <= 0) {
      return false;
    }
  }

  ret = writeUTF(this->content_full_fath_, &outStream);
  if (ret <= 0) {
    return false;
  }

  ret = write(this->size_, &outStream);
  if (ret != 8) {
    return false;
  }

  ret = write(this->offset_, &outStream);
  if (ret != 8) {
    return false;
  }

  if (flow_repository_->Put(uuidStr_, const_cast<uint8_t*>(outStream.getBuffer()), outStream.getSize())) {
    logger_->log_debug("NiFi FlowFile Store event %s size %llu success", uuidStr_, outStream.getSize());
    return true;
  } else {
    logger_->log_error("NiFi FlowFile Store event %s size %llu fail", uuidStr_, outStream.getSize());
    return false;
  }

  return true;
}
Example #12
0
/**
 * Send an MQTT CONNECT packet down a socket.
 * @param client a structure from which to get all the required values
 * @return the completion code (e.g. TCPSOCKET_COMPLETE)
 */
int MQTTPacket_send_connect(Clients* client)
{
	char *buf, *ptr;
	Connect packet;
	int rc, len;

	FUNC_ENTRY;
	packet.header.byte = 0;
	packet.header.bits.type = CONNECT;
	packet.header.bits.qos = 1;

	len = 12 + strlen(client->clientID)+2;
	if (client->will)
		len += strlen(client->will->topic)+2 + strlen(client->will->msg)+2;
	if (client->username)
		len += strlen(client->username)+2;
	if (client->password)
		len += strlen(client->password)+2;

	ptr = buf = malloc(len);
	writeUTF(&ptr, "MQIsdp");
	if (client->noLocal)
		writeChar(&ptr, (char)-125);
	else
		writeChar(&ptr, (char)3);

	packet.flags.all = 0;
	packet.flags.bits.cleanstart = client->cleansession;
	packet.flags.bits.will = (client->will) ? 1 : 0;
	if (packet.flags.bits.will)
	{
		packet.flags.bits.willQoS = client->will->qos;
		packet.flags.bits.willRetain = client->will->retained;
	}

	if (client->username)
		packet.flags.bits.username = 1;
	if (client->password)
		packet.flags.bits.password = 1;

	writeChar(&ptr, packet.flags.all);
	writeInt(&ptr, client->keepAliveInterval);
	writeUTF(&ptr, client->clientID);
	if (client->will)
	{
		writeUTF(&ptr, client->will->topic);
		writeUTF(&ptr, client->will->msg);
	}
	if (client->username)
		writeUTF(&ptr, client->username);
	if (client->password)
		writeUTF(&ptr, client->password);

	rc = MQTTPacket_send(client->socket, packet.header, buf, len);
	Log(LOG_PROTOCOL, 0, NULL, client->socket, client->clientID, client->cleansession,
			client->noLocal, rc);
	free(buf);
	if (rc == TCPSOCKET_COMPLETE)
		time(&(client->lastContact));
	FUNC_EXIT_RC(rc);
	return rc;
}
Example #13
0
/**
 * Send an MQTT CONNECT packet down a socket.
 * @param client a structure from which to get all the required values
 * @param MQTTVersion the MQTT version to connect with
 * @return the completion code (e.g. TCPSOCKET_COMPLETE)
 */
int MQTTPacket_send_connect(Clients* client, int MQTTVersion)
{
	char *buf, *ptr;
	Connect packet;
	int rc = -1, len;

	FUNC_ENTRY;
	packet.header.byte = 0;
	packet.header.bits.type = CONNECT;
	packet.header.bits.qos = 1;

	len = ((MQTTVersion == 3 || MQTTVersion == MQTTVERSION_YUNBA_3_1)  ? 12 : 10) + strlen(client->clientID)+2;
	if (client->will)
		len += strlen(client->will->topic)+2 + strlen(client->will->msg)+2;
	if (client->username)
		len += strlen(client->username)+2;
	if (client->password)
		len += strlen(client->password)+2;

	ptr = buf = malloc(len);
    if(MQTTVersion == 3 || MQTTVersion == MQTTVERSION_YUNBA_3_1)
    {
        writeUTF(&ptr, "MQIsdp");
    }else
    {
        writeUTF(&ptr, "MQTT");
    }
	writeChar(&ptr, (char)MQTTVersion);

	packet.flags.all = 0;
	packet.flags.bits.cleanstart = client->cleansession;
	packet.flags.bits.will = (client->will) ? 1 : 0;
	if (packet.flags.bits.will)
	{
		packet.flags.bits.willQoS = client->will->qos;
		packet.flags.bits.willRetain = client->will->retained;
	}

	if (client->username)
		packet.flags.bits.username = 1;
	if (client->password)
		packet.flags.bits.password = 1;

	writeChar(&ptr, packet.flags.all);
	writeInt(&ptr, client->keepAliveInterval);
	writeUTF(&ptr, client->clientID);
	if (client->will)
	{
		writeUTF(&ptr, client->will->topic);
		writeUTF(&ptr, client->will->msg);
	}
	if (client->username)
		writeUTF(&ptr, client->username);
	if (client->password)
		writeUTF(&ptr, client->password);

	rc = MQTTPacket_send(&client->net, packet.header, buf, len, 1);
	Log(LOG_PROTOCOL, 0, NULL, client->net.socket, client->clientID, client->cleansession, rc);
exit:
	if (rc != TCPSOCKET_INTERRUPTED)
		free(buf);
	FUNC_EXIT_RC(rc);
	return rc;
}