6
6
7
7
class MLOps (object ):
8
8
spool_dir = "/tmp/ta"
9
- agent_dir = "/opt/mlops-agent/datarobot_mlops_package-8.1.2"
9
+ agent_dir = "/opt/mlops-agent"
10
+ mlops_dir_name = "datarobot_mlops_package-8.1.2"
10
11
11
12
def __init__ (self , api_token , path ):
12
13
self .token = api_token
@@ -15,27 +16,28 @@ def __init__(self, api_token, path):
15
16
mlops_config = json .load (f )
16
17
else :
17
18
raise Exception ("'mlops.json' file does not exist, but mlops was requested." )
18
- if not os .path .exists (agent_dir ):
19
+ if not os .path .exists (self . agent_dir ):
19
20
raise Exception ("environment is not configured for mlops.\n Please select a valid mlops enabled environment." )
20
- self .endpoint = mlops_config ['datarobot_api_endpoint ' ]
21
+ self .endpoint = mlops_config ['datarobot_mlops_service_url ' ]
21
22
self .model_id = mlops_config ['model_id' ]
22
23
self .deployment_id = mlops_config ['deployment_id' ]
24
+ self .mlops_name = mlops_config .get ('mlops_dir_name' , 'datarobot_mlops_package-8.1.2' )
23
25
24
26
def init (self ):
25
27
os .environ ['MLOPS_DEPLOYMENT_ID' ] = self .deployment_id
26
28
os .environ ['MLOPS_MODEL_ID' ] = self .model_id
27
29
os .environ ['MLOPS_SPOOLER_TYPE' ] = "FILESYSTEM"
28
- os .environ ['MLOPS_FILESYSTEM_DIRECTORY' ] = "/tmp/ta"
30
+ os .environ ['MLOPS_FILESYSTEM_DIRECTORY' ] = self . spool_dir
29
31
30
- with open (f'{ self .agent_dir } /conf/mlops.agent.conf.yaml' ) as f :
32
+ with open (f'{ self .agent_dir } /{ self . mlops_dir_name } / conf/mlops.agent.conf.yaml' ) as f :
31
33
documents = yaml .load (f , Loader = yaml .FullLoader )
32
34
documents ['mlopsUrl' ] = self .endpoint
33
35
documents ['apiToken' ] = self .token
34
- with open (f'{ self .agent_dir } /conf/mlops.agent.conf.yaml' , 'w' ) as f :
36
+ with open (f'{ self .agent_dir } /{ self . mlops_dir_name } / conf/mlops.agent.conf.yaml' , 'w' ) as f :
35
37
yaml .dump (documents , f )
36
38
37
- subprocess .call (f'{ self .agent_dir } /bin/start-agent.sh' )
38
- check = subprocess .Popen ([f'{ self .agent_dir } /bin/status-agent.sh' ], stdout = subprocess .PIPE )
39
+ subprocess .call (f'{ self .agent_dir } /{ self . mlops_dir_name } / bin/start-agent.sh' )
40
+ check = subprocess .Popen ([f'{ self .agent_dir } /{ self . mlops_dir_name } / bin/status-agent.sh' ], stdout = subprocess .PIPE )
39
41
output = check .stdout .readlines ()[0 ]
40
42
check .terminate ()
41
43
if b"DataRobot MLOps-Agent is running as a service." in output :
0 commit comments