|
8 | 8 |
|
9 | 9 | import re
|
10 | 10 |
|
11 |
| -from .service import Service |
12 | 11 | from .model_repository import ModelRepository
|
| 12 | +from .service import Service |
13 | 13 |
|
14 | 14 |
|
15 | 15 | class ModelPublish(Service):
|
@@ -59,9 +59,13 @@ def list_models(cls):
|
59 | 59 | 'destination')
|
60 | 60 |
|
61 | 61 | @classmethod
|
62 |
| - def publish_model(cls, model, destination, name=None, code=None, |
| 62 | + def publish_model(cls, |
| 63 | + model, |
| 64 | + destination, |
| 65 | + name=None, |
| 66 | + code=None, |
63 | 67 | notes=None):
|
64 |
| - """ |
| 68 | + """Publish a model to an existing publishing destination. |
65 | 69 |
|
66 | 70 | Parameters
|
67 | 71 | ----------
|
@@ -118,3 +122,150 @@ def publish_model(cls, model, destination, name=None, code=None,
|
118 | 122 | return cls.post('/models', json=request, headers={
|
119 | 123 | 'Content-Type':
|
120 | 124 | 'application/vnd.sas.models.publishing.request+json'})
|
| 125 | + |
| 126 | + @classmethod |
| 127 | + def create_cas_destination(cls, name, |
| 128 | + library, |
| 129 | + table, |
| 130 | + server=None, |
| 131 | + description=None): |
| 132 | + """Define a new CAS publishing destination. |
| 133 | +
|
| 134 | + Parameters |
| 135 | + ---------- |
| 136 | + name : str |
| 137 | + Name of the publishing destination. |
| 138 | + library : str |
| 139 | + The CAS library in which `table` will be stored. |
| 140 | + table : str |
| 141 | + Name of the CAS table in which models will be stored. |
| 142 | + server : str, optional |
| 143 | + Name of the CAS server. Defaults to 'cas-shared-default'. |
| 144 | + description : str, optional |
| 145 | + Description of the publishing destination. |
| 146 | +
|
| 147 | + Returns |
| 148 | + ------- |
| 149 | + RestObj |
| 150 | +
|
| 151 | + """ |
| 152 | + server = server or 'cas-shared-default' |
| 153 | + |
| 154 | + return cls.create_destination(name, cas_server=server, |
| 155 | + cas_library=library, cas_table=table, |
| 156 | + type_='cas', description=description) |
| 157 | + |
| 158 | + @classmethod |
| 159 | + def create_mas_destination(cls, name, uri, description=None): |
| 160 | + """Define a new Micro Analytic Server (MAS) publishing destination. |
| 161 | +
|
| 162 | + Parameters |
| 163 | + ---------- |
| 164 | + name : str |
| 165 | + Name of the publishing destination. |
| 166 | + uri : str |
| 167 | + The base URI that contains the host, the protocol, and optionally |
| 168 | + the port, which addresses the remote SAS Micro Analytic Service to |
| 169 | + use. Example: http://spam.com |
| 170 | + description : str, optional |
| 171 | + Description of the publishing destination. |
| 172 | +
|
| 173 | + Returns |
| 174 | + ------- |
| 175 | + RestObj |
| 176 | +
|
| 177 | + """ |
| 178 | + return cls.create_destination(name, mas_uri=uri, type_='mas', |
| 179 | + description=description) |
| 180 | + |
| 181 | + @classmethod |
| 182 | + def create_destination(cls, |
| 183 | + name, |
| 184 | + type_, |
| 185 | + cas_server=None, |
| 186 | + cas_library=None, |
| 187 | + cas_table=None, |
| 188 | + description=None, |
| 189 | + mas_uri=None, |
| 190 | + hdfs_dir=None, |
| 191 | + conf_dir=None, |
| 192 | + user=None, |
| 193 | + database_library=None): |
| 194 | + """Define a new publishing destination. |
| 195 | +
|
| 196 | + Parameters |
| 197 | + ---------- |
| 198 | + name : str |
| 199 | + Name of the publishing destination. |
| 200 | + type_ : {'cas', 'mas', 'hadoop', 'teradata'} |
| 201 | + Type of publishing definition being created |
| 202 | + cas_server : str, optional |
| 203 | + Name of the CAS server. Defaults to 'cas-shared-default'. |
| 204 | + Required if `type_` is 'cas', otherwise ignored. |
| 205 | + cas_library : str, optional |
| 206 | + The CAS library in which `cas_table` will be stored. Required if |
| 207 | + `type_` is 'cas', otherwise ignored. |
| 208 | + cas_table : str, optional |
| 209 | + Name of the CAS table in which models will be stored. Required |
| 210 | + if `type_` is 'cas', otherwise ignored. |
| 211 | + description : str, optional |
| 212 | + Description of the publishing destination. |
| 213 | + mas_uri : str, optional |
| 214 | + Required if `type_` is 'mas', otherwise ignored. |
| 215 | + hdfs_dir : str, optional |
| 216 | + Required if `type_` is 'hadoop', otherwise ignored. |
| 217 | + conf_dir : str, optional |
| 218 | + Required if `type_` is 'hadoop', otherwise ignored. |
| 219 | + user : str, optional |
| 220 | + Required if `type_` is 'hadoop', otherwise ignored. |
| 221 | + database_library : str, optional |
| 222 | + Required if `type_` is 'teradata', otherwise ignored. |
| 223 | +
|
| 224 | + Returns |
| 225 | + ------- |
| 226 | + RestObj |
| 227 | +
|
| 228 | + """ |
| 229 | + type_ = str(type_).lower() |
| 230 | + assert type_ in ('cas', 'microanalyticservice', 'mas', |
| 231 | + 'teradata', 'hadoop') |
| 232 | + |
| 233 | + # As of Viya 3.4 capitalization matters. |
| 234 | + if type_ in ('microanalyticservice', 'mas'): |
| 235 | + type_ = 'microAnalyticService' |
| 236 | + |
| 237 | + request = {'name': str(name), |
| 238 | + 'destinationType': type_, |
| 239 | + 'casServerName': cas_server, |
| 240 | + 'casLibrary': cas_library, |
| 241 | + 'description': description, |
| 242 | + 'destinationTable': cas_table, |
| 243 | + 'databaseCasLibrary': database_library, |
| 244 | + 'user': user, |
| 245 | + 'hdfsDirectory': hdfs_dir, |
| 246 | + 'configurationDirectory': conf_dir, |
| 247 | + 'masUri': mas_uri |
| 248 | + } |
| 249 | + |
| 250 | + drop_list = { |
| 251 | + 'cas': |
| 252 | + ('databaseCasLibrary', 'user', 'hdfsDirectory', 'masUri', |
| 253 | + 'configurationDirectory'), |
| 254 | + 'microAnalyticService': |
| 255 | + ('casServerName', 'casLibrary', 'destinationTable', 'user', |
| 256 | + 'databaseCasLibrary', 'hdfsDirectory', |
| 257 | + 'configurationDirectory'), |
| 258 | + 'hadoop': |
| 259 | + ('casServerName', 'casLibrary', 'destinationTable', |
| 260 | + 'databaseCasLibrary', 'masUri'), |
| 261 | + 'teradata': |
| 262 | + ('casServerName', 'casLibrary', 'destinationTable', 'user', |
| 263 | + 'hdfsDirectory', 'masUri', 'configurationDirectory') |
| 264 | + } |
| 265 | + |
| 266 | + for k in drop_list[request['destinationType']]: |
| 267 | + request.pop(k, None) |
| 268 | + |
| 269 | + return cls.post('/destinations', json=request, headers={ |
| 270 | + 'Content-Type': |
| 271 | + 'application/vnd.sas.models.publishing.destination+json'}) |
0 commit comments