From e34340618e146d7a530e5934fa7bd85784584ea2 Mon Sep 17 00:00:00 2001 From: Chengmin Chi Date: Mon, 9 Dec 2019 19:29:58 +0800 Subject: [PATCH] refactor code to fix eslint error --- .../frameworkcontrollerApiClient.ts | 8 +- .../frameworkcontrollerTrainingService.ts | 4 +- .../kubernetes/kubeflow/kubeflowApiClient.ts | 98 +++++++++---------- .../kubeflow/kubeflowTrainingService.ts | 6 +- 4 files changed, 58 insertions(+), 58 deletions(-) diff --git a/src/nni_manager/training_service/kubernetes/frameworkcontroller/frameworkcontrollerApiClient.ts b/src/nni_manager/training_service/kubernetes/frameworkcontroller/frameworkcontrollerApiClient.ts index 5cbd357838..4a891e8852 100644 --- a/src/nni_manager/training_service/kubernetes/frameworkcontroller/frameworkcontrollerApiClient.ts +++ b/src/nni_manager/training_service/kubernetes/frameworkcontroller/frameworkcontrollerApiClient.ts @@ -9,12 +9,12 @@ import { GeneralK8sClient, KubernetesCRDClient } from '../kubernetesApiClient'; /** * FrameworkController Client */ -abstract class FrameworkControllerClient extends KubernetesCRDClient { +class FrameworkControllerClientFactory { /** * Factory method to generate operator client */ // tslint:disable-next-line:function-name - public static generateFrameworkControllerClient(): KubernetesCRDClient { + public static createClient(): KubernetesCRDClient { return new FrameworkControllerClientV1(); } } @@ -22,7 +22,7 @@ abstract class FrameworkControllerClient extends KubernetesCRDClient { /** * FrameworkController ClientV1 */ -class FrameworkControllerClientV1 extends FrameworkControllerClient { +class FrameworkControllerClientV1 extends KubernetesCRDClient { /** * constructor, to initialize frameworkcontroller CRD definition */ @@ -43,4 +43,4 @@ class FrameworkControllerClientV1 extends FrameworkControllerClient { } } -export { FrameworkControllerClient, GeneralK8sClient }; +export { FrameworkControllerClientFactory, GeneralK8sClient }; diff --git a/src/nni_manager/training_service/kubernetes/frameworkcontroller/frameworkcontrollerTrainingService.ts b/src/nni_manager/training_service/kubernetes/frameworkcontroller/frameworkcontrollerTrainingService.ts index 83e70ddea5..fe51c38cf8 100644 --- a/src/nni_manager/training_service/kubernetes/frameworkcontroller/frameworkcontrollerTrainingService.ts +++ b/src/nni_manager/training_service/kubernetes/frameworkcontroller/frameworkcontrollerTrainingService.ts @@ -19,7 +19,7 @@ import { AzureStorageClientUtility } from '../azureStorageClientUtils'; import { NFSConfig } from '../kubernetesConfig'; import { KubernetesTrialJobDetail } from '../kubernetesData'; import { KubernetesTrainingService } from '../kubernetesTrainingService'; -import { FrameworkControllerClient } from './frameworkcontrollerApiClient'; +import { FrameworkControllerClientFactory } from './frameworkcontrollerApiClient'; import { FrameworkControllerClusterConfig, FrameworkControllerClusterConfigAzure, FrameworkControllerClusterConfigFactory, FrameworkControllerClusterConfigNFS, FrameworkControllerTrialConfig} from './frameworkcontrollerConfig'; import { FrameworkControllerJobInfoCollector } from './frameworkcontrollerJobInfoCollector'; @@ -142,7 +142,7 @@ class FrameworkControllerTrainingService extends KubernetesTrainingService imple nfsFrameworkControllerClusterConfig.nfs.path ); } - this.kubernetesCRDClient = FrameworkControllerClient.generateFrameworkControllerClient(); + this.kubernetesCRDClient = FrameworkControllerClientFactory.createClient(); break; case TrialConfigMetadataKey.TRIAL_CONFIG: const frameworkcontrollerTrialJsonObjsect: any = JSON.parse(value); diff --git a/src/nni_manager/training_service/kubernetes/kubeflow/kubeflowApiClient.ts b/src/nni_manager/training_service/kubernetes/kubeflow/kubeflowApiClient.ts index e6e04b0afd..dacf2229d0 100644 --- a/src/nni_manager/training_service/kubernetes/kubeflow/kubeflowApiClient.ts +++ b/src/nni_manager/training_service/kubernetes/kubeflow/kubeflowApiClient.ts @@ -7,55 +7,9 @@ import * as fs from 'fs'; import { GeneralK8sClient, KubernetesCRDClient } from '../kubernetesApiClient'; import { KubeflowOperator } from './kubeflowConfig'; -/** - * KubeflowOperator Client - */ -abstract class KubeflowOperatorClient extends KubernetesCRDClient { - /** - * Factory method to generate operator client - */ - // tslint:disable-next-line:function-name - public static generateOperatorClient(kubeflowOperator: KubeflowOperator, - operatorApiVersion: string): KubernetesCRDClient { - switch (kubeflowOperator) { - case 'tf-operator': { - switch (operatorApiVersion) { - case 'v1alpha2': { - return new TFOperatorClientV1Alpha2(); - } - case 'v1beta1': { - return new TFOperatorClientV1Beta1(); - } - case 'v1beta2': { - return new TFOperatorClientV1Beta2(); - } - default: - throw new Error(`Invalid tf-operator apiVersion ${operatorApiVersion}`); - } - } - case 'pytorch-operator': { - switch (operatorApiVersion) { - case 'v1alpha2': { - return new PyTorchOperatorClientV1Alpha2(); - } - case 'v1beta1': { - return new PyTorchOperatorClientV1Beta1(); - } - case 'v1beta2': { - return new PyTorchOperatorClientV1Beta2(); - } - default: - throw new Error(`Invalid pytorch-operator apiVersion ${operatorApiVersion}`); - } - } - default: - throw new Error(`Invalid operator ${kubeflowOperator}`); - } - } -} // tslint:disable: no-unsafe-any no-any completed-docs -class TFOperatorClientV1Alpha2 extends KubeflowOperatorClient { +class TFOperatorClientV1Alpha2 extends KubernetesCRDClient { /** * constructor, to initialize tfjob CRD definition */ @@ -112,7 +66,7 @@ class TFOperatorClientV1Beta2 extends KubernetesCRDClient { } } -class PyTorchOperatorClientV1Alpha2 extends KubeflowOperatorClient { +class PyTorchOperatorClientV1Alpha2 extends KubernetesCRDClient { /** * constructor, to initialize tfjob CRD definition */ @@ -169,5 +123,51 @@ class PyTorchOperatorClientV1Beta2 extends KubernetesCRDClient { } } +/** + * KubeflowOperator Client + */ +class KubeflowOperatorClientFactory { + /** + * Factory method to generate operator client + */ + // tslint:disable-next-line:function-name + public static createClient(kubeflowOperator: KubeflowOperator, operatorApiVersion: string): KubernetesCRDClient { + switch (kubeflowOperator) { + case 'tf-operator': { + switch (operatorApiVersion) { + case 'v1alpha2': { + return new TFOperatorClientV1Alpha2(); + } + case 'v1beta1': { + return new TFOperatorClientV1Beta1(); + } + case 'v1beta2': { + return new TFOperatorClientV1Beta2(); + } + default: + throw new Error(`Invalid tf-operator apiVersion ${operatorApiVersion}`); + } + } + case 'pytorch-operator': { + switch (operatorApiVersion) { + case 'v1alpha2': { + return new PyTorchOperatorClientV1Alpha2(); + } + case 'v1beta1': { + return new PyTorchOperatorClientV1Beta1(); + } + case 'v1beta2': { + return new PyTorchOperatorClientV1Beta2(); + } + default: + throw new Error(`Invalid pytorch-operator apiVersion ${operatorApiVersion}`); + } + } + default: + throw new Error(`Invalid operator ${kubeflowOperator}`); + } + } +} + // tslint:enable: no-unsafe-any -export { KubeflowOperatorClient, GeneralK8sClient }; +export { KubeflowOperatorClientFactory, GeneralK8sClient }; diff --git a/src/nni_manager/training_service/kubernetes/kubeflow/kubeflowTrainingService.ts b/src/nni_manager/training_service/kubernetes/kubeflow/kubeflowTrainingService.ts index c68da845f4..93b86e17a4 100644 --- a/src/nni_manager/training_service/kubernetes/kubeflow/kubeflowTrainingService.ts +++ b/src/nni_manager/training_service/kubernetes/kubeflow/kubeflowTrainingService.ts @@ -21,7 +21,7 @@ import { AzureStorageClientUtility } from '../azureStorageClientUtils'; import { NFSConfig } from '../kubernetesConfig'; import { KubernetesTrialJobDetail } from '../kubernetesData'; import { KubernetesTrainingService } from '../kubernetesTrainingService'; -import { KubeflowOperatorClient } from './kubeflowApiClient'; +import { KubeflowOperatorClientFactory } from './kubeflowApiClient'; import { KubeflowClusterConfig, KubeflowClusterConfigAzure, KubeflowClusterConfigFactory, KubeflowClusterConfigNFS, KubeflowTrialConfig, KubeflowTrialConfigFactory, KubeflowTrialConfigPytorch, KubeflowTrialConfigTensorflow } from './kubeflowConfig'; @@ -136,8 +136,8 @@ class KubeflowTrainingService extends KubernetesTrainingService implements Kuber nfsKubeflowClusterConfig.nfs.path ); } - this.kubernetesCRDClient = KubeflowOperatorClient.generateOperatorClient(this.kubeflowClusterConfig.operator, - this.kubeflowClusterConfig.apiVersion); + this.kubernetesCRDClient = KubeflowOperatorClientFactory.createClient( + this.kubeflowClusterConfig.operator, this.kubeflowClusterConfig.apiVersion); break; case TrialConfigMetadataKey.TRIAL_CONFIG: