Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

4. Add MetadataProfile Create and List APIs #1442

Draft
wants to merge 2 commits into
base: mvp_demo
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/main/java/com/autotune/analyzer/Analyzer.java
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,8 @@ public static void addServlets(ServletContextHandler context) {
context.addServlet(MetricProfileService.class, ServerContext.CREATE_METRIC_PROFILE);
context.addServlet(MetricProfileService.class, ServerContext.LIST_METRIC_PROFILES);
context.addServlet(MetricProfileService.class, ServerContext.DELETE_METRIC_PROFILE);
context.addServlet(MetadataProfileService.class, ServerContext.CREATE_METADATA_PROFILE);
context.addServlet(MetadataProfileService.class, ServerContext.LIST_METADATA_PROFILES);
context.addServlet(ListDatasources.class, ServerContext.LIST_DATASOURCES);
context.addServlet(DSMetadataService.class, ServerContext.DATASOURCE_METADATA);
context.addServlet(BulkService.class, ServerContext.BULK_SERVICE);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
package com.autotune.analyzer.exceptions;

public class MetadataProfileResponse {
private String message;
private int httpcode;
private String documentationLink;
private String status;

public MetadataProfileResponse(String message, int httpcode, String documentationLink, String status) {
this.message = message;
this.httpcode = httpcode;
this.documentationLink = documentationLink;
this.status = status;
}

public String getMessage() {
return message;
}

public void setMessage(String message) {
this.message = message;
}

public int getHttpcode() {
return httpcode;
}

public void setHttpcode(int httpcode) {
this.httpcode = httpcode;
}

public String getDocumentationLink() {
return documentationLink;
}

public void setDocumentationLink(String documentationLink) {
this.documentationLink = documentationLink;
}

public String getStatus() {
return status;
}

public void setStatus(String status) {
this.status = status;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
package com.autotune.analyzer.metadataProfiles;

import com.autotune.database.service.ExperimentDBService;
import com.autotune.utils.KruizeConstants;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.HashMap;
import java.util.Map;

public class MetadataProfileCollection {
private static final Logger LOGGER = LoggerFactory.getLogger(MetadataProfileCollection.class);
private static MetadataProfileCollection metadataProfileCollectionInstance = new MetadataProfileCollection();
private HashMap<String, MetadataProfile> metadataProfileCollection;

private MetadataProfileCollection() {
this.metadataProfileCollection = new HashMap<>();
}

public static MetadataProfileCollection getInstance() {
return metadataProfileCollectionInstance;
}

public HashMap<String, MetadataProfile> getMetadataProfileCollection() {
return metadataProfileCollection;
}

public void loadMetadataProfilesFromDB() {
try {
LOGGER.info(KruizeConstants.MetadataProfileConstants.CHECKING_AVAILABLE_METADATA_PROFILE_FROM_DB);
Map<String, MetadataProfile> availableMetadataProfiles = new HashMap<>();
new ExperimentDBService().loadAllMetadataProfiles(availableMetadataProfiles);
if (availableMetadataProfiles.isEmpty()) {
LOGGER.info(KruizeConstants.MetadataProfileConstants.NO_METADATA_PROFILE_FOUND_IN_DB);
}else {
for (Map.Entry<String, MetadataProfile> metadataProfile : availableMetadataProfiles.entrySet()) {
LOGGER.info(KruizeConstants.MetadataProfileConstants.METADATA_PROFILE_FOUND, metadataProfile.getKey());
metadataProfileCollection.put(metadataProfile.getKey(), metadataProfile.getValue());
}
}

} catch (Exception e) {
LOGGER.error(e.getMessage());
}
}


public void addMetadataProfile(MetadataProfile metadataProfile) {
String metadataProfileName = metadataProfile.getMetadata().get("name").asText();

LOGGER.info(KruizeConstants.MetadataProfileConstants.ADDING_METADATA_PROFILE + "{}", metadataProfileName);

if(metadataProfileCollection.containsKey(metadataProfileName)) {
LOGGER.error(KruizeConstants.MetadataProfileConstants.METADATA_PROFILE_ALREADY_EXISTS + "{}", metadataProfileName);
} else {
LOGGER.info(KruizeConstants.MetadataProfileConstants.METADATA_PROFILE_ADDED + "{}", metadataProfileName);
metadataProfileCollection.put(metadataProfileName, metadataProfile);
}
}
}
44 changes: 44 additions & 0 deletions src/main/java/com/autotune/analyzer/serviceObjects/Converters.java
Original file line number Diff line number Diff line change
Expand Up @@ -388,6 +388,50 @@ public static PerformanceProfile convertInputJSONToCreateMetricProfile(String in
return metricProfile;
}

public static MetadataProfile convertInputJSONToCreateMetadataProfile(String inputData) throws InvalidValueException, Exception {
MetadataProfile metadataProfile = null;
if (inputData != null) {
JSONObject jsonObject = new JSONObject(inputData);
String apiVersion = jsonObject.getString(AnalyzerConstants.API_VERSION);
String kind = jsonObject.getString(AnalyzerConstants.KIND);

JSONObject metadataObject = jsonObject.getJSONObject(AnalyzerConstants.AutotuneObjectConstants.METADATA);
ObjectMapper objectMapper = new ObjectMapper();
ObjectNode metadata = objectMapper.readValue(metadataObject.toString(), ObjectNode.class);
metadata.put("name", metadataObject.getString("name"));

Double profileVersion = jsonObject.has(AnalyzerConstants.PROFILE_VERSION) ? jsonObject.getDouble(AnalyzerConstants.PROFILE_VERSION) : null;
String k8sType = jsonObject.has(AnalyzerConstants.MetadataProfileConstants.K8S_TYPE) ? jsonObject.getString(AnalyzerConstants.MetadataProfileConstants.K8S_TYPE) : null;
JSONArray queryVariableArray = jsonObject.getJSONArray(AnalyzerConstants.AutotuneObjectConstants.QUERY_VARIABLES);
ArrayList<Metric> queryVariablesList = new ArrayList<>();
for (Object object : queryVariableArray) {
JSONObject functionVarObj = (JSONObject) object;
String name = functionVarObj.getString(AnalyzerConstants.AutotuneObjectConstants.NAME);
String datasource = functionVarObj.getString(AnalyzerConstants.AutotuneObjectConstants.DATASOURCE);
String query = functionVarObj.has(AnalyzerConstants.AutotuneObjectConstants.QUERY) ? functionVarObj.getString(AnalyzerConstants.AutotuneObjectConstants.QUERY) : null;
String valueType = functionVarObj.getString(AnalyzerConstants.AutotuneObjectConstants.VALUE_TYPE);
String kubeObject = functionVarObj.has(AnalyzerConstants.KUBERNETES_OBJECT) ? functionVarObj.getString(AnalyzerConstants.KUBERNETES_OBJECT) : null;
Metric metric = new Metric(name, query, datasource, valueType, kubeObject);
JSONArray aggrFunctionArray = functionVarObj.has(AnalyzerConstants.AGGREGATION_FUNCTIONS) ? functionVarObj.getJSONArray(AnalyzerConstants.AGGREGATION_FUNCTIONS) : null;
HashMap<String, AggregationFunctions> aggregationFunctionsMap = new HashMap<>();
for (Object innerObject : aggrFunctionArray) {
JSONObject aggrFuncJsonObject = (JSONObject) innerObject;
String function = aggrFuncJsonObject.getString(AnalyzerConstants.FUNCTION);
String aggrFuncQuery = aggrFuncJsonObject.getString(KruizeConstants.JSONKeys.QUERY);
String version = aggrFuncJsonObject.has(KruizeConstants.JSONKeys.VERSION) ? aggrFuncJsonObject.getString(KruizeConstants.JSONKeys.VERSION) : null;
AggregationFunctions aggregationFunctions = new AggregationFunctions(function, aggrFuncQuery, version);
aggregationFunctionsMap.put(function, aggregationFunctions);
}
metric.setAggregationFunctionsMap(aggregationFunctionsMap);
queryVariablesList.add(metric);
}

metadataProfile = new MetadataProfile(apiVersion, kind, metadata, profileVersion, k8sType, queryVariablesList);
}
return metadataProfile;
}


public static ConcurrentHashMap<String, KruizeObject> ConvertUpdateResultDataToAPIResponse(ConcurrentHashMap<String, KruizeObject> mainKruizeExperimentMap) {
return null;
}
Expand Down
Loading
Loading