From 5f7845c047e51d4d631423659ee2e759731525f2 Mon Sep 17 00:00:00 2001 From: Hiren Patel Date: Tue, 13 Jun 2023 12:42:02 +0530 Subject: [PATCH 01/18] Adding log for better deployment monitoring --- deployment/codedeploy/scripts/ApplicationStart.sh | 2 ++ deployment/codedeploy/scripts/ApplicationStop.sh | 1 + 2 files changed, 3 insertions(+) diff --git a/deployment/codedeploy/scripts/ApplicationStart.sh b/deployment/codedeploy/scripts/ApplicationStart.sh index b10ecd5e3..35fda7a9d 100644 --- a/deployment/codedeploy/scripts/ApplicationStart.sh +++ b/deployment/codedeploy/scripts/ApplicationStart.sh @@ -1,4 +1,6 @@ #!/bin/bash # Start application +echo "Starting Naksha service..." sudo systemctl start xyz-hub +echo "Start triggered!" diff --git a/deployment/codedeploy/scripts/ApplicationStop.sh b/deployment/codedeploy/scripts/ApplicationStop.sh index 6c58f68d2..9028cfdc1 100644 --- a/deployment/codedeploy/scripts/ApplicationStop.sh +++ b/deployment/codedeploy/scripts/ApplicationStop.sh @@ -1,4 +1,5 @@ #!/bin/bash # Stop application +echo "Stopping Naksha service..." sudo systemctl stop xyz-hub From 1611d06d91f05390ac2fce87d3443cc0c858d112 Mon Sep 17 00:00:00 2001 From: Hiren Patel Date: Wed, 14 Jun 2023 21:42:32 +0530 Subject: [PATCH 02/18] Added OTel metrics for observing memory utilization --- xyz-hub-service/pom.xml | 8 ++++ .../main/java/com/here/xyz/hub/Service.java | 3 ++ .../com/here/xyz/hub/util/OTelMetrics.java | 38 +++++++++++++++++++ 3 files changed, 49 insertions(+) create mode 100644 xyz-hub-service/src/main/java/com/here/xyz/hub/util/OTelMetrics.java diff --git a/xyz-hub-service/pom.xml b/xyz-hub-service/pom.xml index e055f4740..7c119687c 100644 --- a/xyz-hub-service/pom.xml +++ b/xyz-hub-service/pom.xml @@ -47,6 +47,7 @@ deployment/local/config.json docker-compose.yml 2.20.11 + 1.27.0 @@ -326,6 +327,13 @@ + + + io.opentelemetry + opentelemetry-api + ${otel.version} + + expiringmap diff --git a/xyz-hub-service/src/main/java/com/here/xyz/hub/Service.java b/xyz-hub-service/src/main/java/com/here/xyz/hub/Service.java index 2f1548f91..b1e1dca38 100644 --- a/xyz-hub-service/src/main/java/com/here/xyz/hub/Service.java +++ b/xyz-hub-service/src/main/java/com/here/xyz/hub/Service.java @@ -36,6 +36,7 @@ import com.here.xyz.hub.rest.admin.messages.brokers.Broker; import com.here.xyz.hub.rest.admin.messages.brokers.NoopBroker; import com.here.xyz.hub.util.ARN; +import com.here.xyz.hub.util.OTelMetrics; import com.here.xyz.hub.util.metrics.GcDurationMetric; import com.here.xyz.hub.util.metrics.GlobalInflightRequestMemory; import com.here.xyz.hub.util.metrics.GlobalUsedRfcConnections; @@ -215,6 +216,8 @@ private static void onConfigLoaded(JsonObject jsonConfig) { die(1, "Space config client failed", ar.cause()); } }); + // Initialize OpenTelemetry related metrics + OTelMetrics.init(); } private static void onLocalConnectorsInserted(AsyncResult result, JsonObject config) { diff --git a/xyz-hub-service/src/main/java/com/here/xyz/hub/util/OTelMetrics.java b/xyz-hub-service/src/main/java/com/here/xyz/hub/util/OTelMetrics.java new file mode 100644 index 000000000..7384d8eba --- /dev/null +++ b/xyz-hub-service/src/main/java/com/here/xyz/hub/util/OTelMetrics.java @@ -0,0 +1,38 @@ +package com.here.xyz.hub.util; + +import io.opentelemetry.api.GlobalOpenTelemetry; +import io.opentelemetry.api.metrics.Meter; +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; + +import java.math.BigDecimal; +import java.math.RoundingMode; + +public class OTelMetrics { + + private static final Logger logger = LogManager.getLogger(); + private static final Meter meter = GlobalOpenTelemetry.meterBuilder("io.opentelemetry.metrics.memory") + .setInstrumentationVersion("1.27.0") // as per otel.version in pom.xml + .build(); + + public static void init() { + // This will keep collecting memory utilization in background + meter.gaugeBuilder("mem_used_pct") + .setDescription("Heap-Memory used percentage") + .setUnit("percent") + .buildWithCallback( + (r) -> { + Runtime rt = Runtime.getRuntime(); + long max = rt.maxMemory(); + long total = rt.totalMemory(); + long free = rt.freeMemory(); + long used = total - free; + double usedPct = ((double)used/max)*100.00; + BigDecimal bd = new BigDecimal(usedPct).setScale(2, RoundingMode.HALF_EVEN); + r.record(bd.doubleValue()); + } + ); + } + + +} From 12a6e29bf1283b03a012ea97871f613450446f50 Mon Sep 17 00:00:00 2001 From: Hiren Patel Date: Tue, 20 Jun 2023 22:46:26 +0530 Subject: [PATCH 03/18] Added REST API stats in logs --- .../here/xyz/hub/AbstractHttpServerVerticle.java | 3 ++- .../here/xyz/hub/task/FeatureTaskHandler.java | 2 ++ .../com/here/xyz/hub/util/logging/LogUtil.java | 16 +++++++++++++++- 3 files changed, 19 insertions(+), 2 deletions(-) diff --git a/xyz-hub-service/src/main/java/com/here/xyz/hub/AbstractHttpServerVerticle.java b/xyz-hub-service/src/main/java/com/here/xyz/hub/AbstractHttpServerVerticle.java index c9583b9e1..a5997dbbf 100644 --- a/xyz-hub-service/src/main/java/com/here/xyz/hub/AbstractHttpServerVerticle.java +++ b/xyz-hub-service/src/main/java/com/here/xyz/hub/AbstractHttpServerVerticle.java @@ -155,7 +155,8 @@ protected void onResponseEnd(RoutingContext context) { logger.info(marker, "The request was cancelled. No response has been sent."); onRequestCancelled(context); } - logger.info(marker, "{}", LogUtil.responseToLogEntry(context)); + // Commented this log as it is already getting logged below + // logger.info(marker, "{}", LogUtil.responseToLogEntry(context)); LogUtil.addResponseInfo(context).end(); LogUtil.writeAccessLog(context); } diff --git a/xyz-hub-service/src/main/java/com/here/xyz/hub/task/FeatureTaskHandler.java b/xyz-hub-service/src/main/java/com/here/xyz/hub/task/FeatureTaskHandler.java index db60d044d..9427259d7 100644 --- a/xyz-hub-service/src/main/java/com/here/xyz/hub/task/FeatureTaskHandler.java +++ b/xyz-hub-service/src/main/java/com/here/xyz/hub/task/FeatureTaskHandler.java @@ -773,6 +773,8 @@ private static Future resolveSpace(final X task) if (task.space != null) //If the space is already given we don't need to retrieve it return Future.succeededFuture(task.space); + AbstractHttpServerVerticle.addStreamInfo(task.context, "SpaceId", task.getEvent().getSpace()); + //Load the space definition. return Space.resolveSpace(task.getMarker(), task.getEvent().getSpace()) .compose( diff --git a/xyz-hub-service/src/main/java/com/here/xyz/hub/util/logging/LogUtil.java b/xyz-hub-service/src/main/java/com/here/xyz/hub/util/logging/LogUtil.java index d652e174d..0050941d2 100644 --- a/xyz-hub-service/src/main/java/com/here/xyz/hub/util/logging/LogUtil.java +++ b/xyz-hub-service/src/main/java/com/here/xyz/hub/util/logging/LogUtil.java @@ -115,7 +115,11 @@ public static void addRequestInfo(RoutingContext context) { AccessLog accessLog = Api.Context.getAccessLog(context); HttpMethod method = context.request().method(); accessLog.reqInfo.method = context.request().method().name(); - accessLog.reqInfo.uri = context.request().uri(); + // Remove access_token part from uri for security concerns + //accessLog.reqInfo.uri = context.request().uri(); + final String uri = context.request().uri(); + final int endPos = uri.indexOf("?"); + accessLog.reqInfo.uri = (endPos > 0) ? uri.substring(0, endPos) : uri; accessLog.reqInfo.referer = context.request().getHeader(REFERER); accessLog.reqInfo.origin = context.request().getHeader(ORIGIN); if (POST.equals(method) || PUT.equals(method) || PATCH.equals(method)) { @@ -167,5 +171,15 @@ public static void writeAccessLog(RoutingContext context) { accessLog.streamId = marker.getName(); logger.log(STREAM_LEVEL, ACCESS_LOG_MARKER, accessLog.serialize()); + + // Log relevant details for generating API metrics + final AccessLog.RequestInfo req = accessLog.reqInfo; + final AccessLog.ResponseInfo res = accessLog.respInfo; + final Map si = accessLog.streamInfo; + logger.info("REST API stats for [streamId={}] [format => eventType,spaceId,connectorId,method,uri,status,timeTakenMs,resSize] - RESTAPIStats {} {} {} {} {} {} {}", + accessLog.streamId, + (si == null) ? "-" : si.get("SpaceId"), + (si == null) ? "-" : si.get("SID"), + req.method, req.uri, res.statusCode, accessLog.ms, res.size); } } From 2ce40cebd857936f19975664e1364ee4047b93df Mon Sep 17 00:00:00 2001 From: Hiren Patel Date: Fri, 23 Jun 2023 21:15:15 +0530 Subject: [PATCH 04/18] Updated DBOperationStats metrics to include table as well --- .../com/here/xyz/psql/DatabaseStreamWriter.java | 12 ++++++------ .../here/xyz/psql/DatabaseTransactionalWriter.java | 14 +++++++------- 2 files changed, 13 insertions(+), 13 deletions(-) diff --git a/xyz-psql-connector/src/main/java/com/here/xyz/psql/DatabaseStreamWriter.java b/xyz-psql-connector/src/main/java/com/here/xyz/psql/DatabaseStreamWriter.java index c99328ce8..364bf7884 100644 --- a/xyz-psql-connector/src/main/java/com/here/xyz/psql/DatabaseStreamWriter.java +++ b/xyz-psql-connector/src/main/java/com/here/xyz/psql/DatabaseStreamWriter.java @@ -114,8 +114,8 @@ protected static FeatureCollection insertFeatures(DatabaseHandler dbh, String sc insertStmt.close(); insertWithoutGeometryStmt.close(); final long duration = System.currentTimeMillis() - startTS; - logger.info("{} NonTransactional DB Operation Stats [format => eventType,opType,timeTakenMs] - {} {} {}", - traceItem, "DBOperationStats", TYPE_INSERT, duration); + logger.info("{} NonTransactional DB Operation Stats [format => eventType,table,opType,timeTakenMs] - {} {} {} {}", + traceItem, "DBOperationStats", table, TYPE_INSERT, duration); return collection; } @@ -215,8 +215,8 @@ protected static FeatureCollection updateFeatures(DatabaseHandler dbh, String sc updateStmt.close(); updateWithoutGeometryStmt.close(); final long duration = System.currentTimeMillis() - startTS; - logger.info("{} NonTransactional DB Operation Stats [format => eventType,opType,timeTakenMs] - {} {} {}", - traceItem, "DBOperationStats", TYPE_UPDATE, duration); + logger.info("{} NonTransactional DB Operation Stats [format => eventType,table,opType,timeTakenMs] - {} {} {} {}", + traceItem, "DBOperationStats", table, TYPE_UPDATE, duration); return collection; } @@ -273,7 +273,7 @@ protected static void deleteFeatures( DatabaseHandler dbh, String schema, String deleteStmt.close(); deleteStmtWithoutUUID.close(); final long duration = System.currentTimeMillis() - startTS; - logger.info("{} NonTransactional DB Operation Stats [format => eventType,opType,timeTakenMs] - {} {} {}", - traceItem, "DBOperationStats", TYPE_DELETE, duration); + logger.info("{} NonTransactional DB Operation Stats [format => eventType,table,opType,timeTakenMs] - {} {} {} {}", + traceItem, "DBOperationStats", table, TYPE_DELETE, duration); } } diff --git a/xyz-psql-connector/src/main/java/com/here/xyz/psql/DatabaseTransactionalWriter.java b/xyz-psql-connector/src/main/java/com/here/xyz/psql/DatabaseTransactionalWriter.java index 8375c2b42..65de15a55 100644 --- a/xyz-psql-connector/src/main/java/com/here/xyz/psql/DatabaseTransactionalWriter.java +++ b/xyz-psql-connector/src/main/java/com/here/xyz/psql/DatabaseTransactionalWriter.java @@ -94,7 +94,7 @@ public static FeatureCollection insertFeatures(DatabaseHandler dbh, String schem } executeBatchesAndCheckOnFailures(dbh, insertIdList, insertWithoutGeometryIdList, - insertStmt, insertWithoutGeometryStmt, featureList, featureWithoutGeoList, fails, false, TYPE_INSERT, traceItem); + insertStmt, insertWithoutGeometryStmt, featureList, featureWithoutGeoList, fails, false, TYPE_INSERT, traceItem, table); if(fails.size() > 0) { logException(null, traceItem, LOG_EXCEPTION_INSERT, table); @@ -177,7 +177,7 @@ public static FeatureCollection updateFeatures(DatabaseHandler dbh, String schem } executeBatchesAndCheckOnFailures(dbh, updateIdList, updateWithoutGeometryIdList, - updateStmt, updateWithoutGeometryStmt, featureList, featureWithoutGeoList, fails, handleUUID, TYPE_UPDATE, traceItem); + updateStmt, updateWithoutGeometryStmt, featureList, featureWithoutGeoList, fails, handleUUID, TYPE_UPDATE, traceItem, table); if(fails.size() > 0) { logException(null, traceItem, LOG_EXCEPTION_UPDATE, table); @@ -250,7 +250,7 @@ protected static void deleteFeatures(DatabaseHandler dbh, String schema, String batchDeleteStmtVersioned.setArray(3, handleUUID ? connection.createArrayOf("text", versionedUuidList.toArray()) : null); } executeBatchesAndCheckOnFailures(dbh, deleteIdList, deleteIdListWithoutUUID, - batchDeleteStmtVersioned, batchDeleteStmtVersionedWithoutUUID, null, null, fails, handleUUID, TYPE_DELETE, traceItem); + batchDeleteStmtVersioned, batchDeleteStmtVersionedWithoutUUID, null, null, fails, handleUUID, TYPE_DELETE, traceItem, table); }else{ if (deleteIdListWithoutUUID.size() > 0) { @@ -261,7 +261,7 @@ protected static void deleteFeatures(DatabaseHandler dbh, String schema, String batchDeleteStmt.setArray(2, handleUUID ? connection.createArrayOf("text", deleteUuidList.toArray()) : null); } executeBatchesAndCheckOnFailures(dbh, deleteIdList, deleteIdListWithoutUUID, - batchDeleteStmt, batchDeleteStmtWithoutUUID, null, null, fails, handleUUID, TYPE_DELETE, traceItem); + batchDeleteStmt, batchDeleteStmtWithoutUUID, null, null, fails, handleUUID, TYPE_DELETE, traceItem, table); } if(fails.size() > 0) { @@ -274,7 +274,7 @@ private static void executeBatchesAndCheckOnFailures(DatabaseHandler dbh, List featureList, final List featureWithoutGeoList, List fails, - boolean handleUUID, int type, TraceItem traceItem) throws SQLException, JsonProcessingException { + boolean handleUUID, int type, TraceItem traceItem, final String table) throws SQLException, JsonProcessingException { try { final long startTS = System.currentTimeMillis(); @@ -298,8 +298,8 @@ private static void executeBatchesAndCheckOnFailures(DatabaseHandler dbh, List eventType,opType,timeTakenMs] - {} {} {}", - traceItem, "DBOperationStats", type, duration); + logger.info("{} Transactional DB Operation Stats [format => eventType,table,opType,timeTakenMs] - {} {} {} {}", + traceItem, "DBOperationStats", table, type, duration); }finally { batchStmt.close(); batchStmt2.close(); From b0377ac855c7c979e7f3002541d7b49e1e1a75d7 Mon Sep 17 00:00:00 2001 From: Hiren Patel Date: Fri, 30 Jun 2023 12:04:31 +0530 Subject: [PATCH 05/18] Corrected typo in log message --- .../src/main/java/com/here/xyz/psql/DatabaseHandler.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/xyz-psql-connector/src/main/java/com/here/xyz/psql/DatabaseHandler.java b/xyz-psql-connector/src/main/java/com/here/xyz/psql/DatabaseHandler.java index 6b7af5539..14d38f84e 100644 --- a/xyz-psql-connector/src/main/java/com/here/xyz/psql/DatabaseHandler.java +++ b/xyz-psql-connector/src/main/java/com/here/xyz/psql/DatabaseHandler.java @@ -644,7 +644,7 @@ protected XyzResponse executeModifyFeatures(ModifyFeaturesEvent event) throws Ex throw e;//Table does not exist yet - create it! else { - logger.warn("{} Transaction has failed. {]", traceItem, e); + logger.warn("{} Transaction has failed. ", traceItem, e); connection.close(); Map errorDetails = new HashMap<>(); From a57974271eff7984897f848bf460047c50a77653 Mon Sep 17 00:00:00 2001 From: Hiren Patel Date: Fri, 7 Jul 2023 21:23:04 +0530 Subject: [PATCH 06/18] Updated naksha_bulk_update function to improve featureId sorting logic --- test-scripts/xyz-api-maptask-suite.jmx | 11 +++++------ xyz-psql-connector/src/main/resources/naksha_ext.sql | 7 +++++-- 2 files changed, 10 insertions(+), 8 deletions(-) diff --git a/test-scripts/xyz-api-maptask-suite.jmx b/test-scripts/xyz-api-maptask-suite.jmx index f036eaa73..ada6365a9 100644 --- a/test-scripts/xyz-api-maptask-suite.jmx +++ b/test-scripts/xyz-api-maptask-suite.jmx @@ -836,7 +836,6 @@ var createdTaskStr = vars.get("V_Created_Task_Str"); var updateTaskObj = JSON.parse(createdTaskStr); updateTaskObj.properties["@ns:com:here:xyz"].tags.push("${UTM_DUMMY_UPDATE_TAG}"); - vars.put("V_Update_Request_Str", JSON.stringify(updateTaskObj)); javascript @@ -1423,8 +1422,8 @@ vars.put("V_Update_Request_Str_02", JSON.stringify(updateTaskObj)); { "type": "FeatureCollection", "features": [ - ${V_Update_Request_Str_01}, - ${V_Update_Request_Str_02} + ${V_Update_Request_Str_02}, + ${V_Update_Request_Str_01} ] } @@ -1469,10 +1468,10 @@ prev.setSuccessful(false); var expectedResObj = { "type": "FeatureCollection", "features": [ - ${V_Update_Request_Str_01}, - ${V_Update_Request_Str_02} + ${V_Update_Request_Str_02}, + ${V_Update_Request_Str_01} ], - "updated": ["${TASK_ID_P02_01}", "${TASK_ID_P02_02}"] + "updated": ["${TASK_ID_P02_02}", "${TASK_ID_P02_01}"] }; // Remove unwanted fields from RESPONSE object, before actual v/s expected comparison diff --git a/xyz-psql-connector/src/main/resources/naksha_ext.sql b/xyz-psql-connector/src/main/resources/naksha_ext.sql index 7897c8d51..edf861316 100644 --- a/xyz-psql-connector/src/main/resources/naksha_ext.sql +++ b/xyz-psql-connector/src/main/resources/naksha_ext.sql @@ -1178,8 +1178,11 @@ BEGIN END IF; idx := idx + 1; END LOOP; - sorted_id_arr := akeys(id_pos_hstore); -- Sorted list of feature Ids - orig_idx_arr := id_pos_hstore -> sorted_id_arr; -- Original array idx position of each sorted Id + -- Sorted list of feature Ids + stmt := 'SELECT ARRAY_AGG(x.val) FROM (SELECT unnest($1) AS val ORDER BY val ASC) AS x'; + EXECUTE stmt INTO sorted_id_arr USING akeys(id_pos_hstore); + -- Original array idx position of each sorted Id + orig_idx_arr := id_pos_hstore -> sorted_id_arr; -- Prepare statements upfront for perf optimization purpose random_num := round(random()*1000000)::TEXT; From a9a689d75bb69a45e85fb253aa173723473c0cb4 Mon Sep 17 00:00:00 2001 From: Hiren Patel Date: Fri, 14 Jul 2023 12:41:37 +0530 Subject: [PATCH 07/18] App now supports externally setup AWS role/login --- deployment/codedeploy/contents/.config/config.json | 4 ++-- .../src/main/java/com/here/xyz/hub/Service.java | 8 +++++++- xyz-hub-service/src/main/resources/config.json | 4 ++-- .../main/java/com/here/xyz/pub/XYZTransactionHandler.java | 4 ++-- 4 files changed, 13 insertions(+), 7 deletions(-) diff --git a/deployment/codedeploy/contents/.config/config.json b/deployment/codedeploy/contents/.config/config.json index 575e13529..0e7aad267 100644 --- a/deployment/codedeploy/contents/.config/config.json +++ b/deployment/codedeploy/contents/.config/config.json @@ -60,8 +60,8 @@ "TXN_PUB_TPOOL_MAX_SIZE" : 100, "TXN_PUB_TPOOL_KEEP_ALIVE_SEC" : 60, - "AWS_ACCESS_KEY_ID": "<>", - "AWS_SECRET_ACCESS_KEY": "<>", + "AWS_ACCESS_KEY_ID": "", + "AWS_SECRET_ACCESS_KEY": "", "AWS_DEFAULT_REGION": "<>", "ENABLE_TXN_SEQUENCER" : true, diff --git a/xyz-hub-service/src/main/java/com/here/xyz/hub/Service.java b/xyz-hub-service/src/main/java/com/here/xyz/hub/Service.java index b1e1dca38..01e0a0c21 100644 --- a/xyz-hub-service/src/main/java/com/here/xyz/hub/Service.java +++ b/xyz-hub-service/src/main/java/com/here/xyz/hub/Service.java @@ -207,7 +207,13 @@ private static void onConfigLoaded(JsonObject jsonConfig) { }); subscriptionConfigClient.init(subscriptionConfigReady -> { if (subscriptionConfigReady.succeeded()) { - XYZTransactionHandler.getInstance(rawConfiguration).start(); + try { + XYZTransactionHandler.getInstance(rawConfiguration).start(); + } + catch (Exception ex) { + logger.error("Failed to initiate background Transaction Handler job. ", ex); + die(1, "Background Transaction Handler job initialization failed", ex.getCause()); + } } else { die(1, "Subscription config client failed", subscriptionConfigReady.cause()); } diff --git a/xyz-hub-service/src/main/resources/config.json b/xyz-hub-service/src/main/resources/config.json index e9e6f8427..fe7f8cb90 100644 --- a/xyz-hub-service/src/main/resources/config.json +++ b/xyz-hub-service/src/main/resources/config.json @@ -59,8 +59,8 @@ "TXN_PUB_TPOOL_MAX_SIZE" : 100, "TXN_PUB_TPOOL_KEEP_ALIVE_SEC" : 60, - "AWS_ACCESS_KEY_ID": "<>", - "AWS_SECRET_ACCESS_KEY": "<>", + "AWS_ACCESS_KEY_ID": "", + "AWS_SECRET_ACCESS_KEY": "", "AWS_DEFAULT_REGION": "us-east-1", "ENABLE_TXN_SEQUENCER" : true, diff --git a/xyz-txn-handler/src/main/java/com/here/xyz/pub/XYZTransactionHandler.java b/xyz-txn-handler/src/main/java/com/here/xyz/pub/XYZTransactionHandler.java index 491b7f981..61a8ef8cf 100644 --- a/xyz-txn-handler/src/main/java/com/here/xyz/pub/XYZTransactionHandler.java +++ b/xyz-txn-handler/src/main/java/com/here/xyz/pub/XYZTransactionHandler.java @@ -58,8 +58,8 @@ private static void readConfig() { adminDBConnParams.setUser(pubCfg.STORAGE_DB_USER); adminDBConnParams.setPswd(pubCfg.STORAGE_DB_PASSWORD); // Set AWS account access details - System.setProperty("aws.accessKeyId", pubCfg.AWS_ACCESS_KEY_ID); - System.setProperty("aws.secretAccessKey", pubCfg.AWS_SECRET_ACCESS_KEY); + System.setProperty("aws.accessKeyId", (pubCfg.AWS_ACCESS_KEY_ID!=null) ? pubCfg.AWS_ACCESS_KEY_ID : ""); + System.setProperty("aws.secretAccessKey", (pubCfg.AWS_SECRET_ACCESS_KEY!=null) ? pubCfg.AWS_SECRET_ACCESS_KEY : ""); } From c416374453a0dd381c2f1c3961a5ca5bb91c883d Mon Sep 17 00:00:00 2001 From: Hiren Patel Date: Sat, 15 Jul 2023 00:51:41 +0530 Subject: [PATCH 08/18] Added folder permission in codedeploy spec file --- deployment/codedeploy/appspec.yml | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/deployment/codedeploy/appspec.yml b/deployment/codedeploy/appspec.yml index 31f739e68..9c05de7af 100644 --- a/deployment/codedeploy/appspec.yml +++ b/deployment/codedeploy/appspec.yml @@ -39,18 +39,16 @@ files: # "permissions" section altogether. A blank or incomplete "permissions" # section may cause associated deployments to fail. permissions: + - object: /home/admin/xyz-hub + owner: admin + group: admin + type: + - directory - object: /home/admin/xyz-hub pattern: "**" except: ["set-app-params.sh","set-auth-keys.sh","set-instance-params.sh","start-app.sh"] owner: admin group: admin - #mode: - #acls: - #- - #context: - #user: - #type: - #range: type: - directory - object: /home/admin/xyz-hub From 10dda0e6ffa0416a24f2aac0d33f4ff2a90354d4 Mon Sep 17 00:00:00 2001 From: Hiren Patel Date: Sat, 15 Jul 2023 01:12:27 +0530 Subject: [PATCH 09/18] Added more file/folder permissions in codedeploy spec file --- deployment/codedeploy/appspec.yml | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/deployment/codedeploy/appspec.yml b/deployment/codedeploy/appspec.yml index 9c05de7af..de92ff081 100644 --- a/deployment/codedeploy/appspec.yml +++ b/deployment/codedeploy/appspec.yml @@ -51,6 +51,13 @@ permissions: group: admin type: - directory + - object: /home/admin/xyz-hub + pattern: "**" + except: ["set-app-params.sh","set-auth-keys.sh","set-instance-params.sh","start-app.sh"] + owner: admin + group: admin + type: + - file - object: /home/admin/xyz-hub pattern: "*.sh" owner: admin @@ -58,6 +65,18 @@ permissions: mode: 755 type: - file + - object: /home/admin/xyz-hub/.config + pattern: "**" + owner: admin + group: admin + type: + - file + - object: /home/admin/xyz-hub/.config/auth + pattern: "**" + owner: admin + group: admin + type: + - file - object: /etc/systemd/system/xyz-hub.service owner: admin group: admin From 511ad41c6858aecbdb899f2032c2e14798e26898 Mon Sep 17 00:00:00 2001 From: Hiren Patel Date: Sat, 15 Jul 2023 01:27:05 +0530 Subject: [PATCH 10/18] corrected permissions in codedeploy spec file --- deployment/codedeploy/appspec.yml | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/deployment/codedeploy/appspec.yml b/deployment/codedeploy/appspec.yml index de92ff081..0fe4cfc0b 100644 --- a/deployment/codedeploy/appspec.yml +++ b/deployment/codedeploy/appspec.yml @@ -39,18 +39,21 @@ files: # "permissions" section altogether. A blank or incomplete "permissions" # section may cause associated deployments to fail. permissions: - - object: /home/admin/xyz-hub + # change owner for xyz-hub directory + - object: /home/admin + pattern: "xyz-hub" owner: admin group: admin type: - directory + # change owner recursively for all subdirectories (except xyz-hub itself) - object: /home/admin/xyz-hub pattern: "**" - except: ["set-app-params.sh","set-auth-keys.sh","set-instance-params.sh","start-app.sh"] owner: admin group: admin type: - directory + # change owner for all files in xyz-hub directory (except shell scripts) - object: /home/admin/xyz-hub pattern: "**" except: ["set-app-params.sh","set-auth-keys.sh","set-instance-params.sh","start-app.sh"] @@ -58,6 +61,7 @@ permissions: group: admin type: - file + # change owner+permission for all shell scripts in xyz-hub directory - object: /home/admin/xyz-hub pattern: "*.sh" owner: admin @@ -65,19 +69,23 @@ permissions: mode: 755 type: - file + # change owner for all files inside .config directory - object: /home/admin/xyz-hub/.config pattern: "**" owner: admin group: admin type: - file + # change owner for all files inside auth directory - object: /home/admin/xyz-hub/.config/auth pattern: "**" owner: admin group: admin type: - file - - object: /etc/systemd/system/xyz-hub.service + # change permission for file xyz-hub.service + - object: /etc/systemd/system + pattern: "xyz-hub.service" owner: admin group: admin type: From 2623c4b328b575396da35cfb50283c1ce4551b2b Mon Sep 17 00:00:00 2001 From: Hiren Patel Date: Sat, 15 Jul 2023 01:32:23 +0530 Subject: [PATCH 11/18] updated stop service script for codedeploy --- deployment/codedeploy/scripts/ApplicationStop.sh | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/deployment/codedeploy/scripts/ApplicationStop.sh b/deployment/codedeploy/scripts/ApplicationStop.sh index 9028cfdc1..4f8e5e2f9 100644 --- a/deployment/codedeploy/scripts/ApplicationStop.sh +++ b/deployment/codedeploy/scripts/ApplicationStop.sh @@ -1,5 +1,11 @@ #!/bin/bash -# Stop application -echo "Stopping Naksha service..." -sudo systemctl stop xyz-hub +# Stop Naksha service (only if it was configured) +CODE=0 +sudo systemctl list-unit-files --all | grep -Fq "xyz-hub.service" || CODE=1 +if [[ $CODE -eq 0 ]]; then + echo ">> Stopping service [xyz-hub]..." + sudo systemctl stop xyz-hub +else + echo ">> Service [xyz-hub] not found. Nothing to stop" +fi From 240b794f70b7a5c349a50b964348a6ef0a4178d3 Mon Sep 17 00:00:00 2001 From: Hiren Patel Date: Sat, 15 Jul 2023 01:56:44 +0530 Subject: [PATCH 12/18] corrected file permission in codedeploy spec file --- deployment/codedeploy/appspec.yml | 14 -------------- 1 file changed, 14 deletions(-) diff --git a/deployment/codedeploy/appspec.yml b/deployment/codedeploy/appspec.yml index 0fe4cfc0b..333a95639 100644 --- a/deployment/codedeploy/appspec.yml +++ b/deployment/codedeploy/appspec.yml @@ -69,20 +69,6 @@ permissions: mode: 755 type: - file - # change owner for all files inside .config directory - - object: /home/admin/xyz-hub/.config - pattern: "**" - owner: admin - group: admin - type: - - file - # change owner for all files inside auth directory - - object: /home/admin/xyz-hub/.config/auth - pattern: "**" - owner: admin - group: admin - type: - - file # change permission for file xyz-hub.service - object: /etc/systemd/system pattern: "xyz-hub.service" From 1508330ff5e59a9b620d071e3c754c044b08178c Mon Sep 17 00:00:00 2001 From: Hiren Patel Date: Sat, 15 Jul 2023 02:11:05 +0530 Subject: [PATCH 13/18] added xyz-hub folder in codedeploy setup to resolve permission issue --- .github/workflows/reusable-build-and-publish.yml | 2 +- CONTRIBUTING.md | 2 +- deployment/codedeploy/appspec.yml | 2 +- .../contents/{ => xyz-hub}/.config/auth/dummyJwt.json | 0 .../codedeploy/contents/{ => xyz-hub}/.config/config.json | 0 .../contents/{ => xyz-hub}/.config/connector-config.json | 0 deployment/codedeploy/contents/{ => xyz-hub}/set-app-params.sh | 0 deployment/codedeploy/contents/{ => xyz-hub}/set-auth-keys.sh | 0 .../codedeploy/contents/{ => xyz-hub}/set-instance-params.sh | 0 deployment/codedeploy/contents/{ => xyz-hub}/start-app.sh | 0 deployment/codedeploy/contents/{ => xyz-hub}/xyz-hub.service | 0 11 files changed, 3 insertions(+), 3 deletions(-) rename deployment/codedeploy/contents/{ => xyz-hub}/.config/auth/dummyJwt.json (100%) rename deployment/codedeploy/contents/{ => xyz-hub}/.config/config.json (100%) rename deployment/codedeploy/contents/{ => xyz-hub}/.config/connector-config.json (100%) rename deployment/codedeploy/contents/{ => xyz-hub}/set-app-params.sh (100%) rename deployment/codedeploy/contents/{ => xyz-hub}/set-auth-keys.sh (100%) rename deployment/codedeploy/contents/{ => xyz-hub}/set-instance-params.sh (100%) rename deployment/codedeploy/contents/{ => xyz-hub}/start-app.sh (100%) rename deployment/codedeploy/contents/{ => xyz-hub}/xyz-hub.service (100%) diff --git a/.github/workflows/reusable-build-and-publish.yml b/.github/workflows/reusable-build-and-publish.yml index e3c14306c..dc9734254 100644 --- a/.github/workflows/reusable-build-and-publish.yml +++ b/.github/workflows/reusable-build-and-publish.yml @@ -45,7 +45,7 @@ jobs: ### TODO : Publish to maven central repository - name: Prepare CodeDeploy artifact content run: | - cp -p $SERVICE_JAR_DIR/xyz-hub-service.jar $CODEDEPLOY_DIR/contents/ + cp -p $SERVICE_JAR_DIR/xyz-hub-service.jar $CODEDEPLOY_DIR/contents/xyz-hub/ - name: List CodeDeploy artifact content run: | ls -lR $CODEDEPLOY_DIR diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 56aa2dd39..704a90a64 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -43,4 +43,4 @@ Eventually, before making a pull request, ensure following: 1. If any **new secret** parameter is introduced, then mention in pull-request as an indication for the repo-owner to add the secret in respective cloud environments. 2. If any **new config** (not a secret) parameter is introduced in default [config.json](xyz-hub-service/src/main/resources/config.json), -ensure the same is added into **deployment** [config.json](deployment/codedeploy/contents/.config/config.json) as well. +ensure the same is added into **deployment** [config.json](deployment/codedeploy/contents/xyz-hub/.config/config.json) as well. diff --git a/deployment/codedeploy/appspec.yml b/deployment/codedeploy/appspec.yml index 333a95639..e3f24ec00 100644 --- a/deployment/codedeploy/appspec.yml +++ b/deployment/codedeploy/appspec.yml @@ -25,7 +25,7 @@ os: linux file_exists_behavior: OVERWRITE files: - source: /contents - destination: /home/admin/xyz-hub + destination: /home/admin - source: /contents/xyz-hub.service destination: /etc/systemd/system # For deployments to Amazon Linux, Ubuntu Server, or RHEL instances, diff --git a/deployment/codedeploy/contents/.config/auth/dummyJwt.json b/deployment/codedeploy/contents/xyz-hub/.config/auth/dummyJwt.json similarity index 100% rename from deployment/codedeploy/contents/.config/auth/dummyJwt.json rename to deployment/codedeploy/contents/xyz-hub/.config/auth/dummyJwt.json diff --git a/deployment/codedeploy/contents/.config/config.json b/deployment/codedeploy/contents/xyz-hub/.config/config.json similarity index 100% rename from deployment/codedeploy/contents/.config/config.json rename to deployment/codedeploy/contents/xyz-hub/.config/config.json diff --git a/deployment/codedeploy/contents/.config/connector-config.json b/deployment/codedeploy/contents/xyz-hub/.config/connector-config.json similarity index 100% rename from deployment/codedeploy/contents/.config/connector-config.json rename to deployment/codedeploy/contents/xyz-hub/.config/connector-config.json diff --git a/deployment/codedeploy/contents/set-app-params.sh b/deployment/codedeploy/contents/xyz-hub/set-app-params.sh similarity index 100% rename from deployment/codedeploy/contents/set-app-params.sh rename to deployment/codedeploy/contents/xyz-hub/set-app-params.sh diff --git a/deployment/codedeploy/contents/set-auth-keys.sh b/deployment/codedeploy/contents/xyz-hub/set-auth-keys.sh similarity index 100% rename from deployment/codedeploy/contents/set-auth-keys.sh rename to deployment/codedeploy/contents/xyz-hub/set-auth-keys.sh diff --git a/deployment/codedeploy/contents/set-instance-params.sh b/deployment/codedeploy/contents/xyz-hub/set-instance-params.sh similarity index 100% rename from deployment/codedeploy/contents/set-instance-params.sh rename to deployment/codedeploy/contents/xyz-hub/set-instance-params.sh diff --git a/deployment/codedeploy/contents/start-app.sh b/deployment/codedeploy/contents/xyz-hub/start-app.sh similarity index 100% rename from deployment/codedeploy/contents/start-app.sh rename to deployment/codedeploy/contents/xyz-hub/start-app.sh diff --git a/deployment/codedeploy/contents/xyz-hub.service b/deployment/codedeploy/contents/xyz-hub/xyz-hub.service similarity index 100% rename from deployment/codedeploy/contents/xyz-hub.service rename to deployment/codedeploy/contents/xyz-hub/xyz-hub.service From 6aeae472272fa9926b054de6d2543b9b6c9c4737 Mon Sep 17 00:00:00 2001 From: Hiren Patel Date: Sat, 15 Jul 2023 02:15:57 +0530 Subject: [PATCH 14/18] corrected service file path for codedeploy spec file --- deployment/codedeploy/appspec.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/deployment/codedeploy/appspec.yml b/deployment/codedeploy/appspec.yml index e3f24ec00..4c38055e1 100644 --- a/deployment/codedeploy/appspec.yml +++ b/deployment/codedeploy/appspec.yml @@ -26,7 +26,7 @@ file_exists_behavior: OVERWRITE files: - source: /contents destination: /home/admin - - source: /contents/xyz-hub.service + - source: /contents/xyz-hub/xyz-hub.service destination: /etc/systemd/system # For deployments to Amazon Linux, Ubuntu Server, or RHEL instances, # you can specify a "permissions" From b91419a31925646582571ada03eac6b03c1a5661 Mon Sep 17 00:00:00 2001 From: Hiren Patel Date: Sat, 15 Jul 2023 02:26:30 +0530 Subject: [PATCH 15/18] added folder permission in codedeploy spec file --- deployment/codedeploy/appspec.yml | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/deployment/codedeploy/appspec.yml b/deployment/codedeploy/appspec.yml index 4c38055e1..f41f1fa20 100644 --- a/deployment/codedeploy/appspec.yml +++ b/deployment/codedeploy/appspec.yml @@ -40,8 +40,7 @@ files: # section may cause associated deployments to fail. permissions: # change owner for xyz-hub directory - - object: /home/admin - pattern: "xyz-hub" + - object: /home/admin/xyz-hub owner: admin group: admin type: From 67c9249e4b0296fe08c8e42eba080d911294f5aa Mon Sep 17 00:00:00 2001 From: Hiren Patel Date: Sat, 15 Jul 2023 02:49:08 +0530 Subject: [PATCH 16/18] corrected folder permission in codedeploy spec file --- deployment/codedeploy/appspec.yml | 7 ------- 1 file changed, 7 deletions(-) diff --git a/deployment/codedeploy/appspec.yml b/deployment/codedeploy/appspec.yml index f41f1fa20..1302f3b4c 100644 --- a/deployment/codedeploy/appspec.yml +++ b/deployment/codedeploy/appspec.yml @@ -45,13 +45,6 @@ permissions: group: admin type: - directory - # change owner recursively for all subdirectories (except xyz-hub itself) - - object: /home/admin/xyz-hub - pattern: "**" - owner: admin - group: admin - type: - - directory # change owner for all files in xyz-hub directory (except shell scripts) - object: /home/admin/xyz-hub pattern: "**" From 96c6d7e00ef83a9159011fa310fb11d80d61b46c Mon Sep 17 00:00:00 2001 From: Hiren Patel Date: Sat, 15 Jul 2023 02:57:25 +0530 Subject: [PATCH 17/18] corrected folder permission --- deployment/codedeploy/appspec.yml | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/deployment/codedeploy/appspec.yml b/deployment/codedeploy/appspec.yml index 1302f3b4c..f69e1e5d9 100644 --- a/deployment/codedeploy/appspec.yml +++ b/deployment/codedeploy/appspec.yml @@ -40,6 +40,13 @@ files: # section may cause associated deployments to fail. permissions: # change owner for xyz-hub directory + - object: /home/admin + pattern: "xyz-hub" + owner: admin + group: admin + type: + - directory + # change owner for all subdirectories inside xyz-hub - object: /home/admin/xyz-hub owner: admin group: admin From 8c9bd64b53f1536d1d5a3a0f99f0cac3d68b74c1 Mon Sep 17 00:00:00 2001 From: Hiren Patel Date: Sat, 22 Jul 2023 12:26:19 +0530 Subject: [PATCH 18/18] Updating OTEL version to 1.28.0 --- xyz-hub-service/pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/xyz-hub-service/pom.xml b/xyz-hub-service/pom.xml index 7c119687c..b8b63c6d9 100644 --- a/xyz-hub-service/pom.xml +++ b/xyz-hub-service/pom.xml @@ -47,7 +47,7 @@ deployment/local/config.json docker-compose.yml 2.20.11 - 1.27.0 + 1.28.0