-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #87 from PierreBeucher/update-command
Update command
- Loading branch information
Showing
46 changed files
with
1,479 additions
and
608 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,17 @@ | ||
import { CommonConfigurationOutputV1, InstanceStateV1 } from "./state/state"; | ||
|
||
/** | ||
* Configurator are responsible to configure an instance after provisioning, | ||
* such as installing drivers and system packages. | ||
*/ | ||
export interface InstanceConfigurator { | ||
configure(): Promise<void> | ||
configure(): Promise<CommonConfigurationOutputV1> | ||
} | ||
|
||
export abstract class AbstractInstanceConfigurator<ST extends InstanceStateV1> implements InstanceConfigurator { | ||
configure(): Promise<NonNullable<ST["configuration"]["output"]>> { | ||
return this.doConfigure() | ||
} | ||
|
||
abstract doConfigure(): Promise<NonNullable<ST["configuration"]["output"]>> | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,87 +1,104 @@ | ||
import { CLOUDYPAD_PROVIDER_AWS, CLOUDYPAD_PROVIDER_AZURE, CLOUDYPAD_PROVIDER_GCP, CLOUDYPAD_PROVIDER_PAPERSPACE } from './const'; | ||
import { getLogger } from '../log/utils'; | ||
import { StateManager } from './state/manager'; | ||
import { AwsInstanceStateV1 } from '../providers/aws/state'; | ||
import { AwsSubManagerFactory } from '../providers/aws/factory'; | ||
import { InstanceStateV1 } from './state/state'; | ||
import { AzureInstanceStateV1 } from '../providers/azure/state'; | ||
import { PaperspaceInstanceStateV1 } from '../providers/paperspace/state'; | ||
import { GcpInstanceStateV1 } from '../providers/gcp/state'; | ||
import { GcpSubManagerFactory } from '../providers/gcp/factory'; | ||
import { AzureSubManagerFactory } from '../providers/azure/factory'; | ||
import { PaperspaceSubManagerFactory } from '../providers/paperspace/factory'; | ||
import { InstanceManager } from './manager'; | ||
import { GenericInstanceManager, InstanceManager } from './manager'; | ||
import { StateLoader } from './state/loader'; | ||
import { StateParser } from './state/parser'; | ||
import { StateWriter } from './state/writer'; | ||
import { InstanceStateV1 } from './state/state'; | ||
import { StateMigrator } from './state/migrator'; | ||
import { AwsInstanceStateV1 } from '../providers/aws/state'; | ||
import { AzureInstanceStateV1 } from '../providers/azure/state'; | ||
import { GcpInstanceStateV1 } from '../providers/gcp/state'; | ||
import { PaperspaceInstanceStateV1 } from '../providers/paperspace/state'; | ||
import { InstanceUpdater } from './updater'; | ||
|
||
export class InstanceManagerBuilder { | ||
|
||
private static readonly logger = getLogger(InstanceManagerBuilder.name) | ||
|
||
private readonly stateManager: StateManager | ||
|
||
private readonly stateParser = new StateParser() | ||
|
||
constructor() { | ||
this.stateManager = StateManager.default() | ||
getAllInstances(): string[] { | ||
return new StateLoader().listInstances() | ||
} | ||
|
||
getAllInstances(): string[] { | ||
return StateManager.default().listInstances() | ||
private async loadAndMigrateState(instanceName: string): Promise<InstanceStateV1>{ | ||
await new StateMigrator().ensureInstanceStateV1(instanceName) | ||
|
||
const state = await new StateLoader().loadInstanceStateSafe(instanceName) | ||
return state | ||
} | ||
|
||
/** | ||
* Build an InstanceManager for a instance. Load instance state from disk | ||
* and create a related InstanceManager. | ||
*/ | ||
async buildManagerForInstance(name: string): Promise<InstanceManager>{ | ||
const state = await StateManager.default().loadInstanceStateSafe(name) | ||
return this.buildManagerForState(state) | ||
private parseAwsState(rawState: InstanceStateV1): AwsInstanceStateV1 { | ||
return new StateParser().parseAwsStateV1(rawState) | ||
} | ||
|
||
private parseAzureState(rawState: InstanceStateV1): AzureInstanceStateV1 { | ||
return new StateParser().parseAzureStateV1(rawState) | ||
} | ||
|
||
private parseGcpState(rawState: InstanceStateV1): GcpInstanceStateV1 { | ||
return new StateParser().parseGcpStateV1(rawState) | ||
} | ||
|
||
private parsePaperspaceState(rawState: InstanceStateV1): PaperspaceInstanceStateV1 { | ||
return new StateParser().parsePaperspaceStateV1(rawState) | ||
} | ||
|
||
async buildInstanceManager(name: string): Promise<InstanceManager>{ | ||
const state = await this.loadAndMigrateState(name) | ||
|
||
buildManagerForState(state: InstanceStateV1) { | ||
if (state.provision.provider === CLOUDYPAD_PROVIDER_AWS) { | ||
const awsState: AwsInstanceStateV1 = this.stateParser.parseAwsStateV1(state) | ||
return this.buildAwsInstanceManager(awsState) | ||
return new GenericInstanceManager({ | ||
stateWriter: new StateWriter({ state: this.parseAwsState(state)}), | ||
factory: new AwsSubManagerFactory() | ||
}) | ||
} else if (state.provision.provider === CLOUDYPAD_PROVIDER_GCP) { | ||
const gcpState: GcpInstanceStateV1 = this.stateParser.parseGcpStateV1(state) | ||
return this.buildGcpInstanceManager(gcpState) | ||
return new GenericInstanceManager({ | ||
stateWriter: new StateWriter({ state: this.parseGcpState(state)}), | ||
factory: new GcpSubManagerFactory() | ||
}) | ||
} else if (state.provision.provider === CLOUDYPAD_PROVIDER_AZURE) { | ||
const azureState: AzureInstanceStateV1 = this.stateParser.parseAzureStateV1(state) | ||
return this.buildAzureInstanceManager(azureState) | ||
return new GenericInstanceManager({ | ||
stateWriter: new StateWriter({ state: this.parseAzureState(state)}), | ||
factory: new AzureSubManagerFactory() | ||
}) | ||
} else if (state.provision.provider === CLOUDYPAD_PROVIDER_PAPERSPACE) { | ||
const paperspaceState: PaperspaceInstanceStateV1 = this.stateParser.parsePaperspaceStateV1(state) | ||
return this.buildPaperspaceInstanceManager(paperspaceState) | ||
return new GenericInstanceManager({ | ||
stateWriter: new StateWriter({ state: this.parsePaperspaceState(state)}), | ||
factory: new PaperspaceSubManagerFactory() | ||
}) | ||
} else { | ||
throw new Error(`Unknown provider '${state.provision.provider}' in state: ${JSON.stringify(state)}`) | ||
} | ||
} | ||
} | ||
|
||
buildAwsInstanceManager(state: AwsInstanceStateV1){ | ||
return new InstanceManager({ | ||
state: state, | ||
factory: new AwsSubManagerFactory() | ||
}) | ||
async buildAwsInstanceUpdater(instanceName: string): Promise<InstanceUpdater<AwsInstanceStateV1>> { | ||
const rawState = await this.loadAndMigrateState(instanceName) | ||
const stateWriter = new StateWriter({ state: this.parseAwsState(rawState) }) | ||
return new InstanceUpdater({ stateWriter: stateWriter }) | ||
} | ||
|
||
buildGcpInstanceManager(state: GcpInstanceStateV1){ | ||
return new InstanceManager({ | ||
state: state, | ||
factory: new GcpSubManagerFactory() | ||
}) | ||
|
||
async buildGcpInstanceUpdater(instanceName: string): Promise<InstanceUpdater<GcpInstanceStateV1>> { | ||
const rawState = await this.loadAndMigrateState(instanceName) | ||
const stateWriter = new StateWriter({ state: this.parseGcpState(rawState) }) | ||
return new InstanceUpdater({ stateWriter: stateWriter }) | ||
} | ||
|
||
buildAzureInstanceManager(state: AzureInstanceStateV1){ | ||
return new InstanceManager({ | ||
state: state, | ||
factory: new AzureSubManagerFactory() | ||
}) | ||
|
||
async buildAzureInstanceUpdater(instanceName: string): Promise<InstanceUpdater<AzureInstanceStateV1>> { | ||
const rawState = await this.loadAndMigrateState(instanceName) | ||
const stateWriter = new StateWriter({ state: this.parseAzureState(rawState) }) | ||
return new InstanceUpdater({ stateWriter: stateWriter }) | ||
} | ||
|
||
buildPaperspaceInstanceManager(state: PaperspaceInstanceStateV1){ | ||
return new InstanceManager({ | ||
state: state, | ||
factory: new PaperspaceSubManagerFactory() | ||
}) | ||
|
||
async buildPaperspaceInstanceUpdater(instanceName: string): Promise<InstanceUpdater<PaperspaceInstanceStateV1>> { | ||
const rawState = await this.loadAndMigrateState(instanceName) | ||
const stateWriter = new StateWriter({ state: this.parsePaperspaceState(rawState) }) | ||
return new InstanceUpdater({ stateWriter: stateWriter }) | ||
} | ||
|
||
|
||
|
||
} |
Oops, something went wrong.