Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
A
AddtoModelStore
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
CI / CD Analytics
Repository Analytics
Value Stream Analytics
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
dasharatha.vamshi
AddtoModelStore
Commits
8a0ee94d
Commit
8a0ee94d
authored
Mar 11, 2021
by
dasharatha.vamshi
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
sonarlint changes
parent
83131f6a
Changes
5
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
45 additions
and
26 deletions
+45
-26
main.py
main.py
+16
-19
scripts/common/config_parser.py
scripts/common/config_parser.py
+1
-4
scripts/common/constants.py
scripts/common/constants.py
+1
-0
temp/mnt/ilens/ai-jobs/models/metadata.json
temp/mnt/ilens/ai-jobs/models/metadata.json
+27
-3
temp/mnt/ilens/ai-jobs/pipe1/default_run_id/AddtoModelStore/input/model_9547643f_59d89573.pkl
..._run_id/AddtoModelStore/input/model_9547643f_59d89573.pkl
+0
-0
No files found.
main.py
View file @
8a0ee94d
import
traceback
import
traceback
from
scripts.common.config_parser
import
*
from
scripts.common.config_parser
import
config
from
scripts.common.constants
import
AddtoModelStoreConstants
,
ComponentExceptions
from
scripts.common.constants
import
AddtoModelStoreConstants
,
ComponentExceptions
from
scripts.common.logsetup
import
logger
from
scripts.common.logsetup
import
logger
from
sklearn.ensemble
import
RandomForestRegressor
from
sklearn.ensemble
import
RandomForestRegressor
...
@@ -9,6 +9,7 @@ import os.path
...
@@ -9,6 +9,7 @@ import os.path
from
os
import
path
from
os
import
path
from
datetime
import
date
from
datetime
import
date
import
uuid
import
uuid
import
json
class
AddtoModelStore
:
class
AddtoModelStore
:
...
@@ -24,7 +25,7 @@ class AddtoModelStore:
...
@@ -24,7 +25,7 @@ class AddtoModelStore:
self
.
artifact_archived_path
=
self
.
query
[
'artifact_archived_path'
]
self
.
artifact_archived_path
=
self
.
query
[
'artifact_archived_path'
]
self
.
new_model_path
=
os
.
path
.
join
(
self
.
component_input_dir
,
os
.
listdir
(
self
.
component_input_dir
)[
0
])
self
.
new_model_path
=
os
.
path
.
join
(
self
.
component_input_dir
,
os
.
listdir
(
self
.
component_input_dir
)[
0
])
self
.
new_model_name
=
os
.
listdir
(
self
.
component_input_dir
)[
0
]
self
.
new_model_name
=
os
.
listdir
(
self
.
component_input_dir
)[
0
]
self
.
file_rename
=
self
.
new_model_name
.
split
(
'.'
)[
0
]
+
"_"
+
str
(
uuid
.
uuid4
())
.
split
(
'-'
)[
0
]
+
"."
+
\
self
.
file_rename
=
self
.
new_model_name
.
split
(
'.'
)[
0
]
+
"_"
+
str
(
uuid
.
uuid4
())
.
split
(
'-'
)[
0
]
+
"."
+
\
self
.
new_model_name
.
split
(
'.'
)[
1
]
self
.
new_model_name
.
split
(
'.'
)[
1
]
os
.
rename
(
self
.
new_model_path
,
os
.
path
.
join
(
self
.
component_input_dir
,
self
.
file_rename
))
os
.
rename
(
self
.
new_model_path
,
os
.
path
.
join
(
self
.
component_input_dir
,
self
.
file_rename
))
self
.
new_model_path
=
os
.
path
.
join
(
self
.
component_input_dir
,
os
.
listdir
(
self
.
component_input_dir
)[
0
])
self
.
new_model_path
=
os
.
path
.
join
(
self
.
component_input_dir
,
os
.
listdir
(
self
.
component_input_dir
)[
0
])
...
@@ -67,14 +68,11 @@ class AddtoModelStore:
...
@@ -67,14 +68,11 @@ class AddtoModelStore:
logger
.
info
(
"File at "
+
source_blob_path
+
" is moved to "
+
dest_blob_path
)
logger
.
info
(
"File at "
+
source_blob_path
+
" is moved to "
+
dest_blob_path
)
if
copy_properties
.
status
!=
"success"
:
if
copy_properties
.
status
!=
"success"
:
dest_blob
.
abort_copy
(
copy_properties
.
id
)
dest_blob
.
abort_copy
(
copy_properties
.
id
)
raise
Exception
(
logger
.
info
(
"Unable to copy files from current to archived"
)
f
"Unable to copy blob
%
s with status
%
s"
%
(
source_blob_path
,
copy_properties
.
status
)
)
source_blob
.
delete_blob
()
source_blob
.
delete_blob
()
except
Exception
as
e
:
except
Exception
as
e
:
logger
.
info
(
traceback
.
format_exc
())
logger
.
info
(
traceback
.
format_exc
())
raise
Exception
(
e
)
logger
.
info
(
e
)
def
check_meta_data
(
self
):
def
check_meta_data
(
self
):
return
path
.
exists
(
self
.
query
[
'metadata_file'
])
return
path
.
exists
(
self
.
query
[
'metadata_file'
])
...
@@ -92,7 +90,7 @@ class AddtoModelStore:
...
@@ -92,7 +90,7 @@ class AddtoModelStore:
return
True
return
True
except
Exception
as
e
:
except
Exception
as
e
:
logger
.
info
(
traceback
.
format_exc
())
logger
.
info
(
traceback
.
format_exc
())
raise
Exception
(
e
)
raise
FileExistsError
(
e
)
def
update_meta_data
(
self
,
data
):
def
update_meta_data
(
self
,
data
):
try
:
try
:
...
@@ -101,13 +99,11 @@ class AddtoModelStore:
...
@@ -101,13 +99,11 @@ class AddtoModelStore:
if
i
[
'id'
]
==
self
.
ilens_tag_hierarchy
:
if
i
[
'id'
]
==
self
.
ilens_tag_hierarchy
:
i
[
'archived'
]
.
append
(
i
[
'current_model'
])
i
[
'archived'
]
.
append
(
i
[
'current_model'
])
i
[
'current_model'
]
=
self
.
update_current_model
i
[
'current_model'
]
=
self
.
update_current_model
else
:
pass
# print(data)
# print(data)
return
data
return
data
except
Exception
as
e
:
except
Exception
as
e
:
logger
.
info
(
traceback
.
format_exc
())
logger
.
info
(
traceback
.
format_exc
())
raise
Exception
(
e
)
raise
KeyError
(
e
)
def
get_file_name_from_meta_data
(
self
,
data
):
def
get_file_name_from_meta_data
(
self
,
data
):
try
:
try
:
...
@@ -117,19 +113,20 @@ class AddtoModelStore:
...
@@ -117,19 +113,20 @@ class AddtoModelStore:
return
i
[
'current_model'
][
'model_fl_name'
]
return
i
[
'current_model'
][
'model_fl_name'
]
except
Exception
as
e
:
except
Exception
as
e
:
logger
.
info
(
traceback
.
format_exc
())
logger
.
info
(
traceback
.
format_exc
())
raise
Exception
(
e
)
raise
KeyError
(
e
)
def
run
(
self
):
def
run
(
self
):
try
:
try
:
chec
K
_meta_file
=
self
.
check_meta_data
()
chec
k
_meta_file
=
self
.
check_meta_data
()
# print(chec
K
_meta_file)
# print(chec
k
_meta_file)
if
chec
K
_meta_file
:
if
chec
k
_meta_file
:
logger
.
info
(
"metadata json file is present........."
)
logger
.
info
(
"metadata json file is present........."
)
try
:
try
:
logger
.
info
(
"Reading Json file"
)
logger
.
info
(
"Reading Json file"
)
with
open
(
self
.
meta_data_file
)
as
f
:
with
open
(
self
.
meta_data_file
)
as
f
:
data
=
json
.
load
(
f
)
data
=
json
.
load
(
f
)
except
:
except
Exception
as
e
:
logger
.
info
(
e
)
logger
.
info
(
"Failed reading Json File"
)
logger
.
info
(
"Failed reading Json File"
)
logger
.
info
(
traceback
.
format_exc
())
logger
.
info
(
traceback
.
format_exc
())
old_model_name
=
self
.
get_file_name_from_meta_data
(
data
)
old_model_name
=
self
.
get_file_name_from_meta_data
(
data
)
...
@@ -149,9 +146,9 @@ class AddtoModelStore:
...
@@ -149,9 +146,9 @@ class AddtoModelStore:
else
:
else
:
logger
.
info
(
"AddToModelStore component failed..............."
)
logger
.
info
(
"AddToModelStore component failed..............."
)
return
True
return
True
except
Exception
as
e
:
except
Exception
as
e
r
:
logger
.
info
(
traceback
.
format_exc
())
logger
.
info
(
traceback
.
format_exc
())
raise
Exception
(
e
)
logger
.
info
(
er
)
if
__name__
==
'__main__'
:
if
__name__
==
'__main__'
:
...
@@ -159,6 +156,6 @@ if __name__ == '__main__':
...
@@ -159,6 +156,6 @@ if __name__ == '__main__':
obj
=
AddtoModelStore
(
config
)
obj
=
AddtoModelStore
(
config
)
obj
.
run
()
obj
.
run
()
logger
.
info
(
"Component ran successfully"
)
logger
.
info
(
"Component ran successfully"
)
except
:
except
Exception
as
e
:
logger
.
info
(
"Model Object Component Failed"
)
logger
.
info
(
"Model Object Component Failed"
)
logger
.
info
(
traceback
.
format_exc
())
logger
.
info
(
traceback
.
format_exc
())
scripts/common/config_parser.py
View file @
8a0ee94d
...
@@ -69,7 +69,7 @@ except Exception as e:
...
@@ -69,7 +69,7 @@ except Exception as e:
try
:
try
:
ilens_tag_hierarchy
=
os
.
environ
.
get
(
'ilens_tag_hierarchy'
)
ilens_tag_hierarchy
=
os
.
environ
.
get
(
'ilens_tag_hierarchy'
)
except
Exception
as
e
:
except
Exception
as
e
:
raise
Exception
(
e
)
raise
KeyError
(
e
)
BASE_LOG_PATH
=
os
.
path
.
join
(
os
.
getcwd
(),
"logs"
)
BASE_LOG_PATH
=
os
.
path
.
join
(
os
.
getcwd
(),
"logs"
)
if
not
os
.
path
.
exists
(
os
.
path
.
join
(
os
.
getcwd
(),
'logs'
)):
if
not
os
.
path
.
exists
(
os
.
path
.
join
(
os
.
getcwd
(),
'logs'
)):
...
@@ -81,9 +81,6 @@ ENABLE_LOGSTASH_LOG = os.environ.get("ENABLE_LOGSTASH_LOG", 'False').lower()
...
@@ -81,9 +81,6 @@ ENABLE_LOGSTASH_LOG = os.environ.get("ENABLE_LOGSTASH_LOG", 'False').lower()
LOGSTASH_HOST
=
_config
.
get
(
'SERVICE_CONFIG'
,
{})
.
get
(
'LOGSTASH_HOST'
)
LOGSTASH_HOST
=
_config
.
get
(
'SERVICE_CONFIG'
,
{})
.
get
(
'LOGSTASH_HOST'
)
LOGSTASH_PORT
=
str
(
_config
.
get
(
'SERVICE_CONFIG'
,
{})
.
get
(
'LOGSTASH_PORT'
))
LOGSTASH_PORT
=
str
(
_config
.
get
(
'SERVICE_CONFIG'
,
{})
.
get
(
'LOGSTASH_PORT'
))
# os.environ['azure_file_path'] = '/data/model/tested/test1.pkl'
# os.environ['local_file_path'] = r'E:\iLens-AI\azure-file-download\StandardScaler.pkl'
config
=
{
config
=
{
'pipeline_id'
:
pipeline_id
,
'pipeline_id'
:
pipeline_id
,
'run_id'
:
run_id
,
'run_id'
:
run_id
,
...
...
scripts/common/constants.py
View file @
8a0ee94d
...
@@ -14,3 +14,4 @@ class ComponentExceptions:
...
@@ -14,3 +14,4 @@ class ComponentExceptions:
INVALID_ARTIFACT_BASE_PATH_EXCEPTION
=
"Artifact base path value is missing"
INVALID_ARTIFACT_BASE_PATH_EXCEPTION
=
"Artifact base path value is missing"
INVALID_AZURE_FILE_NAME_EXCEPTION
=
"Artifact name is missing"
INVALID_AZURE_FILE_NAME_EXCEPTION
=
"Artifact name is missing"
INVALID_CONTAINER_NAME
=
"Container name is missing"
INVALID_CONTAINER_NAME
=
"Container name is missing"
FAILED_UPLOAD_TO_BLOB
=
"Failed while uploading to blob"
temp/mnt/ilens/ai-jobs/models/metadata.json
View file @
8a0ee94d
...
@@ -4,10 +4,10 @@
...
@@ -4,10 +4,10 @@
"current_model"
:
{
"current_model"
:
{
"model_name"
:
"randomforest"
,
"model_name"
:
"randomforest"
,
"model_params"
:
null
,
"model_params"
:
null
,
"training_date"
:
"2021-03-1
0
"
,
"training_date"
:
"2021-03-1
1
"
,
"framework"
:
null
,
"framework"
:
null
,
"serializedObjectType"
:
"pkl"
,
"serializedObjectType"
:
"pkl"
,
"model_fl_name"
:
"model
e_a7d835e0
.pkl"
"model_fl_name"
:
"model
_9547643f_59d89573
.pkl"
},
},
"archived"
:
[
"archived"
:
[
{
{
...
@@ -16,7 +16,31 @@
...
@@ -16,7 +16,31 @@
"training_date"
:
"2021-03-10"
,
"training_date"
:
"2021-03-10"
,
"framework"
:
null
,
"framework"
:
null
,
"serializedObjectType"
:
"pkl"
,
"serializedObjectType"
:
"pkl"
,
"model_fl_name"
:
"modele_85194781.pkl"
"model_fl_name"
:
"model_111175b9.pkl"
},
{
"model_name"
:
"randomforest"
,
"model_params"
:
null
,
"training_date"
:
"2021-03-10"
,
"framework"
:
null
,
"serializedObjectType"
:
"pkl"
,
"model_fl_name"
:
"model_3f0d66a2.pkl"
},
{
"model_name"
:
"randomforest"
,
"model_params"
:
null
,
"training_date"
:
"2021-03-10"
,
"framework"
:
null
,
"serializedObjectType"
:
"pkl"
,
"model_fl_name"
:
"model_7f17bf54.pkl"
},
{
"model_name"
:
"randomforest"
,
"model_params"
:
null
,
"training_date"
:
"2021-03-10"
,
"framework"
:
null
,
"serializedObjectType"
:
"pkl"
,
"model_fl_name"
:
"model_07080eaa.pkl"
}
}
]
]
}
}
...
...
temp/mnt/ilens/ai-jobs/pipe1/default_run_id/AddtoModelStore/input/model.pkl
→
temp/mnt/ilens/ai-jobs/pipe1/default_run_id/AddtoModelStore/input/model
_9547643f_59d89573
.pkl
View file @
8a0ee94d
File moved
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment