Skip to content

Commit

Permalink
remove hdi-migrate-all
Browse files Browse the repository at this point in the history
  • Loading branch information
rlindner81 committed Feb 19, 2024
1 parent e70a12f commit 4e8e0b8
Show file tree
Hide file tree
Showing 5 changed files with 0 additions and 117 deletions.
7 changes: 0 additions & 7 deletions docs/hana-management/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ Commands for this area are:
hdirt --hdi-rebind-tenant TENANT_ID [PARAMS] rebind tenant hdi container instances
hdira --hdi-rebind-all [PARAMS] rebind all hdi container instances
--hdi-repair-bindings [PARAMS] create missing and delete ambiguous bindings
--hdi-migrate-all migrate all hdi containers to service-manager
* --hdi-delete-tenant TENANT_ID delete hdi container instance and bindings for tenant
* --hdi-delete-all delete all hdi container instances and bindings
... [TENANT_ID] filter list for tenant id
Expand Down Expand Up @@ -148,12 +147,6 @@ manager. In other words, `mtx hdirt <tenant_id> '{"special":true}'` corresponds
cf bind-service <service-manager> <hdi-shared service-instance of tenant_id> -c '{"special":true}'
```

## HDI Migrate

The migration command `mtx --hdi-migrate-all` is a convenience functionality for migrating instance manager maintained
hdi containers and bindings to service manager. It will take care to not only migrate the underlying containers, but
also create new bindings for all of them so they can be accessed like before.

## HDI Delete

The deletion commands are only sensible for cleanup after some mocking/testing purposes.
Expand Down
3 changes: 0 additions & 3 deletions docs/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,6 @@ commands:
hdirt --hdi-rebind-tenant TENANT_ID [PARAMS] rebind tenant hdi container instances
hdira --hdi-rebind-all [PARAMS] rebind all hdi container instances
--hdi-repair-bindings [PARAMS] create missing and delete ambiguous bindings
--hdi-migrate-all migrate all hdi containers to service-manager
* --hdi-delete-tenant TENANT_ID delete hdi container instance and bindings for tenant
* --hdi-delete-all delete all hdi container instances and bindings
... [TENANT_ID] filter list for tenant id
Expand Down Expand Up @@ -124,6 +123,4 @@ commands:
either handle this gracefully or be restarted
- `--server-start-debugger` will send SIGUSR1 to node process (requires ssh enabled on cf), which starts debugger _
without restart_
- `--hdi-migrate-all` will call the instance-manager's migration route and then lazily create missing service-bindings
on service-manager
- `TENANT` means you can enter either the subdomain or tenant id and both will work
1 change: 0 additions & 1 deletion src/cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,6 @@ commands:
hdirt --hdi-rebind-tenant TENANT_ID [PARAMS] rebind tenant hdi container instances
hdira --hdi-rebind-all [PARAMS] rebind all hdi container instances
--hdi-repair-bindings [PARAMS] create missing and delete ambiguous bindings
--hdi-migrate-all migrate all hdi containers to service-manager
* --hdi-delete-tenant TENANT_ID delete hdi container instance and bindings for tenant
* --hdi-delete-all delete all hdi container instances and bindings
... [TENANT_ID] filter list for tenant id
Expand Down
5 changes: 0 additions & 5 deletions src/cliOptions.js
Original file line number Diff line number Diff line change
Expand Up @@ -243,11 +243,6 @@ module.exports = {
callback: hdi.hdiRepairBindings,
useCache: false,
},
HDI_MIGRATE_ALL: {
commandVariants: ["--hdi-migrate-all"],
callback: hdi.hdiMigrateAll,
useCache: false,
},
HDI_DELETE_TENANT: {
commandVariants: ["--hdi-delete-tenant"],
requiredPassArgs: [PASS_ARG.TENANT_ID],
Expand Down
101 changes: 0 additions & 101 deletions src/submodules/hanaManagement.js
Original file line number Diff line number Diff line change
Expand Up @@ -643,106 +643,6 @@ const hdiDeleteAllInstanceManager = async (context) => {
const hdiDeleteAll = async (context) =>
(await _isServiceManager(context)) ? hdiDeleteAllServiceManager(context) : hdiDeleteAllInstanceManager(context);

const _lazyCreateServiceBinding = async (tenant_id, sm_url, token) => {
const { items: bindings } = await (
await request({
url: sm_url,
pathname: `/v1/service_bindings`,
query: { labelQuery: `tenant_id eq '${tenant_id}'` },
auth: { token },
headers: {
"Content-Type": "application/json",
},
logged: false,
})
).json();
if (bindings.length > 0) {
return "FOUND";
}

const { items: instances } = await (
await request({
url: sm_url,
pathname: `/v1/service_instances`,
query: { labelQuery: `tenant_id eq '${tenant_id}'` },
auth: { token },
headers: {
"Content-Type": "application/json",
},
logged: false,
})
).json();
if (instances.length === 0) {
console.error("error: found no service instances for tenant %s--skipping migration for this tenant", tenant_id);
return "ERROR";
}
const [instance] = instances;

await _createBindingServiceManagerFromInstance(sm_url, token, instance);
return "BINDING_CREATED";
};

const hdiMigrateAll = async (context) => {
const { cfEnvServices } = await context.getHdiInfo();
const [serviceManager, instanceManager] = ["service-manager", "managed-hana"].map((name) => {
const services = cfEnvServices[name];
assert(Array.isArray(services), "could not find %s service binding", name);
assert(services.length === 1, "found multiple %s service bindings, expected just one", name);
return services[0];
});

const {
credentials: { get_all_managed_instances_url, migrate_managed_instance_url, user: username, password },
} = instanceManager;
assert(
migrate_managed_instance_url,
"cannot find 'migrate_managed_instance_url' property on instance-manager service"
);
const { credentials } = serviceManager;
const { sm_url } = credentials;
const token = await context.getCachedUaaTokenFromCredentials(credentials);

const containers = await (
await request({
url: get_all_managed_instances_url,
auth: { username, password },
})
).json();

containers.sort(compareForInstanceManagerTenantId);

const headers = ["tenant_id", "instance_manager_migration_status", "service_manager_binding_status"];
const table = [headers];

// NOTE: we want to do this serially
for (const { tenant_id, managed_binding_id } of containers) {
let instance_manager_migration_status = "...";
let service_manager_binding_status = "...";
const response = await request({
method: "POST",
url: migrate_managed_instance_url
.replace("{tenant_id}", tenant_id)
.replace("{service-manager_container_id}", serviceManager.instance_guid),
auth: { username, password },
checkStatus: false,
});
if (!response.ok) {
console.error("got bad response for tenant %s: %s", tenant_id, await response.text());
instance_manager_migration_status = "FOUND";
} else {
const { migration_status } = await response.json();
instance_manager_migration_status = migration_status;
}

service_manager_binding_status = await _lazyCreateServiceBinding(tenant_id, sm_url, token, managed_binding_id);

table.push([tenant_id, instance_manager_migration_status, service_manager_binding_status]);
}

console.log();
return tableList(table);
};

module.exports = {
hdiList,
hdiLongList,
Expand All @@ -753,5 +653,4 @@ module.exports = {
hdiTunnelTenant,
hdiDeleteTenant,
hdiDeleteAll,
hdiMigrateAll,
};

0 comments on commit 4e8e0b8

Please sign in to comment.