Skip to content

Commit

Permalink
Merge branch 'master' into fix/note
Browse files Browse the repository at this point in the history
  • Loading branch information
ozyx authored Aug 28, 2023
2 parents bc5d7b1 + a8678aa commit b941d1e
Show file tree
Hide file tree
Showing 8 changed files with 96 additions and 38 deletions.
5 changes: 4 additions & 1 deletion .npmrc
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
loglevel=warn

#Prevent folks from ignoring an important error when building from source
engine-strict=true
engine-strict=true

# Dont include lockfile
package-lock=false
11 changes: 9 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@
"cov:unit:publish": "codecov --disable=gcov -f ./coverage/unit/lcov.info -F unit",
"prepare": "npm run build:prod && npx tsc"
},
"homepage": "https://nasa.github.io/openmct",
"repository": {
"type": "git",
"url": "https://github.com/nasa/openmct.git"
Expand All @@ -126,6 +127,12 @@
"ios_saf >= 16",
"Safari >= 16"
],
"author": "National Aeronautics and Space Administration",
"license": "Apache-2.0"
"author": {
"name": "National Aeronautics and Space Administration",
"url": "https://www.nasa.gov"
},
"license": "Apache-2.0",
"keywords": [
"nasa"
]
}
19 changes: 18 additions & 1 deletion src/api/telemetry/TelemetryAPI.js
Original file line number Diff line number Diff line change
Expand Up @@ -784,6 +784,7 @@ export default class TelemetryAPI {
*/
getLimits(domainObject) {
const provider = this.#findLimitEvaluator(domainObject);

if (!provider || !provider.getLimits) {
return {
limits: function () {
Expand All @@ -792,7 +793,23 @@ export default class TelemetryAPI {
};
}

return provider.getLimits(domainObject);
const abortController = new AbortController();
const options = { signal: abortController.signal };
this.requestAbortControllers.add(abortController);

try {
return provider.getLimits(domainObject, options);
} catch (error) {
if (error.name !== 'AbortError') {
this.openmct.notifications.error(
'Error requesting telemetry data, see console for details'
);
}

throw new Error(error);
} finally {
this.requestAbortControllers.delete(abortController);
}
}
}

Expand Down
7 changes: 6 additions & 1 deletion src/plugins/autoflow/AutoflowTabularRowController.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,12 @@ define([], function () {
this.updateRowData.bind(this)
);

this.openmct.telemetry.request(this.domainObject, { size: 1 }).then(
const options = {
size: 1,
strategy: 'latest',
timeContext: this.openmct.time.getContextForView([])
};
this.openmct.telemetry.request(this.domainObject, options).then(
function (history) {
if (!this.initialized && history.length > 0) {
this.updateRowData(history[history.length - 1]);
Expand Down
6 changes: 5 additions & 1 deletion src/plugins/gauge/components/Gauge.vue
Original file line number Diff line number Diff line change
Expand Up @@ -638,7 +638,11 @@ export default {

this.valueKey = this.metadata.valuesForHints(['range'])[0].source;

this.openmct.telemetry.request(domainObject, { strategy: 'latest' }).then((values) => {
const options = {
strategy: 'latest',
timeContext: this.openmct.time.getContextForView([])
};
this.openmct.telemetry.request(domainObject, options).then((values) => {
const length = values.length;
this.updateValue(values[length - 1]);
});
Expand Down
1 change: 1 addition & 0 deletions src/plugins/imagery/components/ImageryView.vue
Original file line number Diff line number Diff line change
Expand Up @@ -864,6 +864,7 @@ export default {
if (this.domainObject.configuration) {
const persistedLayers = this.domainObject.configuration.layers;
if (!persistedLayers) {
this.layers.forEach((layer) => (layer.visible = false));
return;
}

Expand Down
8 changes: 8 additions & 0 deletions src/plugins/persistence/couch/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,14 @@ sh ./src/plugins/persistence/couch/replace-localstorage-with-couchdb-indexhtml.s

Open MCT will now use your local CouchDB container as its persistence store. Access the CouchDB instance manager by visiting <http://localhost:5984/_utils>.

### Removing CouchDB Container completely

To completely remove the CouchDB container and volumes:

```sh
docker stop couch-couchdb-1;docker rm couch-couchdb-1;docker volume rm couch_couchdb
```

## macOS

While we highly recommend using the CouchDB docker-compose installation, it is still possible to install CouchDB through other means.
Expand Down
77 changes: 45 additions & 32 deletions src/plugins/persistence/couch/setup-couchdb.sh
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ if [ "${COUCH_ADMIN_PASSWORD}" ]; then
CURL_USERPASS_ARG+=":${COUCH_ADMIN_PASSWORD}"
fi

# Functions
resource_exists() {
response=$(curl -u "${CURL_USERPASS_ARG}" -s -o /dev/null -I -w "%{http_code}" $1);
if [ "200" == "${response}" ]; then
Expand All @@ -29,16 +28,16 @@ resource_exists() {
}

db_exists() {
resource_exists $COUCH_BASE_LOCAL/$OPENMCT_DATABASE_NAME
resource_exists "$COUCH_BASE_LOCAL"/"$OPENMCT_DATABASE_NAME"
}

create_db() {
response=$(curl -su "${CURL_USERPASS_ARG}" -XPUT $COUCH_BASE_LOCAL/$OPENMCT_DATABASE_NAME);
echo $response
response=$(curl -su "${CURL_USERPASS_ARG}" -XPUT "$COUCH_BASE_LOCAL"/"$OPENMCT_DATABASE_NAME");
echo "$response"
}

admin_user_exists() {
response=$(curl -su "${CURL_USERPASS_ARG}" -o /dev/null -I -w "%{http_code}" $COUCH_BASE_LOCAL/_node/$COUCH_NODE_NAME/_config/admins/$COUCH_ADMIN_USER);
response=$(curl -su "${CURL_USERPASS_ARG}" -o /dev/null -I -w "%{http_code}" "$COUCH_BASE_LOCAL"/_node/"$COUCH_NODE_NAME"/_config/admins/"$COUCH_ADMIN_USER");
if [ "200" == "${response}" ]; then
echo "TRUE"
else
Expand All @@ -48,26 +47,26 @@ admin_user_exists() {

create_admin_user() {
echo Creating admin user
curl -X PUT $COUCH_BASE_LOCAL/_node/$COUCH_NODE_NAME/_config/admins/$COUCH_ADMIN_USER -d \'"$COUCH_ADMIN_PASSWORD"\'
curl -X PUT "$COUCH_BASE_LOCAL"/_node/"$COUCH_NODE_NAME"/_config/admins/"$COUCH_ADMIN_USER" -d \'"$COUCH_ADMIN_PASSWORD"\'
}

is_cors_enabled() {
resource_exists $COUCH_BASE_LOCAL/_node/$COUCH_NODE_NAME/_config/httpd/enable_cors
resource_exists "$COUCH_BASE_LOCAL"/_node/"$COUCH_NODE_NAME"/_config/httpd/enable_cors
}

enable_cors() {
curl -su "${CURL_USERPASS_ARG}" -o /dev/null -X PUT $COUCH_BASE_LOCAL/_node/$COUCH_NODE_NAME/_config/httpd/enable_cors -d '"true"'
curl -su "${CURL_USERPASS_ARG}" -o /dev/null -X PUT $COUCH_BASE_LOCAL/_node/$COUCH_NODE_NAME/_config/cors/origins -d '"*"'
curl -su "${CURL_USERPASS_ARG}" -o /dev/null -X PUT $COUCH_BASE_LOCAL/_node/$COUCH_NODE_NAME/_config/cors/credentials -d '"true"'
curl -su "${CURL_USERPASS_ARG}" -o /dev/null -X PUT $COUCH_BASE_LOCAL/_node/$COUCH_NODE_NAME/_config/cors/methods -d '"GET, PUT, POST, HEAD, DELETE"'
curl -su "${CURL_USERPASS_ARG}" -o /dev/null -X PUT $COUCH_BASE_LOCAL/_node/$COUCH_NODE_NAME/_config/cors/headers -d '"accept, authorization, content-type, origin, referer, x-csrf-token"'
curl -su "${CURL_USERPASS_ARG}" -o /dev/null -X PUT "$COUCH_BASE_LOCAL"/_node/"$COUCH_NODE_NAME"/_config/httpd/enable_cors -d '"true"'
curl -su "${CURL_USERPASS_ARG}" -o /dev/null -X PUT "$COUCH_BASE_LOCAL"/_node/"$COUCH_NODE_NAME"/_config/cors/origins -d '"*"'
curl -su "${CURL_USERPASS_ARG}" -o /dev/null -X PUT "$COUCH_BASE_LOCAL"/_node/"$COUCH_NODE_NAME"/_config/cors/credentials -d '"true"'
curl -su "${CURL_USERPASS_ARG}" -o /dev/null -X PUT "$COUCH_BASE_LOCAL"/_node/"$COUCH_NODE_NAME"/_config/cors/methods -d '"GET, PUT, POST, HEAD, DELETE"'
curl -su "${CURL_USERPASS_ARG}" -o /dev/null -X PUT "$COUCH_BASE_LOCAL"/_node/"$COUCH_NODE_NAME"/_config/cors/headers -d '"accept, authorization, content-type, origin, referer, x-csrf-token"'
}

update_db_permissions() {
local db_name=$1
echo "Updating ${db_name} database permissions"
response=$(curl -su "${CURL_USERPASS_ARG}" --location \
--request PUT $COUCH_BASE_LOCAL/$db_name/_security \
--request PUT "$COUCH_BASE_LOCAL"/"$db_name"/_security \
--header 'Content-Type: application/json' \
--data-raw '{ "admins": {"roles": []},"members": {"roles": []}}')
if [ "{\"ok\":true}" == "${response}" ]; then
Expand All @@ -77,17 +76,24 @@ update_db_permissions() {
fi
}

create_system_tables() {
local system_tables=("_users" "_replicator")
for table in "${system_tables[@]}"; do
echo "Creating $table database"
response=$(curl -su "${CURL_USERPASS_ARG}" -X PUT $COUCH_BASE_LOCAL/$table)
if [ "{\"ok\":true}" == "${response}" ]; then
echo "Successfully created $table database"
else
echo "Unable to create $table database"
fi
done
create_users_table() {
echo "Creating _users database"
response=$(curl -su "${CURL_USERPASS_ARG}" -XPUT "$COUCH_BASE_LOCAL"/_users)
if [ "{\"ok\":true}" == "${response}" ]; then
echo "Successfully created _users database"
else
echo "Unable to create _users database"
fi
}

create_replicator_table() {
echo "Creating _replicator database"
response=$(curl -su "${CURL_USERPASS_ARG}" -XPUT "$COUCH_BASE_LOCAL"/_replicator)
if [ "{\"ok\":true}" == "${response}" ]; then
echo "Successfully created _replicator database"
else
echo "Unable to create _replicator database"
fi
}

# Main script execution
Expand All @@ -100,17 +106,24 @@ else
echo "Admin user exists"
fi

# Check if system tables exist; if not, create them.
system_tables_exist=$(resource_exists $COUCH_BASE_LOCAL/_users)
if [ "TRUE" == "${system_tables_exist}" ]; then
echo "System tables exist, skipping creation"
# Check if the _users table exists; if not, create it.
users_table_exists=$(resource_exists "$COUCH_BASE_LOCAL"/_users)
if [ "FALSE" == "${users_table_exists}" ]; then
create_users_table
else
echo "_users database already exists, skipping creation"
fi

# Check if the _replicator database exists; if not, create it.
replicator_table_exists=$(resource_exists "$COUCH_BASE_LOCAL/_replicator")
if [ "FALSE" == "${replicator_table_exists}" ]; then
create_replicator_table
else
echo "Fresh install, creating system tables"
create_system_tables
echo "_replicator database already exists, skipping creation"
fi

# Check if the database exists; if not, create it.
if [ "FALSE" == $(db_exists) ]; then
if [ "FALSE" == "$(db_exists)" ]; then
response=$(create_db)
if [ "{\"ok\":true}" == "${response}" ]; then
echo "Database successfully created"
Expand All @@ -126,7 +139,7 @@ update_db_permissions "_replicator"
update_db_permissions "${OPENMCT_DATABASE_NAME}"

# Check if CORS is enabled; if not, enable it.
if [ "FALSE" == $(is_cors_enabled) ]; then
if [ "FALSE" == "$(is_cors_enabled)" ]; then
echo "Enabling CORS"
enable_cors
else
Expand Down

0 comments on commit b941d1e

Please sign in to comment.