Skip to content

Commit

Permalink
issue #270, #380
Browse files Browse the repository at this point in the history
1 - Tested Run/DryRun with Check Compatibility
2 - Tested Run/DryRun with Create FHIR Schemas
3 - Tested Run/DryRun with Allocate Tenant

Signed-off-by: Paul Bastide <pbastide@us.ibm.com>
  • Loading branch information
prb112 committed Feb 25, 2020
1 parent 327e176 commit 3b01fcf
Show file tree
Hide file tree
Showing 6 changed files with 66 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import com.ibm.fhir.database.utils.api.IDatabaseTranslator;
import com.ibm.fhir.database.utils.api.TenantStatus;
import com.ibm.fhir.database.utils.common.DataDefinitionUtil;
import com.ibm.fhir.database.utils.dryrun.DryRunContainer;
import com.ibm.fhir.database.utils.model.Tenant;

/**
Expand Down Expand Up @@ -43,7 +44,6 @@ public Tenant run(IDatabaseTranslator translator, Connection c) {
* Execute the encapsulated query against the database and stream the result
* data to the configured target
*/

final String tableName = DataDefinitionUtil.getQualifiedName(schemaName, "TENANTS");
final String SQL = "SELECT mt_id, tenant_status " + " FROM " + tableName
+ " WHERE tenant_name = ?";
Expand All @@ -58,6 +58,13 @@ public Tenant run(IDatabaseTranslator translator, Connection c) {
result.setTenantStatus(TenantStatus.valueOf(rs.getString(2)));
return result;
} else {
if(DryRunContainer.getSingleInstance().isDryRun()) {
Tenant result = new Tenant();
result.setTenantName(tenantName);
result.setTenantId(-100);
result.setTenantStatus(TenantStatus.PROVISIONING);
return result;
}
return null;
}
} catch (SQLException x) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,9 +106,14 @@ public void processTransaction(ISchemaAction action) throws SchemaActionExceptio

// Configure the connection pool
try (ITransaction tx = TransactionFactory.openTransaction(connectionPool, true)) {
if (c == null) {
c = createConnection();
}
JdbcTarget target = new JdbcTarget(c);

try {
Db2Adapter adapter = new Db2Adapter(connectionPool);
action.run(actionBean, null, adapter, transactionProvider);
action.run(actionBean, target, adapter, transactionProvider);
} catch (DataAccessException x) {
// Something went wrong, so mark the transaction as failed
tx.setRollbackOnly();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,15 @@ public void run(ActionBean actionBean, IDatabaseTarget target, IDatabaseAdapter
// this transaction must come from the same pool
logger.info("Allocating new tenant: " + actionBean.getTenantName() + " [key=" + tenantKey + "]");

String adminSchema = actionBean.getAdminSchemaName();
String schemaName = actionBean.getSchemaName();
String tenantName = actionBean.getTenantName();
int tenantId =
adapter.allocateTenant(actionBean.getAdminSchemaName(), actionBean.getSchemaName(),
actionBean.getTenantName(), tenantKey, tenantSalt, TENANT_SEQUENCE);
adapter.allocateTenant(adminSchema, schemaName, tenantName, tenantKey, tenantSalt, TENANT_SEQUENCE);

// The tenant-id is important because this is also used to identify the partition number
logger.info("Tenant Id[" + actionBean.getTenantName() + "] = " + tenantId);

actionBean.setTenantId(tenantId);
actionBean.setTenantKey(tenantKey);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
/*
* (C) Copyright IBM Corp. 2020
*
* SPDX-License-Identifier: Apache-2.0
*/

package com.ibm.fhir.schema.app.test.main;

import com.ibm.fhir.schema.app.Main;
import com.ibm.fhir.schema.app.test.main.helper.TestHelper;

public class AddKeyForTenantMain {
public static void main(String[] args) {
String[] arguments = {
"--prop-file", TestHelper.absolutePathToProperties(),
"--pool-size", "5",
"--schema-name", "FHIRDATA",
"--add-tenant-key", "default"
};
Main.main(arguments);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@ public class AllocateTenantMain {
public static void main(String[] args) {
String[] arguments = {
"--prop-file", TestHelper.absolutePathToProperties(),
"--pool-size", "5",
"--pool-size", "20",
"--schema-name", "FHIRDATA",
"--allocate-tenant", "default"
"--allocate-tenant", "default3"
};
Main.main(arguments);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
/*
* (C) Copyright IBM Corp. 2020
*
* SPDX-License-Identifier: Apache-2.0
*/

package com.ibm.fhir.schema.app.test.main.dryrun;

import com.ibm.fhir.schema.app.Main;
import com.ibm.fhir.schema.app.test.main.helper.TestHelper;

public class AllocateTenantDryRunMain {
public static void main(String[] args) {
String[] arguments = {
"--prop-file", TestHelper.absolutePathToProperties(),
"--pool-size", "5",
"--schema-name", "FHIRDATA",
"--allocate-tenant", "default10",
"--dry-run"
};
Main.main(arguments);
}
}

0 comments on commit 3b01fcf

Please sign in to comment.