Skip to content

Commit

Permalink
0002985: C Client FileSync raises an error on empty incoming batches
Browse files Browse the repository at this point in the history
  • Loading branch information
mmichalek committed Feb 7, 2017
1 parent 2f17556 commit 177d2bf
Show file tree
Hide file tree
Showing 5 changed files with 86 additions and 7 deletions.
31 changes: 31 additions & 0 deletions symmetric-client-clib/inc/transport/http/CurlConfig.h
@@ -0,0 +1,31 @@
/**
* Licensed to JumpMind Inc under one or more contributor
* license agreements. See the NOTICE file distributed
* with this work for additional information regarding
* copyright ownership. JumpMind Inc licenses this file
* to you under the GNU General Public License, version 3.0 (GPLv3)
* (the "License"); you may not use this file except in compliance
* with the License.
*
* You should have received a copy of the GNU General Public License,
* version 3.0 (GPLv3) along with this library; if not, see
* <http://www.gnu.org/licenses/>.
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
#ifndef SYM_CURLCONFIG_H_
#define SYM_CURLCONFIG_H_

#include <stdlib.h>
#include <curl/curl.h>
#include "service/ParameterService.h"
#include "common/ParameterConstants.h"

void SymCurlConfig_configure(CURL *curl, SymParameterService *parameterService);

#endif /* SYM_CURLCONFIG_H_ */
15 changes: 10 additions & 5 deletions symmetric-client-clib/src/service/FileSyncService.c
Expand Up @@ -605,9 +605,12 @@ SymList * /*<IncomingBatch>*/ SymFileSyncService_processZip(SymFileSyncService *
batchesProcessed->add(batchesProcessed, incomingBatch);
if (incomingBatchService->acquireIncomingBatch(incomingBatchService, incomingBatch)) {
char* syncScript = SymStringUtils_format("%s/%s", batchDir, "sync.sh");
if (SymFileUtils_exists(syncScript)) {
unsigned short syncScriptExists = SymFileUtils_exists(syncScript);

SymLog_debug("syncScriptExists=%d for path %s", syncScriptExists, syncScript);

if (syncScriptExists) {
// In Java this would be a beanshell. Here we assume a shell script we'll exec.
// TODO *** *here, exec the script, everything is tee'd up.
char *tmpOutputDir = SymStringUtils_format("tmp/staging/filesync_incoming/processing/%s/", batchId);
SymFileUtils_mkdir(tmpOutputDir);

Expand All @@ -621,8 +624,11 @@ SymList * /*<IncomingBatch>*/ SymFileSyncService_processZip(SymFileSyncService *

int rc = system(cmd);

if (rc == 0 && SymFileUtils_exists(fileListProcessed)) {
// TODO read in the output
unsigned short outputFileExists = SymFileUtils_exists(fileListProcessed);

SymLog_debug("Script rc=%d, outputFileExists=%d", rc, outputFileExists);

if (rc == 0 && outputFileExists) {
SymProperties *filesToEventType = SymProperties_newWithFile(NULL, fileListProcessed);

if (this->engine->parameterService->is(this->engine->parameterService, SYM_PARAMETER_FILE_SYNC_PREVENT_PING_BACK, 1)) {
Expand Down Expand Up @@ -657,7 +663,6 @@ SymList * /*<IncomingBatch>*/ SymFileSyncService_processZip(SymFileSyncService *
free(batchInfo);
free(batchDir);
free(tmpOutputDir);
// free(cmd);
free(fileListProcessed);
free(outputFileName);
}
Expand Down
6 changes: 4 additions & 2 deletions symmetric-client-clib/src/service/IncomingBatchService.c
Expand Up @@ -75,9 +75,11 @@ unsigned short SymIncomingBatchService_acquireIncomingBatch(SymIncomingBatchServ
SymIncomingBatch *existingBatch = NULL;

if (this->isRecordOkBatchesEnabled(this)) {
if (this->insertIncomingBatch(this, batch) == 0) {
existingBatch = this->findIncomingBatch(this, batch->batchId, batch->nodeId);
if (existingBatch == NULL) {
this->insertIncomingBatch(this, batch);
} else {
batch->retry = 1;
existingBatch = this->findIncomingBatch(this, batch->batchId, batch->nodeId);
}
} else {
existingBatch = this->findIncomingBatch(this, batch->batchId, batch->nodeId);
Expand Down
38 changes: 38 additions & 0 deletions symmetric-client-clib/src/transport/http/CurlConfig.c
@@ -0,0 +1,38 @@
/**
* Licensed to JumpMind Inc under one or more contributor
* license agreements. See the NOTICE file distributed
* with this work for additional information regarding
* copyright ownership. JumpMind Inc licenses this file
* to you under the GNU General Public License, version 3.0 (GPLv3)
* (the "License"); you may not use this file except in compliance
* with the License.
*
* You should have received a copy of the GNU General Public License,
* version 3.0 (GPLv3) along with this library; if not, see
* <http://www.gnu.org/licenses/>.
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
#include "transport/http/CurlConfig.h"

void SymCurlConfig_configure(CURL *curl, SymParameterService *parameterService) {

long readTimeoutMillis = parameterService->getLong(parameterService,
SYM_PARAMETER_TRANSPORT_HTTP_TIMEOUT, 90000);
long readTimeoutSeconds = readTimeoutMillis/1000;

curl_easy_setopt(curl, CURLOPT_LOW_SPEED_LIMIT, 1);
curl_easy_setopt(curl, CURLOPT_LOW_SPEED_TIME, readTimeoutSeconds);

if (parameterService->is(parameterService, SYM_PARAMETER_HTTPS_VERIFIED_SERVERS, 1)) {
curl_easy_setopt(curl, CURLOPT_SSL_VERIFYHOST, 0);
}
if (parameterService->is(parameterService, SYM_PARAMETER_HTTPS_ALLOW_SELF_SIGNED_CERTS, 1)) {
curl_easy_setopt(curl, CURLOPT_SSL_VERIFYPEER, 0);
}
}
Expand Up @@ -70,6 +70,9 @@ public void buildScriptFileSnapshot(Batch batch, FileSnapshot snapshot, FileTrig
}

appendln("if [ \"$processFile\" = true ] ; then ");
// This line guards against shell script syntax error caused by empty "if...fi" when the source
// file was removed before extraction.
appendln(" echo \"#Processing " + snapshot.getFileName() + "\" >> \"$outputFileName\"");

switch (eventType) {
case CREATE:
Expand Down

0 comments on commit 177d2bf

Please sign in to comment.