Skip to content

Commit

Permalink
add serverless instances handling
Browse files Browse the repository at this point in the history
RE, apply to instance
  • Loading branch information
taras-dubyk committed Feb 14, 2022
1 parent a96a7ce commit 7bb690a
Show file tree
Hide file tree
Showing 6 changed files with 122 additions and 17 deletions.
46 changes: 46 additions & 0 deletions adapter/0.1.30.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
/**
* Copyright © 2016-2018 by IntegrIT S.A. dba Hackolade. All rights reserved.
*
* The copyright to the computer software herein is the property of IntegrIT S.A.
* The software may be used and/or copied only with the written permission of
* IntegrIT S.A. or in accordance with the terms and conditions stipulated in
* the agreement/contract under which the software has been supplied.
*
* {
* "add": {
* "entity": [<names of new property>],
* "container": [<names of new property>],
* "model": [<names of new property>],
* "view": [<names of new property>],
* "field": {
* "<type>": [<names of new property>]
* }
* },
* "remove": {
* "entity": [<names of new property>],
* "container": [<names of new property>],
* "model": [<names of new property>],
* "view": [<names of new property>],
* "field": {
* "<type>": [<names of new property>]
* }
* },
* "modify": {
* "entity": [
* {
* "from": { <properties that identify record> },
* "to": { <properties that need to be changed> }
* }
* ],
* "container": [],
* "model": [],
* "view": [],
* "field": []
* },
* }
*/
{
"add": {
"container": ["capacityMode"]
}
}
10 changes: 10 additions & 0 deletions forward_engineering/applyToInstance/applyToInstanceHelper.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,16 @@ const applyToInstanceHelper = (_) => ({
return -1;
}
},

getContainerThroughputProps(containerData) {
if (containerData.capacityMode === "Serverless") {
return {};
}
if (containerData.autopilot) {
return { maxThroughput: containerData.throughput || 4000 };
}
return { throughput: containerData.throughput || 400 };
}
});

module.exports = applyToInstanceHelper;
8 changes: 5 additions & 3 deletions forward_engineering/applyToInstance/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -87,9 +87,9 @@ module.exports = {
logger.log('info', connectionInfo, 'Apply to instance connection settings', connectionInfo.hiddenKeys);
const client = helper.setUpDocumentClient(connectionInfo);
const script = parseScript(connectionInfo.script);
const containerData = _.get(connectionInfo, 'containerData');
const databaseId = _.get(containerData, '[0].dbId');
const containerId = _.get(containerData, '[0].name');
const containerData = _.get(connectionInfo, 'containerData[0]');
const databaseId = _.get(containerData, 'dbId');
const containerId = _.get(containerData, 'name');

if (!databaseId) {
return callback({
Expand All @@ -109,6 +109,8 @@ module.exports = {
id: containerId,
partitionKey: script.partitionKey,
defaultTtl: helper.getTTL(containerData),
...helper.getContainerThroughputProps(containerData),

});

progress('Add sample documents ...');
Expand Down
57 changes: 47 additions & 10 deletions properties_pane/container_level/containerLevelConfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,13 @@ making sure that you maintain a proper JSON format.
"template": "orderedList"
}]
},
{
"propertyName": "Description",
"propertyKeyword": "description",
"propertyTooltip": "description",
"propertyType": "details",
"template": "textarea"
},
{
"propertyName": "Database ID",
"propertyKeyword": "dbId",
Expand All @@ -191,17 +198,24 @@ making sure that you maintain a proper JSON format.
}
},
{
"propertyName": "Description",
"propertyKeyword": "description",
"propertyTooltip": "description",
"propertyType": "details",
"template": "textarea"
"propertyName": "Capacity mode",
"propertyKeyword": "capacityMode",
"propertyTooltip": "Choose the capacity mode",
"propertyType": "select",
"options": [
"Provisioned throughput",
"Serverless"
]
},
{
"propertyName": "Autoscale",
"propertyKeyword": "autopilot",
"propertyType": "checkbox",
"template": "boolean"
"template": "boolean",
"dependency": {
"key": "capacityMode",
"value": "Provisioned throughput"
}
},
{
"propertyName": "Maximum throughput (RU/s)",
Expand All @@ -210,8 +224,17 @@ making sure that you maintain a proper JSON format.
"propertyType": "numeric",
"valueType": "number",
"dependency": {
"key": "autopilot",
"value": true
"type": "and",
"values": [
{
"key": "autopilot",
"value": true
},
{
"key": "capacityMode",
"value": "Provisioned throughput"
}
]
}
},
{
Expand All @@ -221,8 +244,22 @@ making sure that you maintain a proper JSON format.
"propertyType": "numeric",
"valueType": "number",
"dependency": {
"key": "autopilot",
"value": false
"type": "and",
"values": [
{
"type": "not",
"values": [
{
"key": "autopilot",
"value": true
}
]
},
{
"key": "capacityMode",
"value": "Provisioned throughput"
}
]
}
},
{
Expand Down
3 changes: 2 additions & 1 deletion properties_pane/defaultData.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@
"name": "New container",
"partitionKey": [],
"indexes": [],
"autopilot": false
"autopilot": false,
"capacityMode": "Provisioned throughput"
},
"collection": {
"collectionName": "New item type",
Expand Down
15 changes: 12 additions & 3 deletions reverse_engineering/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -132,11 +132,12 @@ module.exports = {
const udfs = await getUdfs(containerInstance);
const collection = await getCollectionById(containerInstance);
const offerInfo = await getOfferType(collection, logger);
const { autopilot, throughput } = getOfferProps(offerInfo);
const { autopilot, throughput, capacityMode } = getOfferProps(offerInfo);
const partitionKey = getPartitionKey(collection);
const indexes = getIndexes(collection.indexingPolicy);
const bucketInfo = Object.assign({
dbId: data.database,
capacityMode,
throughput,
autopilot,
partitionKey,
Expand Down Expand Up @@ -552,16 +553,24 @@ function getUniqueKeys(collection) {
}

function getOfferProps(offer) {
if (!offer) {
return {
capacityMode: 'Serverless',
autopilot: false,
};
}
const isAutopilotOn = _.get(offer, 'content.offerAutopilotSettings');
if (isAutopilotOn) {
return {
autopilot: true,
throughput: offer.content.offerAutopilotSettings.maximumTierThroughput
throughput: offer.content.offerAutopilotSettings.maximumTierThroughput,
capacityMode: 'Provisioned throughput',
};
}
return {
autopilot: false,
throughput: offer ? offer.content.offerThroughput : ''
throughput: offer ? offer.content.offerThroughput : '',
capacityMode: 'Provisioned throughput',
};
}

Expand Down

0 comments on commit 7bb690a

Please sign in to comment.