You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ambari.apache.org by vs...@apache.org on 2017/06/23 07:02:42 UTC
[33/35] ambari git commit: AMBARI-21330.Remove slider view from
Ambari-3.0.0(Venkata Sairam)
http://git-wip-us.apache.org/repos/asf/ambari/blob/ec8deeba/contrib/views/slider/src/main/java/org/apache/ambari/view/slider/clients/AmbariServiceInfo.java
----------------------------------------------------------------------
diff --git a/contrib/views/slider/src/main/java/org/apache/ambari/view/slider/clients/AmbariServiceInfo.java b/contrib/views/slider/src/main/java/org/apache/ambari/view/slider/clients/AmbariServiceInfo.java
deleted file mode 100644
index 9d2fb31..0000000
--- a/contrib/views/slider/src/main/java/org/apache/ambari/view/slider/clients/AmbariServiceInfo.java
+++ /dev/null
@@ -1,51 +0,0 @@
-/**
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.ambari.view.slider.clients;
-
-public class AmbariServiceInfo {
-
- private String id;
- private boolean started;
- private boolean maintenanceMode;
-
- public String getId() {
- return id;
- }
-
- public void setId(String id) {
- this.id = id;
- }
-
- public boolean isStarted() {
- return started;
- }
-
- public void setStarted(boolean started) {
- this.started = started;
- }
-
- public boolean isMaintenanceMode() {
- return maintenanceMode;
- }
-
- public void setMaintenanceMode(boolean maintenanceMode) {
- this.maintenanceMode = maintenanceMode;
- }
-
-}
http://git-wip-us.apache.org/repos/asf/ambari/blob/ec8deeba/contrib/views/slider/src/main/java/org/apache/ambari/view/slider/rest/SliderAppTypesResource.java
----------------------------------------------------------------------
diff --git a/contrib/views/slider/src/main/java/org/apache/ambari/view/slider/rest/SliderAppTypesResource.java b/contrib/views/slider/src/main/java/org/apache/ambari/view/slider/rest/SliderAppTypesResource.java
deleted file mode 100644
index fa2a71c..0000000
--- a/contrib/views/slider/src/main/java/org/apache/ambari/view/slider/rest/SliderAppTypesResource.java
+++ /dev/null
@@ -1,54 +0,0 @@
-/**
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.ambari.view.slider.rest;
-
-import javax.ws.rs.GET;
-import javax.ws.rs.Path;
-import javax.ws.rs.PathParam;
-import javax.ws.rs.Produces;
-import javax.ws.rs.core.Context;
-import javax.ws.rs.core.HttpHeaders;
-import javax.ws.rs.core.MediaType;
-import javax.ws.rs.core.Response;
-import javax.ws.rs.core.UriInfo;
-
-import org.apache.ambari.view.ViewResourceHandler;
-
-import com.google.inject.Inject;
-
-public class SliderAppTypesResource {
-
- @Inject
- ViewResourceHandler resourceHandler;
-
- @GET
- @Produces({ MediaType.TEXT_PLAIN, MediaType.APPLICATION_JSON })
- public Response getApps(@Context HttpHeaders headers, @Context UriInfo uri) {
- return resourceHandler.handleRequest(headers, uri, null);
- }
-
- @GET
- @Path("{appTypeId}")
- @Produces({ MediaType.TEXT_PLAIN, MediaType.APPLICATION_JSON })
- public Response getApp(@Context HttpHeaders headers, @Context UriInfo uri,
- @PathParam("appTypeId") String appTypeId) {
- return resourceHandler.handleRequest(headers, uri, appTypeId);
- }
-
-}
http://git-wip-us.apache.org/repos/asf/ambari/blob/ec8deeba/contrib/views/slider/src/main/java/org/apache/ambari/view/slider/rest/SliderAppsResource.java
----------------------------------------------------------------------
diff --git a/contrib/views/slider/src/main/java/org/apache/ambari/view/slider/rest/SliderAppsResource.java b/contrib/views/slider/src/main/java/org/apache/ambari/view/slider/rest/SliderAppsResource.java
deleted file mode 100644
index 94d37d3..0000000
--- a/contrib/views/slider/src/main/java/org/apache/ambari/view/slider/rest/SliderAppsResource.java
+++ /dev/null
@@ -1,163 +0,0 @@
-/**
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.ambari.view.slider.rest;
-
-import java.io.IOException;
-import java.net.URI;
-import java.net.URISyntaxException;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-import java.util.Map.Entry;
-
-import javax.ws.rs.Consumes;
-import javax.ws.rs.DELETE;
-import javax.ws.rs.GET;
-import javax.ws.rs.POST;
-import javax.ws.rs.PUT;
-import javax.ws.rs.Path;
-import javax.ws.rs.PathParam;
-import javax.ws.rs.Produces;
-import javax.ws.rs.core.Context;
-import javax.ws.rs.core.HttpHeaders;
-import javax.ws.rs.core.MediaType;
-import javax.ws.rs.core.MultivaluedMap;
-import javax.ws.rs.core.Response;
-import javax.ws.rs.core.Response.Status;
-import javax.ws.rs.core.UriInfo;
-
-import org.apache.ambari.view.ViewResourceHandler;
-import org.apache.ambari.view.slider.SliderAppsViewController;
-import org.apache.hadoop.yarn.exceptions.YarnException;
-
-import com.google.gson.JsonElement;
-import com.google.gson.JsonObject;
-import com.google.gson.JsonParser;
-import com.google.inject.Inject;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-public class SliderAppsResource {
-
- private static final Logger logger = LoggerFactory
- .getLogger(SliderAppsResource.class);
- @Inject
- ViewResourceHandler resourceHandler;
- @Inject
- SliderAppsViewController sliderAppsViewController;
-
- @GET
- @Produces({ MediaType.TEXT_PLAIN, MediaType.APPLICATION_JSON })
- public Response getApps(@Context HttpHeaders headers, @Context UriInfo uri) {
- MultivaluedMap<String, String> queryParameters = uri.getQueryParameters();
- if (queryParameters != null && queryParameters.containsKey("validateAppName")) {
- List<String> appNames = queryParameters.get("validateAppName");
- if (appNames.size() > 0) {
- try {
- if (sliderAppsViewController.appExists(appNames.get(0))) {
- return Response.status(Status.CONFLICT).build();
- }
- } catch (IOException e) {
- logger.warn("Unable to validate cluster name", e);
- } catch (InterruptedException e) {
- logger.warn("Unable to validate cluster name", e);
- } catch (YarnException e) {
- logger.warn("Unable to validate cluster name", e);
- }
- return Response.ok().build();
- }
- }
- return resourceHandler.handleRequest(headers, uri, null);
- }
-
- @GET
- @Path("{appId}")
- @Produces({ MediaType.TEXT_PLAIN, MediaType.APPLICATION_JSON })
- public Response getApp(@Context HttpHeaders headers, @Context UriInfo uri,
- @PathParam("appId") String appId) {
- return resourceHandler.handleRequest(headers, uri, appId);
- }
-
- @DELETE
- @Path("{appId}")
- public void deleteApp(@Context HttpHeaders headers, @Context UriInfo uri,
- @PathParam("appId") String appId) throws YarnException, IOException, InterruptedException {
- sliderAppsViewController.deleteSliderApp(appId);
- }
-
- @PUT
- @Path("{appId}")
- @Consumes({ MediaType.TEXT_PLAIN, MediaType.APPLICATION_JSON })
- public Response updateApp(@Context UriInfo uri, String jsonString,
- @PathParam("appId") String appId) throws IOException, YarnException,
- InterruptedException, URISyntaxException {
- if (jsonString != null) {
- JsonElement requestContent = new JsonParser().parse(jsonString);
- if (requestContent != null && appId != null) {
- JsonObject requestJson = requestContent.getAsJsonObject();
- if (requestJson.has("state")) {
- String newState = requestJson.get("state").getAsString();
- if ("FROZEN".equals(newState)) {
- sliderAppsViewController.freezeApp(appId);
- return Response.ok().build();
- } else if ("RUNNING".equals(newState)) {
- sliderAppsViewController.thawApp(appId);
- return Response.ok().build();
- }
- } else if (requestJson.has("components")) {
- Map<String, Integer> componentsMap = new HashMap<String, Integer>();
- JsonObject componentsJson = requestJson.get("components")
- .getAsJsonObject();
- for (Entry<String, JsonElement> e : componentsJson.entrySet()) {
- String componentName = e.getKey();
- int instanceCount = e.getValue().getAsJsonObject()
- .get("instanceCount").getAsInt();
- componentsMap.put(componentName, instanceCount);
- }
- sliderAppsViewController.flexApp(appId, componentsMap);
- return Response.ok().build();
- }
- }
- String sliderApp = sliderAppsViewController
- .createSliderApp(requestContent.getAsJsonObject());
- if (sliderApp != null)
- return Response.created(new URI(uri.getAbsolutePath() + sliderApp))
- .build();
- }
- logger.warn("No request content sent to create app");
- return Response.status(Response.Status.BAD_REQUEST).build();
- }
-
- @POST
- @Consumes({ MediaType.TEXT_PLAIN, MediaType.APPLICATION_JSON })
- public Response createApp(@Context UriInfo uri, String jsonString)
- throws IOException, YarnException, InterruptedException,
- URISyntaxException {
- if (jsonString != null) {
- JsonElement requestContent = new JsonParser().parse(jsonString);
- String sliderApp = sliderAppsViewController
- .createSliderApp(requestContent.getAsJsonObject());
- if (sliderApp != null)
- return Response.created(new URI(uri.getAbsolutePath() + sliderApp))
- .build();
- }
- logger.warn("No request content sent to create app");
- return Response.status(Response.Status.BAD_REQUEST).build();
- }
-}
http://git-wip-us.apache.org/repos/asf/ambari/blob/ec8deeba/contrib/views/slider/src/main/java/org/apache/ambari/view/slider/rest/ViewStatusResource.java
----------------------------------------------------------------------
diff --git a/contrib/views/slider/src/main/java/org/apache/ambari/view/slider/rest/ViewStatusResource.java b/contrib/views/slider/src/main/java/org/apache/ambari/view/slider/rest/ViewStatusResource.java
deleted file mode 100644
index 5023d90..0000000
--- a/contrib/views/slider/src/main/java/org/apache/ambari/view/slider/rest/ViewStatusResource.java
+++ /dev/null
@@ -1,40 +0,0 @@
-/**
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.ambari.view.slider.rest;
-
-import javax.ws.rs.GET;
-import javax.ws.rs.Produces;
-import javax.ws.rs.core.MediaType;
-
-import org.apache.ambari.view.slider.SliderAppsViewController;
-import org.apache.ambari.view.slider.ViewStatus;
-
-import com.google.inject.Inject;
-
-public class ViewStatusResource {
-
- @Inject
- SliderAppsViewController sliderController;
-
- @GET
- @Produces({ MediaType.APPLICATION_JSON })
- public ViewStatus getViewStatus() {
- return sliderController.getViewStatus();
- }
-}
http://git-wip-us.apache.org/repos/asf/ambari/blob/ec8deeba/contrib/views/slider/src/main/java/org/apache/ambari/view/slider/rest/client/AmbariHttpClient.java
----------------------------------------------------------------------
diff --git a/contrib/views/slider/src/main/java/org/apache/ambari/view/slider/rest/client/AmbariHttpClient.java b/contrib/views/slider/src/main/java/org/apache/ambari/view/slider/rest/client/AmbariHttpClient.java
deleted file mode 100644
index 74578c9..0000000
--- a/contrib/views/slider/src/main/java/org/apache/ambari/view/slider/rest/client/AmbariHttpClient.java
+++ /dev/null
@@ -1,233 +0,0 @@
-/**
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.ambari.view.slider.rest.client;
-
-import java.io.IOException;
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-import java.util.Map.Entry;
-
-import org.apache.ambari.view.ViewContext;
-import org.apache.ambari.view.slider.clients.AmbariClient;
-import org.apache.ambari.view.slider.clients.AmbariCluster;
-import org.apache.ambari.view.slider.clients.AmbariClusterInfo;
-import org.apache.ambari.view.slider.clients.AmbariHostComponent;
-import org.apache.ambari.view.slider.clients.AmbariHostInfo;
-import org.apache.ambari.view.slider.clients.AmbariService;
-import org.apache.ambari.view.slider.clients.AmbariServiceInfo;
-
-import com.google.gson.JsonArray;
-import com.google.gson.JsonElement;
-import com.google.gson.JsonObject;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-public class AmbariHttpClient extends BaseHttpClient implements AmbariClient {
-
- private static final Logger logger = LoggerFactory.getLogger(AmbariHttpClient.class);
-
- public AmbariHttpClient(String url, String userId, String password,
- ViewContext viewContext) {
- super(url, userId, password, viewContext);
- }
-
- /**
- * Provides the first cluster defined on this Ambari server.
- *
- * @return
- */
- public AmbariClusterInfo getClusterInfo() {
- try {
- JsonElement jsonElement = doGetJson("/api/v1/clusters");
- if(jsonElement==null) {
- return null;
- }
- JsonObject jsonObject = jsonElement.getAsJsonObject();
- JsonArray clustersArray = jsonObject.get("items").getAsJsonArray();
- if (clustersArray.size() > 0) {
- AmbariClusterInfo cluster = new AmbariClusterInfo();
- JsonObject clusterObj = clustersArray.get(0).getAsJsonObject()
- .get("Clusters").getAsJsonObject();
- cluster.setName(clusterObj.get("cluster_name").getAsString());
- cluster.setVersion(clusterObj.get("version").getAsString());
- return cluster;
- }
- } catch (IOException e) {
- logger.warn("Unable to determine Ambari clusters", e);
- throw new RuntimeException(e.getMessage(), e);
- }
- return null;
- }
-
- /**
- * Provides the first cluster defined on this Ambari server.
- *
- * @return
- */
- public Map<String, String> getAmbariServerConfigs() {
- Map<String, String> configs = new HashMap<String, String>();
- try {
- JsonElement jsonElement = doGetJson("/api/v1/services/AMBARI/components/AMBARI_SERVER");
- if (jsonElement != null && jsonElement.getAsJsonObject().has("RootServiceComponents")
- && jsonElement.getAsJsonObject().get("RootServiceComponents").getAsJsonObject().has("properties")) {
- JsonObject ambariProperties = jsonElement.getAsJsonObject().get("RootServiceComponents").getAsJsonObject().get("properties").getAsJsonObject();
- for (Entry<String, JsonElement> entry : ambariProperties.entrySet()) {
- if (entry.getValue().isJsonPrimitive()) {
- configs.put(entry.getKey(), entry.getValue().getAsString());
- }
- }
- }
- } catch (IOException e) {
- logger.warn("Unable to determine Ambari clusters", e);
- }
- return configs;
- }
-
- public AmbariCluster getCluster(AmbariClusterInfo clusterInfo) {
- if (clusterInfo != null) {
- try {
- JsonElement jsonElement = doGetJson("/api/v1/clusters/"
- + clusterInfo.getName() + "?fields=services/ServiceInfo,hosts,Clusters");
- if (jsonElement != null) {
- AmbariCluster cluster = new AmbariCluster();
- // desired configs
- Map<String, String> desiredConfigs = new HashMap<String, String>();
- JsonObject jsonObject = jsonElement.getAsJsonObject();
- JsonObject clustersJsonObject = jsonObject.get("Clusters").getAsJsonObject();
- JsonObject desiredConfigsObj = clustersJsonObject.get("desired_configs")
- .getAsJsonObject();
- for (Map.Entry<String, JsonElement> entry : desiredConfigsObj
- .entrySet()) {
- desiredConfigs.put(entry.getKey(), entry.getValue()
- .getAsJsonObject().get("tag").getAsString());
- }
- cluster.setDesiredConfigs(desiredConfigs);
- cluster.setName(clustersJsonObject.get("cluster_name").getAsString());
- cluster.setVersion(clustersJsonObject.get("version").getAsString());
- // services
- List<AmbariServiceInfo> services = new ArrayList<AmbariServiceInfo>();
- for (JsonElement svcJson : jsonObject.get("services")
- .getAsJsonArray()) {
- AmbariServiceInfo si = new AmbariServiceInfo();
- si.setId(svcJson.getAsJsonObject().get("ServiceInfo")
- .getAsJsonObject().get("service_name").getAsString());
- si.setStarted("STARTED".equals(svcJson.getAsJsonObject()
- .get("ServiceInfo").getAsJsonObject().get("state")
- .getAsString()));
- services.add(si);
- }
- cluster.setServices(services);
- // hosts
- List<AmbariHostInfo> hosts = new ArrayList<AmbariHostInfo>();
- for (JsonElement hostJson : jsonObject.get("hosts")
- .getAsJsonArray()) {
- AmbariHostInfo hi = new AmbariHostInfo();
- hi.setHostName(hostJson.getAsJsonObject().get("Hosts")
- .getAsJsonObject().get("host_name").getAsString());
- hosts.add(hi);
- }
- cluster.setHosts(hosts);
- return cluster;
- }
- } catch (IllegalStateException e) {
- logger.warn("Unable to determine Ambari cluster details - "
- + clusterInfo.getName(), e);
- throw new RuntimeException(e.getMessage(), e);
- } catch (IOException e) {
- logger.warn("Unable to determine Ambari cluster details - "
- + clusterInfo.getName(), e);
- throw new RuntimeException(e.getMessage(), e);
- }
- }
- return null;
- }
-
- public Map<String, String> getConfiguration(AmbariClusterInfo cluster,
- String configType, String configTag) {
- if (cluster != null && configType != null && configTag != null) {
- try {
- JsonElement jsonElement = doGetJson("/api/v1/clusters/"
- + cluster.getName() + "/configurations?type=" + configType
- + "&tag=" + configTag);
- if (jsonElement!=null) {
- JsonObject jsonObject = jsonElement.getAsJsonObject();
- JsonArray configsArray = jsonObject.get("items").getAsJsonArray();
- if (configsArray.size() > 0) {
- JsonObject propertiesObj = configsArray.get(0).getAsJsonObject()
- .get("properties").getAsJsonObject();
- Map<String, String> properties = new HashMap<String, String>();
- for (Map.Entry<String, JsonElement> entry : propertiesObj.entrySet()) {
- if (entry.getValue().isJsonPrimitive()) {
- properties.put(entry.getKey(), entry.getValue().getAsString());
- }
- }
- return properties;
- }
- }
- } catch (IOException e) {
- logger.warn("Unable to determine Ambari clusters", e);
- throw new RuntimeException(e.getMessage(), e);
- }
- }
- return null;
- }
-
- @Override
- public AmbariService getService(AmbariClusterInfo cluster, String serviceId) {
- if (cluster != null && serviceId != null) {
- try {
- JsonElement jsonElement = doGetJson("/api/v1/clusters/"
- + cluster.getName() + "/services/" + serviceId + "?fields=ServiceInfo,components/host_components/HostRoles");
- if (jsonElement == null) {
- return null;
- }
- JsonObject jsonObject = jsonElement.getAsJsonObject();
- AmbariService svc = new AmbariService();
- JsonObject serviceInfoJsonObject = jsonObject.get("ServiceInfo").getAsJsonObject();
- svc.setId(serviceInfoJsonObject.get("service_name").getAsString());
- svc.setStarted("STARTED".equals(serviceInfoJsonObject.get("state").getAsString()));
- svc.setMaintenanceMode(!"OFF".equals(serviceInfoJsonObject.get("maintenance_state").getAsString()));
- Map<String, List<AmbariHostComponent>> componentsToHostComponentsMap = new HashMap<String, List<AmbariHostComponent>>();
- for(JsonElement ce: jsonObject.get("components").getAsJsonArray()){
- String componentName = ce.getAsJsonObject().get("ServiceComponentInfo").getAsJsonObject().get("component_name").getAsString();
- List<AmbariHostComponent> hcList = new ArrayList<AmbariHostComponent>();
- componentsToHostComponentsMap.put(componentName, hcList);
- JsonArray hcJsonArray = ce.getAsJsonObject().get("host_components").getAsJsonArray();
- for(JsonElement hce: hcJsonArray) {
- AmbariHostComponent hc = new AmbariHostComponent();
- JsonObject hcJsonObject = hce.getAsJsonObject().get("HostRoles").getAsJsonObject();
- hc.setHostName(hcJsonObject.get("host_name").getAsString());
- hc.setStarted("STARTED".equals(hcJsonObject.get("state").getAsString()));
- hc.setName(hcJsonObject.get("component_name").getAsString());
- hcList.add(hc);
- }
- }
- svc.setComponentsToHostComponentsMap(componentsToHostComponentsMap);
- return svc;
- } catch (IOException e) {
- logger.warn("Unable to determine Ambari clusters", e);
- throw new RuntimeException(e.getMessage(), e);
- }
- }
- return null;
-}
-
-}
http://git-wip-us.apache.org/repos/asf/ambari/blob/ec8deeba/contrib/views/slider/src/main/java/org/apache/ambari/view/slider/rest/client/BaseHttpClient.java
----------------------------------------------------------------------
diff --git a/contrib/views/slider/src/main/java/org/apache/ambari/view/slider/rest/client/BaseHttpClient.java b/contrib/views/slider/src/main/java/org/apache/ambari/view/slider/rest/client/BaseHttpClient.java
deleted file mode 100644
index bfc4d3a..0000000
--- a/contrib/views/slider/src/main/java/org/apache/ambari/view/slider/rest/client/BaseHttpClient.java
+++ /dev/null
@@ -1,157 +0,0 @@
-/**
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.ambari.view.slider.rest.client;
-
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.InputStreamReader;
-import java.util.HashMap;
-import java.util.Map;
-
-import org.apache.ambari.view.URLStreamProvider;
-import org.apache.ambari.view.ViewContext;
-import org.apache.ambari.view.utils.ambari.AmbariApi;
-import org.apache.commons.io.IOUtils;
-
-import com.google.gson.JsonElement;
-import com.google.gson.JsonParser;
-import com.google.gson.stream.JsonReader;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-public class BaseHttpClient {
- private static final Logger logger = LoggerFactory.getLogger(BaseHttpClient.class);
-
- private String url;
- private boolean needsAuthentication;
- private String userId;
- private String password;
- protected ViewContext viewContext;
- protected AmbariApi ambariApi;
-
- public BaseHttpClient(String url, ViewContext viewContext) {
- setUrl(url);
- setNeedsAuthentication(false);
- setViewContext(viewContext);
- if (viewContext != null) {
- ambariApi = new AmbariApi(viewContext);
- }
- }
-
- public BaseHttpClient(String url, String userId, String password,
- ViewContext viewContext) {
- setUrl(url);
- setNeedsAuthentication(true);
- setUserId(userId);
- setPassword(password);
- setViewContext(viewContext);
- if (viewContext != null) {
- ambariApi = new AmbariApi(viewContext);
- }
- }
-
- public void setViewContext(ViewContext viewContext) {
- this.viewContext = viewContext;
- }
-
- public URLStreamProvider getUrlStreamProvider() {
- return viewContext.getURLStreamProvider();
- }
-
- public URLStreamProviderBasicAuth getUrlStreamProviderBasicAuth() {
- return new URLStreamProviderBasicAuth(getUrlStreamProvider(),getUserId(),getPassword());
- }
-
- public String getUrl() {
- return url;
- }
-
- public void setUrl(String url) {
- this.url = url;
- }
-
- public boolean isNeedsAuthentication() {
- return needsAuthentication;
- }
-
- public void setNeedsAuthentication(boolean needsAuthentication) {
- this.needsAuthentication = needsAuthentication;
- }
-
- public String getUserId() {
- return userId;
- }
-
- public void setUserId(String userId) {
- this.userId = userId;
- }
-
- public String getPassword() {
- return password;
- }
-
- public void setPassword(String password) {
- this.password = password;
- }
-
- public JsonElement doGetJson(String path) throws IOException {
- return doGetJson(getUrl(), path);
- }
-
- public JsonElement doGetJson(String url, String path) throws IOException {
- InputStream inputStream = null;
- try {
- Map<String, String> headers = new HashMap<String, String>();
- if (isNeedsAuthentication()) {
- inputStream = getUrlStreamProviderBasicAuth().readFrom(
- url + path, "GET", (String) null, headers);
- } else {
- inputStream = getUrlStreamProvider().readAsCurrent(
- url + path, "GET", (String) null, headers);
- }
- } catch (IOException e) {
- logger.error("Error while reading from url " + url + path, e);
- throw e;
- }
- JsonElement jsonElement = new JsonParser().parse(new JsonReader(
- new InputStreamReader(inputStream)));
- return jsonElement;
- }
-
- public String doGet(String path) throws IOException {
- String response = null;
- try {
- InputStream inputStream = null;
- if (isNeedsAuthentication()) {
- inputStream = getUrlStreamProviderBasicAuth().readFrom(
- getUrl() + path, "GET", (String) null,
- new HashMap<String, String>());
- } else {
- inputStream = getUrlStreamProvider().readAsCurrent(
- getUrl() + path, "GET", (String) null,
- new HashMap<String, String>());
- }
- response = IOUtils.toString(inputStream);
- } catch (IOException e) {
- logger.error("Error while reading from url " + getUrl() + path, e);
- throw e;
- }
- return response;
- }
-}
http://git-wip-us.apache.org/repos/asf/ambari/blob/ec8deeba/contrib/views/slider/src/main/java/org/apache/ambari/view/slider/rest/client/JMXMetricHolder.java
----------------------------------------------------------------------
diff --git a/contrib/views/slider/src/main/java/org/apache/ambari/view/slider/rest/client/JMXMetricHolder.java b/contrib/views/slider/src/main/java/org/apache/ambari/view/slider/rest/client/JMXMetricHolder.java
deleted file mode 100644
index 04b824a..0000000
--- a/contrib/views/slider/src/main/java/org/apache/ambari/view/slider/rest/client/JMXMetricHolder.java
+++ /dev/null
@@ -1,50 +0,0 @@
-/**
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.ambari.view.slider.rest.client;
-
-import java.util.List;
-import java.util.Map;
-
-/**
- *
- */
-public final class JMXMetricHolder {
-
- private List<Map<String, Object>> beans;
-
- public List<Map<String, Object>> getBeans() {
- return beans;
- }
-
- public void setBeans(List<Map<String, Object>> beans) {
- this.beans = beans;
- }
-
- @Override
- public String toString() {
- StringBuilder stringBuilder = new StringBuilder();
-
- for (Map<String, Object> map : beans) {
- for (Map.Entry<String, Object> entry : map.entrySet()) {
- stringBuilder.append(" ").append(entry.toString()).append("\n");
- }
- }
- return stringBuilder.toString();
- }
-}
http://git-wip-us.apache.org/repos/asf/ambari/blob/ec8deeba/contrib/views/slider/src/main/java/org/apache/ambari/view/slider/rest/client/Metric.java
----------------------------------------------------------------------
diff --git a/contrib/views/slider/src/main/java/org/apache/ambari/view/slider/rest/client/Metric.java b/contrib/views/slider/src/main/java/org/apache/ambari/view/slider/rest/client/Metric.java
deleted file mode 100644
index 1ec682b..0000000
--- a/contrib/views/slider/src/main/java/org/apache/ambari/view/slider/rest/client/Metric.java
+++ /dev/null
@@ -1,158 +0,0 @@
-/**
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.ambari.view.slider.rest.client;
-
-import org.codehaus.jackson.annotate.JsonIgnore;
-import org.codehaus.jackson.annotate.JsonIgnoreProperties;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-import javax.xml.xpath.XPath;
-import javax.xml.xpath.XPathExpression;
-import javax.xml.xpath.XPathExpressionException;
-import javax.xml.xpath.XPathFactory;
-
-import java.util.ArrayList;
-import java.util.List;
-
-@JsonIgnoreProperties({"keyName", "matchers", "xPathExpression", "xPathExpressionComputed"})
-public class Metric {
- private static final Logger logger = LoggerFactory
- .getLogger(Metric.class);
- private static String SEPARATOR = ".";
- private static char SEPARATOR_REPLACED = '#';
- private String metric;
- private boolean pointInTime;
- private boolean temporal;
- @JsonIgnore
- private String keyName = null;
- @JsonIgnore
- private List<List<String>> matchers = null;
- @JsonIgnore
- private XPathExpression xPathExpression = null;
- @JsonIgnore
- private boolean xPathExpressionComputed = false;
-
- private Metric() {
- }
-
- protected Metric(String metric, boolean pointInTime, boolean temporal) {
- this.metric = metric;
- this.pointInTime = pointInTime;
- this.temporal = temporal;
- }
-
- public String getMetric() {
- return metric;
- }
-
- public void setMetric(String metric) {
- this.metric = metric;
- }
-
- public boolean isPointInTime() {
- return pointInTime;
- }
-
- public void setPointInTime(boolean pointInTime) {
- this.pointInTime = pointInTime;
- }
-
- public boolean isTemporal() {
- return temporal;
- }
-
- public void setTemporal(boolean temporal) {
- this.temporal = temporal;
- }
-
- @JsonIgnore
- public XPathExpression getxPathExpression() {
- if (!xPathExpressionComputed) {
- XPathFactory xPathfactory = XPathFactory.newInstance();
- XPath xpath = xPathfactory.newXPath();
- XPathExpression schemaPath = null;
- try {
- schemaPath = xpath.compile(metric);
- } catch (XPathExpressionException e) {
- logger.info(String.format("Unable to compile %s into xpath expression", metric));
- }
- xPathExpression = schemaPath;
- xPathExpressionComputed = true;
- }
-
- return xPathExpression;
- }
-
- @JsonIgnore
- public String getJmxBeanKeyName() {
- if (keyName == null) {
- int firstIndex = metric.indexOf(SEPARATOR);
- if (firstIndex > 0) {
- keyName = metric.substring(0, firstIndex).replace(SEPARATOR_REPLACED, '.');
- }
- }
- return keyName;
- }
-
- /**
- * Matcher is of the form a.b.c... They can be matched as a -> b-> c or a.b -> c or a -> b.c etc. The matcher returns
- * all possibilities in priority order
- *
- * @return
- */
- @JsonIgnore
- public List<List<String>> getMatchers() {
- if (matchers == null) {
- List<List<String>> tmpMatchers = new ArrayList<List<String>>();
- int matcherStartIndex = metric.indexOf(SEPARATOR);
- if (matcherStartIndex > 0) {
- String allTagsStr = metric.substring(matcherStartIndex + 1);
- String[] tags = allTagsStr.split("\\.");
- if (tags.length > 0) {
- extractMatchers(tags, -1, tmpMatchers, null);
- }
- }
-
- matchers = tmpMatchers;
- }
- return matchers;
- }
-
- public void extractMatchers(String[] tags, int index, List<List<String>> matchers, ArrayList<String> currentSet) {
- if (tags.length == index + 1) {
- matchers.add(currentSet);
- } else {
- if (index == -1) {
- currentSet = new ArrayList<String>();
- currentSet.add(tags[0]);
- extractMatchers(tags, 0, matchers, currentSet);
- } else {
- ArrayList<String> mergeAndProceed = new ArrayList<String>(currentSet);
- mergeAndProceed.add(tags[index + 1]);
- extractMatchers(tags, index + 1, matchers, mergeAndProceed);
-
- ArrayList<String> appendAndProceed = new ArrayList<String>(currentSet);
- int lastIndex = appendAndProceed.size() - 1;
- appendAndProceed.set(lastIndex, appendAndProceed.get(lastIndex) + "." + tags[index + 1]);
- extractMatchers(tags, index + 1, matchers, appendAndProceed);
- }
- }
- }
-}
http://git-wip-us.apache.org/repos/asf/ambari/blob/ec8deeba/contrib/views/slider/src/main/java/org/apache/ambari/view/slider/rest/client/SliderAppJmxHelper.java
----------------------------------------------------------------------
diff --git a/contrib/views/slider/src/main/java/org/apache/ambari/view/slider/rest/client/SliderAppJmxHelper.java b/contrib/views/slider/src/main/java/org/apache/ambari/view/slider/rest/client/SliderAppJmxHelper.java
deleted file mode 100644
index 7f7aae0..0000000
--- a/contrib/views/slider/src/main/java/org/apache/ambari/view/slider/rest/client/SliderAppJmxHelper.java
+++ /dev/null
@@ -1,205 +0,0 @@
-/**
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.ambari.view.slider.rest.client;
-
-import org.apache.commons.io.IOUtils;
-import org.codehaus.jackson.map.DeserializationConfig;
-import org.codehaus.jackson.map.ObjectMapper;
-import org.codehaus.jackson.map.ObjectReader;
-import org.json.simple.JSONObject;
-import org.json.simple.parser.JSONParser;
-import org.json.simple.parser.ParseException;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-import org.w3c.dom.Document;
-import org.xml.sax.SAXException;
-
-import javax.xml.parsers.DocumentBuilder;
-import javax.xml.parsers.DocumentBuilderFactory;
-import javax.xml.parsers.ParserConfigurationException;
-import javax.xml.xpath.XPathExpression;
-import javax.xml.xpath.XPathExpressionException;
-import java.io.IOException;
-import java.io.InputStream;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-
-public class SliderAppJmxHelper {
-
- private static final Logger logger = LoggerFactory
- .getLogger(SliderAppJmxHelper.class);
- private static final String NAME_KEY = "name";
- private static final String PORT_KEY = "tag.port";
- private static final String FORPORT_KEY = "ForPort";
- private static final String JSON_METRIC_START = "$['";
- private static final String JSON_METRIC_END = "']";
-
- public static JMXTypes jmxTypeExpected(Map<String, Metric> metrics) {
- JMXTypes retVal = null;
- for (Metric metric : metrics.values()) {
- if (retVal == null) {
- retVal = getMetricType(metric.getMetric());
- continue;
- } else {
- if (retVal != getMetricType(metric.getMetric())) {
- retVal = null;
- break;
- }
- }
- }
- return retVal;
- }
-
- public static void extractMetricsFromJmxBean(InputStream jmxStream, String jmxUrl,
- Map<String, String> jmxProperties,
- Map<String, Metric> metrics) {
- ObjectMapper jmxObjectMapper = new ObjectMapper();
- jmxObjectMapper.configure(DeserializationConfig.Feature.USE_ANNOTATIONS, false);
- ObjectReader jmxObjectReader = jmxObjectMapper.reader(JMXMetricHolder.class);
- JMXMetricHolder metricHolder = null;
- try {
- metricHolder = jmxObjectReader.readValue(jmxStream);
- } catch (IOException e) {
- logger.error(String.format("Malformed jmx data from %s. Error %s", jmxUrl, e.getMessage()));
- }
-
- Map<String, Map<String, Object>> categories = new HashMap<String, Map<String, Object>>();
-
- for (Map<String, Object> bean : metricHolder.getBeans()) {
- String category = getCategory(bean);
- if (category != null) {
- categories.put(category, bean);
- }
- }
-
- addJmxPropertiesFromBeans(jmxProperties, categories, metrics);
- }
-
- public static void extractMetricsFromJmxJson(InputStream jmxStream, String jmxUrl,
- Map<String, String> jmxProperties,
- Map<String, Metric> metrics)
- throws IOException, ParseException {
- JSONParser parser = new JSONParser();
- Object obj = parser.parse(IOUtils.toString(jmxStream));
- JSONObject jsonObject = (JSONObject) obj;
- for (String key : metrics.keySet()) {
- Metric metric = metrics.get(key);
- String jsonKey = extractJsonKeySingleLevel(metric.getMetric());
- Object value = jsonObject.get(jsonKey);
- if (value != null) {
- jmxProperties.put(key, value.toString());
- }
- }
- }
-
- private static String extractJsonKeySingleLevel(String metricKey) {
- String jsonKey = metricKey;
- if (metricKey != null) {
- if (metricKey.startsWith(JSON_METRIC_START) && metricKey.endsWith(JSON_METRIC_END)) {
- jsonKey = metricKey.substring(JSON_METRIC_START.length(), metricKey.length() - JSON_METRIC_END.length());
- }
- }
-
- return jsonKey;
- }
-
- public static void extractMetricsFromJmxXML(InputStream jmxStream, String jmxUrl,
- Map<String, String> jmxProperties,
- Map<String, Metric> metrics)
- throws ParserConfigurationException, IOException, SAXException, XPathExpressionException {
- DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
- DocumentBuilder builder = factory.newDocumentBuilder();
- Document doc = builder.parse(jmxStream);
- for (String key : metrics.keySet()) {
- Metric metric = metrics.get(key);
- XPathExpression xPathExpression = metric.getxPathExpression();
- if (xPathExpression != null) {
- String value = xPathExpression.evaluate(doc);
- if (value != null) {
- jmxProperties.put(key, value.toString().trim());
- }
- }
- }
- }
-
- private static String getCategory(Map<String, Object> bean) {
- if (bean.containsKey(NAME_KEY)) {
- String name = (String) bean.get(NAME_KEY);
-
- if (bean.containsKey(PORT_KEY)) {
- String port = (String) bean.get(PORT_KEY);
- name = name.replace(FORPORT_KEY + port, "");
- }
- return name;
- }
- return null;
- }
-
- protected static void addJmxPropertiesFromBeans(Map<String, String> jmxProperties,
- Map<String, Map<String, Object>> categories,
- Map<String, Metric> relevantMetrics) {
- for (String metricName : relevantMetrics.keySet()) {
- Metric metric = relevantMetrics.get(metricName);
- String beanName = metric.getJmxBeanKeyName();
- Object value = categories.get(beanName);
- if (value instanceof Map) {
- Map<?, ?> map = (Map<?, ?>) value;
- for (List<String> matcher : metric.getMatchers()) {
- boolean foundMetrics = false;
- for (int matchIndex = 0; matchIndex < matcher.size(); matchIndex++) {
- String matchKey = matcher.get(matchIndex);
- value = map.get(matchKey);
- if (value instanceof Map) {
- map = (Map<?, ?>) value;
- continue;
- } else {
- if (value != null && matchIndex == matcher.size() - 1) {
- jmxProperties.put(metricName, value.toString());
- foundMetrics = true;
- } else {
- break;
- }
- }
- }
- if (foundMetrics) {
- break;
- }
- }
- }
- }
- }
-
- private static JMXTypes getMetricType(String metricKey) {
- assert metricKey != null;
- if (metricKey.startsWith("/")) {
- return JMXTypes.XML;
- } else if (metricKey.startsWith("$")) {
- return JMXTypes.JSON;
- } else {
- return JMXTypes.JMX_BEAN;
- }
- }
-
- public enum JMXTypes {
- JMX_BEAN,
- JSON,
- XML
- }
-}
http://git-wip-us.apache.org/repos/asf/ambari/blob/ec8deeba/contrib/views/slider/src/main/java/org/apache/ambari/view/slider/rest/client/SliderAppMasterClient.java
----------------------------------------------------------------------
diff --git a/contrib/views/slider/src/main/java/org/apache/ambari/view/slider/rest/client/SliderAppMasterClient.java b/contrib/views/slider/src/main/java/org/apache/ambari/view/slider/rest/client/SliderAppMasterClient.java
deleted file mode 100644
index 0a2540c..0000000
--- a/contrib/views/slider/src/main/java/org/apache/ambari/view/slider/rest/client/SliderAppMasterClient.java
+++ /dev/null
@@ -1,324 +0,0 @@
-/**
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.ambari.view.slider.rest.client;
-
-import java.io.IOException;
-import java.io.InputStream;
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.HashSet;
-import java.util.List;
-import java.util.Map;
-import java.util.Map.Entry;
-import java.util.Set;
-
-import org.apache.ambari.view.URLStreamProvider;
-import org.apache.ambari.view.ViewContext;
-import org.apache.ambari.view.slider.MetricsHolder;
-import org.apache.ambari.view.slider.SliderAppType;
-import org.apache.ambari.view.slider.SliderAppTypeComponent;
-import org.apache.ambari.view.slider.TemporalInfo;
-import org.apache.ambari.view.slider.SliderAppsViewController;
-
-import com.google.gson.JsonElement;
-import com.google.gson.JsonObject;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-public class SliderAppMasterClient extends BaseHttpClient {
-
- private static final Logger logger = LoggerFactory
- .getLogger(SliderAppMasterClient.class);
-
- public SliderAppMasterClient(String url, ViewContext viewContext) {
- super(url, viewContext);
- }
-
- public SliderAppMasterData getAppMasterData() {
- try {
- String html = doGet("");
- if (html != null) {
- int from = html.lastIndexOf("<ul>");
- int to = html.lastIndexOf("</ul>");
- if (from < to && from > -1) {
- SliderAppMasterData data = new SliderAppMasterData();
- String content = html.substring(from, to);
- content = content.replaceAll("<[^>]*>", "\r\n");
- String[] splits = content.split("\r\n");
- for (int i = 0; i < splits.length; i++) {
- String split = splits[i].trim();
- if ("classpath:org.apache.slider.registry".equals(split)) {
- data.registryUrl = splits[i + 1].trim();
- } else if ("classpath:org.apache.http.UI".equals(split)) {
- data.uiUrl = splits[i + 1].trim();
- } else if ("classpath:org.apache.slider.management".equals(split)) {
- data.managementUrl = splits[i + 1].trim();
- } else if ("classpath:org.apache.slider.publisher".equals(split)) {
- data.publisherUrl = splits[i + 1].trim();
- }
- }
- return data;
- }
- }
- } catch (IOException e) {
- logger.warn("Unable to determine Ambari clusters", e);
- throw new RuntimeException(e.getMessage(), e);
- }
- return null;
- }
-
- public Map<String, String> getQuickLinks(String providerUrl) {
- Map<String, String> quickLinks = new HashMap<String, String>();
- try {
- if (providerUrl == null || providerUrl.trim().length() < 1) {
- return quickLinks;
- }
- JsonElement json = super.doGetJson(providerUrl, "/slider/quicklinks");
- if (json != null && json.getAsJsonObject() != null
- && json.getAsJsonObject().has("entries")) {
- JsonObject jsonObject = json.getAsJsonObject().get("entries")
- .getAsJsonObject();
- for (Entry<String, JsonElement> entry : jsonObject.entrySet()) {
- if ("org.apache.slider.jmx".equals(entry.getKey())) {
- quickLinks.put("JMX", entry.getValue().getAsString());
- } else if ("org.apache.slider.monitor".equals(entry.getKey())) {
- quickLinks.put("UI", entry.getValue().getAsString());
- } else if ("org.apache.slider.metrics.ui".equals(entry.getKey())) {
- quickLinks.put("Metrics UI", entry.getValue().getAsString());
- } else if ("org.apache.slider.metrics".equals(entry.getKey())) {
- quickLinks.put(SliderAppsViewController.METRICS_API_NAME, entry.getValue().getAsString());
- } else {
- quickLinks.put(entry.getKey(), entry.getValue().getAsString());
- }
- }
- }
- } catch (IOException e) {
- logger.warn("Unable to determine quicklinks from " + providerUrl, e);
- }
- return quickLinks;
- }
-
- public Map<String, Map<String, String>> getConfigs(String providerUrl) {
- Map<String, Map<String, String>> configsMap = new HashMap<String, Map<String, String>>();
- try {
- if (providerUrl == null || providerUrl.trim().length() < 1) {
- return configsMap;
- }
- JsonElement json = super.doGetJson(providerUrl, "/slider");
- if (json != null) {
- JsonObject configsJson = json.getAsJsonObject().get("configurations")
- .getAsJsonObject();
- for (Entry<String, JsonElement> entry : configsJson.entrySet()) {
- if ("complete-config".equals(entry.getKey())
- || "quicklinks".equals(entry.getKey())) {
- continue;
- }
- JsonElement entryJson = super.doGetJson(providerUrl, "/slider/"
- + entry.getKey());
- if (entryJson != null) {
- JsonObject configsObj = entryJson.getAsJsonObject().get("entries")
- .getAsJsonObject();
- if (configsObj != null) {
- Map<String, String> configs = new HashMap<String, String>();
- for (Entry<String, JsonElement> e : configsObj.entrySet()) {
- configs.put(e.getKey(), e.getValue().getAsString());
- }
- configsMap.put(entry.getKey(), configs);
- }
- }
- }
- }
- } catch (IOException e) {
- logger.warn("Unable to determine quicklinks from " + providerUrl, e);
- }
- return configsMap;
- }
-
- public Map<String, Number[][]> getMetrics(String appName,
- String metricsUrl,
- Set<String> metricsRequested,
- TemporalInfo temporalInfo,
- ViewContext context,
- SliderAppType appType,
- MetricsHolder metricsHolder) {
- Map<String, Number[][]> retVal = new HashMap<String, Number[][]>();
-
- if (appType == null || metricsHolder == null
- || metricsHolder.getTimelineMetrics() == null) {
- logger.info("AppType must be provided and it must contain "
- + "timeline_metrics.json to extract jmx properties");
- return retVal;
- }
-
- Map<String, Number[][]> receivedMetrics = null;
- List<String> components = new ArrayList<String>();
- for (SliderAppTypeComponent appTypeComponent : appType.getTypeComponents()) {
- components.add(appTypeComponent.getName());
- }
-
- Map<String, Map<String, Map<String, Metric>>> metrics = metricsHolder
- .getTimelineMetrics();
- Map<String, Metric> relevantMetrics = getRelevantMetrics(metrics, components);
- Set<String> metricsToRead = new HashSet<String>();
- Map<String, String> reverseNameLookup = new HashMap<String, String>();
- for (String key : relevantMetrics.keySet()) {
- if (metricsRequested.contains(key)) {
- String metricName = relevantMetrics.get(key).getMetric();
- metricsToRead.add(metricName);
- reverseNameLookup.put(metricName, key);
- }
- }
-
- if (metricsToRead.size() != 0) {
- try {
- String specWithParams = SliderAppMetricsHelper.getUrlWithParams(
- appName, metricsUrl, metricsToRead, temporalInfo);
- logger.info("Using spec: " + specWithParams);
- if (specWithParams != null) {
-
- String spec = null;
- String params = null;
- String[] tokens = specWithParams.split("\\?", 2);
-
- try {
- spec = tokens[0];
- params = tokens[1];
- } catch (ArrayIndexOutOfBoundsException e) {
- logger.info(e.toString());
- }
-
- receivedMetrics = SliderAppMetricsHelper.getMetrics(context, spec,
- params);
- }
- } catch (Exception e) {
- logger.warn("Unable to retrieve metrics. " + e.getMessage());
- }
- }
-
- if (receivedMetrics != null) {
- for (Map.Entry<String, Number[][]> metric : receivedMetrics.entrySet()) {
- if (reverseNameLookup.containsKey(metric.getKey())) {
- retVal.put(reverseNameLookup.get(metric.getKey()), metric.getValue());
- }
- }
- }
-
- return retVal;
- }
-
- /**
- * Provides only the interesting JMX metric names and values.
- *
- * @param jmxUrl
- *
- * @return
- */
- public Map<String, String> getJmx(String jmxUrl,
- ViewContext context,
- SliderAppType appType,
- MetricsHolder metricsHolder) {
- Map<String, String> jmxProperties = new HashMap<String, String>();
- if (appType == null || metricsHolder == null || metricsHolder.getJmxMetrics() == null) {
- logger
- .info("AppType must be provided and it must contain jmx_metrics.json to extract jmx properties");
- return jmxProperties;
- }
-
- List<String> components = new ArrayList<String>();
- for (SliderAppTypeComponent appTypeComponent : appType.getTypeComponents()) {
- components.add(appTypeComponent.getName());
- }
-
- Map<String, Map<String, Map<String, Metric>>> metrics = metricsHolder.getJmxMetrics();
- Map<String, Metric> relevantMetrics = getRelevantMetrics(metrics, components);
- if (relevantMetrics.size() == 0) {
- logger.info("No metrics found for components defined in the app.");
- return jmxProperties;
- }
-
- SliderAppJmxHelper.JMXTypes jmxType = SliderAppJmxHelper.jmxTypeExpected(relevantMetrics);
- if (jmxType == null) {
- logger
- .info("jmx_metrics.json is malformed. It may have mixed metric key types of unsupported metric key types.");
- return jmxProperties;
- }
-
- try {
- URLStreamProvider streamProvider = context.getURLStreamProvider();
- InputStream jmxStream = null;
- Map<String, String> headers = new HashMap<String, String>();
- try {
- jmxStream = streamProvider.readFrom(jmxUrl, "GET", (String)null, headers);
- } catch (IOException e) {
- logger.error(String.format(
- "Unable to access JMX endpoint at %s. Error %s", jmxUrl,
- e.getMessage()));
- }
-
- if (jmxStream != null) {
- switch (jmxType) {
- case JMX_BEAN:
- SliderAppJmxHelper.extractMetricsFromJmxBean(jmxStream, jmxUrl,
- jmxProperties, relevantMetrics);
- break;
- case JSON:
- SliderAppJmxHelper.extractMetricsFromJmxJson(jmxStream, jmxUrl,
- jmxProperties, relevantMetrics);
- break;
- case XML:
- SliderAppJmxHelper.extractMetricsFromJmxXML(jmxStream, jmxUrl,
- jmxProperties, relevantMetrics);
- break;
- default:
- logger.info("Unsupported jmx type.");
- }
- }
- } catch (Exception e) {
- logger.info("Failed to extract jmx metrics. " + e.getMessage());
- }
-
- return jmxProperties;
- }
-
- private Map<String, Metric> getRelevantMetrics(
- Map<String, Map<String, Map<String, Metric>>> metrics, List<String> comps) {
- Map<String, Metric> relevantMetrics = new HashMap<String, Metric>();
- for (String comp : comps) {
- for (Map<String, Map<String, Metric>> m : metrics.values()) {
- if (m.containsKey(comp)) {
- relevantMetrics.putAll(m.get(comp));
- }
- }
- }
- return relevantMetrics;
- }
-
- public static class SliderAppMasterData {
- public String registryUrl;
- public String uiUrl;
- public String managementUrl;
- public String publisherUrl;
- }
-
- public static class SliderAppContainerData {
- public String hostName;
- public String containerId;
- }
-
-}
http://git-wip-us.apache.org/repos/asf/ambari/blob/ec8deeba/contrib/views/slider/src/main/java/org/apache/ambari/view/slider/rest/client/SliderAppMetricsHelper.java
----------------------------------------------------------------------
diff --git a/contrib/views/slider/src/main/java/org/apache/ambari/view/slider/rest/client/SliderAppMetricsHelper.java b/contrib/views/slider/src/main/java/org/apache/ambari/view/slider/rest/client/SliderAppMetricsHelper.java
deleted file mode 100644
index 1044e9d..0000000
--- a/contrib/views/slider/src/main/java/org/apache/ambari/view/slider/rest/client/SliderAppMetricsHelper.java
+++ /dev/null
@@ -1,159 +0,0 @@
-/**
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.ambari.view.slider.rest.client;
-
-import java.io.BufferedReader;
-import java.io.IOException;
-import java.io.InputStreamReader;
-import java.net.URISyntaxException;
-import java.util.HashMap;
-import java.util.Map;
-import java.util.Set;
-
-import org.apache.ambari.view.SystemException;
-import org.apache.ambari.view.ViewContext;
-import org.apache.ambari.view.slider.TemporalInfo;
-import org.apache.http.client.utils.URIBuilder;
-import org.codehaus.jackson.map.AnnotationIntrospector;
-import org.codehaus.jackson.map.ObjectMapper;
-import org.codehaus.jackson.map.ObjectReader;
-import org.codehaus.jackson.map.annotate.JsonSerialize.Inclusion;
-import org.codehaus.jackson.xc.JaxbAnnotationIntrospector;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-public class SliderAppMetricsHelper {
- private static final Logger logger = LoggerFactory
- .getLogger(SliderAppMetricsHelper.class);
- private static ObjectMapper mapper;
- private final static ObjectReader timelineObjectReader;
- private final static String URI_PARAM_APP_ID = "appId";
- private final static String URI_PARAM_METRIC_NAMES = "metricNames";
- private final static String URI_PARAM_START_TIME = "startTime";
- private final static String URI_PARAM_END_TIME = "endTime";
-
- static {
- mapper = new ObjectMapper();
- AnnotationIntrospector introspector = new JaxbAnnotationIntrospector();
- mapper.setAnnotationIntrospector(introspector);
- // no inspection deprecation
- mapper.getSerializationConfig().setSerializationInclusion(
- Inclusion.NON_NULL);
- timelineObjectReader = mapper.reader(TimelineMetrics.class);
- }
-
- public static Map<String, Number[][]> getMetrics(ViewContext context,
- String spec, String params) throws IOException {
- Map<String, Number[][]> receivedMetrics = new HashMap<String, Number[][]>();
- Map<String, String> headers = new HashMap<String, String>();
-
- BufferedReader reader = null;
- try {
- String fullUrl = spec + "?" + params;
- logger.debug("Metrics request url = " + fullUrl);
- reader = new BufferedReader(new InputStreamReader(context
- .getURLStreamProvider().readFrom(fullUrl, "GET", (String)null, headers)));
-
- TimelineMetrics timelineMetrics = timelineObjectReader.readValue(reader);
- logger.debug("Timeline metrics response => " + timelineMetrics);
-
- for (TimelineMetric tlMetric : timelineMetrics.getMetrics()) {
- if (tlMetric.getMetricName() != null
- && tlMetric.getMetricValues() != null) {
- Map<Long, Double> tlMetricValues = tlMetric.getMetricValues();
- Number[][] metricValues = transformMetricValues(tlMetricValues);
- receivedMetrics.put(tlMetric.getMetricName(), metricValues);
- }
- }
-
- } catch (IOException io) {
- logger.warn("Error getting timeline metrics.", io);
- } finally {
- if (reader != null) {
- try {
- reader.close();
- } catch (IOException e) {
- if (logger.isDebugEnabled()) {
- logger.warn("Unable to close http input steam : spec=" + spec, e);
- }
- }
- }
- }
-
- return receivedMetrics;
- }
-
- private static Number[][] transformMetricValues(
- Map<Long, Double> tlMetricValues) {
- Number[][] metricValues = new Number[tlMetricValues.size()][2];
- int i = 0;
- for (Map.Entry<Long, Double> tlMetricValue : tlMetricValues.entrySet()) {
- // value goes to column 0
- metricValues[i][0] = tlMetricValue.getValue();
- // timestamp goes to column 1 - convert it from millis to sec
- metricValues[i][1] = tlMetricValue.getKey() / 1000;
- i++;
- }
- return metricValues;
- }
-
- public static String getUrlWithParams(String appName, String metricUrl,
- Set<String> metricSet, TemporalInfo temporalInfo) throws SystemException,
- URISyntaxException {
- String metrics = getSetString(metricSet, -1);
- URIBuilder uriBuilder = new URIBuilder(metricUrl);
-
- if (appName != null) {
- uriBuilder.setParameter(URI_PARAM_APP_ID, appName);
- }
- if (metrics.length() > 0) {
- uriBuilder.setParameter(URI_PARAM_METRIC_NAMES, metrics);
- }
-
- if (temporalInfo != null) {
- long startTime = temporalInfo.getStartTime();
- if (startTime != -1) {
- uriBuilder.setParameter(URI_PARAM_START_TIME, String.valueOf(startTime));
- }
- long endTime = temporalInfo.getEndTime();
- if (endTime != -1) {
- uriBuilder.setParameter(URI_PARAM_END_TIME, String.valueOf(endTime));
- }
- } else {
- long endTime = System.currentTimeMillis() / 1000;
- long startTime = System.currentTimeMillis() / 1000 - 60 * 60;
- uriBuilder.setParameter(URI_PARAM_END_TIME, String.valueOf(endTime));
- uriBuilder.setParameter(URI_PARAM_START_TIME, String.valueOf(startTime));
- }
- return uriBuilder.toString();
- }
-
- private static String getSetString(Set<String> set, int limit) {
- StringBuilder sb = new StringBuilder();
- if (limit == -1 || set.size() <= limit) {
- for (String cluster : set) {
- if (sb.length() > 0) {
- sb.append(",");
- }
- sb.append(cluster);
- }
- }
- return sb.toString();
- }
-}
http://git-wip-us.apache.org/repos/asf/ambari/blob/ec8deeba/contrib/views/slider/src/main/java/org/apache/ambari/view/slider/rest/client/TimelineMetric.java
----------------------------------------------------------------------
diff --git a/contrib/views/slider/src/main/java/org/apache/ambari/view/slider/rest/client/TimelineMetric.java b/contrib/views/slider/src/main/java/org/apache/ambari/view/slider/rest/client/TimelineMetric.java
deleted file mode 100644
index e5e1e8f..0000000
--- a/contrib/views/slider/src/main/java/org/apache/ambari/view/slider/rest/client/TimelineMetric.java
+++ /dev/null
@@ -1,172 +0,0 @@
-/**
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.ambari.view.slider.rest.client;
-
-import org.apache.hadoop.classification.InterfaceAudience;
-import org.apache.hadoop.classification.InterfaceStability;
-import javax.xml.bind.annotation.XmlAccessType;
-import javax.xml.bind.annotation.XmlAccessorType;
-import javax.xml.bind.annotation.XmlElement;
-import javax.xml.bind.annotation.XmlRootElement;
-import java.util.Map;
-import java.util.TreeMap;
-
-@XmlRootElement(name = "metric")
-@XmlAccessorType(XmlAccessType.NONE)
-@InterfaceAudience.Public
-@InterfaceStability.Unstable
-public class TimelineMetric implements Comparable<TimelineMetric> {
-
- private String metricName;
- private String appId;
- private String instanceId;
- private String hostName;
- private long timestamp;
- private long startTime;
- private String type;
- private Map<Long, Double> metricValues = new TreeMap<Long, Double>();
-
- @XmlElement(name = "metricname")
- public String getMetricName() {
- return metricName;
- }
-
- public void setMetricName(String metricName) {
- this.metricName = metricName;
- }
-
- @XmlElement(name = "appid")
- public String getAppId() {
- return appId;
- }
-
- public void setAppId(String appId) {
- this.appId = appId;
- }
-
- @XmlElement(name = "instanceid")
- public String getInstanceId() {
- return instanceId;
- }
-
- public void setInstanceId(String instanceId) {
- this.instanceId = instanceId;
- }
-
- @XmlElement(name = "hostname")
- public String getHostName() {
- return hostName;
- }
-
- public void setHostName(String hostName) {
- this.hostName = hostName;
- }
-
- @XmlElement(name = "timestamp")
- public long getTimestamp() {
- return timestamp;
- }
-
- public void setTimestamp(long timestamp) {
- this.timestamp = timestamp;
- }
-
- @XmlElement(name = "starttime")
- public long getStartTime() {
- return startTime;
- }
-
- public void setStartTime(long startTime) {
- this.startTime = startTime;
- }
-
- @XmlElement(name = "type")
- public String getType() {
- return type;
- }
-
- public void setType(String type) {
- this.type = type;
- }
-
- @XmlElement(name = "metrics")
- public Map<Long, Double> getMetricValues() {
- return metricValues;
- }
-
- public void setMetricValues(Map<Long, Double> metricValues) {
- this.metricValues = metricValues;
- }
-
- public void addMetricValues(Map<Long, Double> metricValues) {
- this.metricValues.putAll(metricValues);
- }
-
- @Override
- public boolean equals(Object o) {
- if (this == o) return true;
- if (o == null || getClass() != o.getClass()) return false;
-
- TimelineMetric metric = (TimelineMetric) o;
-
- if (!metricName.equals(metric.metricName)) return false;
- if (hostName != null ? !hostName.equals(metric.hostName) : metric.hostName != null)
- return false;
- if (appId != null ? !appId.equals(metric.appId) : metric.appId != null)
- return false;
- if (instanceId != null ? !instanceId.equals(metric.instanceId) : metric.instanceId != null)
- return false;
- if (timestamp != metric.timestamp) return false;
- if (startTime != metric.startTime) return false;
-
- return true;
- }
-
- public boolean equalsExceptTime(TimelineMetric metric) {
- if (!metricName.equals(metric.metricName)) return false;
- if (hostName != null ? !hostName.equals(metric.hostName) : metric.hostName != null)
- return false;
- if (appId != null ? !appId.equals(metric.appId) : metric.appId != null)
- return false;
- if (instanceId != null ? !instanceId.equals(metric.instanceId) : metric.instanceId != null)
- return false;
-
- return true;
- }
-
- @Override
- public int hashCode() {
- int result = metricName.hashCode();
- result = 31 * result + (appId != null ? appId.hashCode() : 0);
- result = 31 * result + (instanceId != null ? instanceId.hashCode() : 0);
- result = 31 * result + (hostName != null ? hostName.hashCode() : 0);
- result = 31 * result + (int) (timestamp ^ (timestamp >>> 32));
- return result;
- }
-
- @Override
- public int compareTo(TimelineMetric other) {
- if (timestamp > other.timestamp) {
- return -1;
- } else if (timestamp < other.timestamp) {
- return 1;
- } else {
- return metricName.compareTo(other.metricName);
- }
- }
-}
http://git-wip-us.apache.org/repos/asf/ambari/blob/ec8deeba/contrib/views/slider/src/main/java/org/apache/ambari/view/slider/rest/client/TimelineMetrics.java
----------------------------------------------------------------------
diff --git a/contrib/views/slider/src/main/java/org/apache/ambari/view/slider/rest/client/TimelineMetrics.java b/contrib/views/slider/src/main/java/org/apache/ambari/view/slider/rest/client/TimelineMetrics.java
deleted file mode 100644
index bb125af..0000000
--- a/contrib/views/slider/src/main/java/org/apache/ambari/view/slider/rest/client/TimelineMetrics.java
+++ /dev/null
@@ -1,101 +0,0 @@
-/**
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.ambari.view.slider.rest.client;
-
-import org.apache.hadoop.classification.InterfaceAudience;
-import org.apache.hadoop.classification.InterfaceStability;
-
-import javax.xml.bind.annotation.XmlAccessType;
-import javax.xml.bind.annotation.XmlAccessorType;
-import javax.xml.bind.annotation.XmlElement;
-import javax.xml.bind.annotation.XmlRootElement;
-import java.util.ArrayList;
-import java.util.List;
-
-/**
- * The class that hosts a list of timeline entities.
- */
-@XmlRootElement(name = "metrics")
-@XmlAccessorType(XmlAccessType.NONE)
-@InterfaceAudience.Public
-@InterfaceStability.Unstable
-public class TimelineMetrics {
-
- private List<TimelineMetric> allMetrics = new ArrayList<TimelineMetric>();
-
- public TimelineMetrics() {}
-
- @XmlElement(name = "metrics")
- public List<TimelineMetric> getMetrics() {
- return allMetrics;
- }
-
- public void setMetrics(List<TimelineMetric> allMetrics) {
- this.allMetrics = allMetrics;
- }
-
- private boolean isEqualTimelineMetrics(TimelineMetric metric1,
- TimelineMetric metric2) {
-
- boolean isEqual = true;
-
- if (!metric1.getMetricName().equals(metric2.getMetricName())) {
- return false;
- }
-
- if (metric1.getHostName() != null) {
- isEqual = metric1.getHostName().equals(metric2.getHostName());
- }
-
- if (metric1.getAppId() != null) {
- isEqual = metric1.getAppId().equals(metric2.getAppId());
- }
-
- return isEqual;
- }
-
- /**
- * Merge with existing TimelineMetric if everything except startTime is
- * the same.
- * @param metric {@link TimelineMetric}
- */
- public void addOrMergeTimelineMetric(TimelineMetric metric) {
- TimelineMetric metricToMerge = null;
-
- if (!allMetrics.isEmpty()) {
- for (TimelineMetric timelineMetric : allMetrics) {
- if (timelineMetric.equalsExceptTime(metric)) {
- metricToMerge = timelineMetric;
- break;
- }
- }
- }
-
- if (metricToMerge != null) {
- metricToMerge.addMetricValues(metric.getMetricValues());
- if (metricToMerge.getTimestamp() > metric.getTimestamp()) {
- metricToMerge.setTimestamp(metric.getTimestamp());
- }
- if (metricToMerge.getStartTime() > metric.getStartTime()) {
- metricToMerge.setStartTime(metric.getStartTime());
- }
- } else {
- allMetrics.add(metric);
- }
- }
-}
http://git-wip-us.apache.org/repos/asf/ambari/blob/ec8deeba/contrib/views/slider/src/main/java/org/apache/ambari/view/slider/rest/client/URLStreamProviderBasicAuth.java
----------------------------------------------------------------------
diff --git a/contrib/views/slider/src/main/java/org/apache/ambari/view/slider/rest/client/URLStreamProviderBasicAuth.java b/contrib/views/slider/src/main/java/org/apache/ambari/view/slider/rest/client/URLStreamProviderBasicAuth.java
deleted file mode 100644
index 2d32fd7..0000000
--- a/contrib/views/slider/src/main/java/org/apache/ambari/view/slider/rest/client/URLStreamProviderBasicAuth.java
+++ /dev/null
@@ -1,105 +0,0 @@
-/**
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.ambari.view.slider.rest.client;
-
-import org.apache.ambari.view.URLStreamProvider;
-import org.apache.commons.codec.binary.Base64;
-
-import java.io.IOException;
-import java.io.InputStream;
-import java.util.HashMap;
-import java.util.Map;
-
-/**
- * Wrapper for URLStreamProvider that adds authentication header.
- */
-public class URLStreamProviderBasicAuth implements URLStreamProvider {
- private URLStreamProvider urlStreamProvider;
- private String username;
- private String password;
- private String requestedBy = "views";
-
- public URLStreamProviderBasicAuth(URLStreamProvider urlStreamProvider, String username, String password) {
- this.urlStreamProvider = urlStreamProvider;
- this.username = username;
- this.password = password;
- }
-
- /**
- * X-Requested-By header value
- * @param requestedBy value of X-Requested-By header
- */
- public void setRequestedBy(String requestedBy) {
- this.requestedBy = requestedBy;
- }
-
- @Override
- public InputStream readFrom(String url, String method, String data, Map<String, String> headers) throws IOException {
- return urlStreamProvider.readFrom(url, method, data, addHeaders(headers));
- }
-
- @Override
- public InputStream readFrom(String url, String method, InputStream data, Map<String, String> headers) throws IOException {
- return urlStreamProvider.readFrom(url, method, data, addHeaders(headers));
- }
-
- @Override
- public InputStream readAs(String url, String method, String data, Map<String, String> headers, String doAs) throws IOException {
- return urlStreamProvider.readAs(url, method, data, addHeaders(headers), doAs);
- }
-
- @Override
- public InputStream readAs(String url, String method, InputStream data, Map<String, String> headers, String doAs) throws IOException {
- return urlStreamProvider.readAs(url, method, data, addHeaders(headers), doAs);
- }
-
- @Override
- public InputStream readAsCurrent(String url, String method, String data, Map<String, String> headers) throws IOException {
- return urlStreamProvider.readAsCurrent(url, method, data, addHeaders(headers));
- }
-
- @Override
- public InputStream readAsCurrent(String url, String method, InputStream data, Map<String, String> headers) throws IOException {
- return urlStreamProvider.readAsCurrent(url, method, data, addHeaders(headers));
- }
-
- private HashMap<String, String> addHeaders(Map<String, String> customHeaders) {
- HashMap<String, String> newHeaders = new HashMap<String, String>();
- if (customHeaders != null)
- newHeaders.putAll(customHeaders);
-
- if (urlStreamProvider != null) {
- // basic auth is not needed for AmbariStreamProvider
- addBasicAuthHeaders(newHeaders);
- }
- addRequestedByHeaders(newHeaders);
- return newHeaders;
- }
-
- private void addRequestedByHeaders(HashMap<String, String> newHeaders) {
- newHeaders.put("X-Requested-By", requestedBy);
- }
-
- private void addBasicAuthHeaders(HashMap<String, String> headers) {
- String authString = username + ":" + password;
- byte[] authEncBytes = Base64.encodeBase64(authString.getBytes());
- String authStringEnc = new String(authEncBytes);
-
- headers.put("Authorization", "Basic " + authStringEnc);
- }
-}
http://git-wip-us.apache.org/repos/asf/ambari/blob/ec8deeba/contrib/views/slider/src/main/resources/slider.properties
----------------------------------------------------------------------
diff --git a/contrib/views/slider/src/main/resources/slider.properties b/contrib/views/slider/src/main/resources/slider.properties
deleted file mode 100644
index c635e15..0000000
--- a/contrib/views/slider/src/main/resources/slider.properties
+++ /dev/null
@@ -1,19 +0,0 @@
-# Copyright 2011 The Apache Software Foundation
-#
-# Licensed to the Apache Software Foundation (ASF) under one
-# or more contributor license agreements. See the NOTICE file
-# distributed with this work for additional information
-# regarding copyright ownership. The ASF licenses this file
-# to you under the Apache License, Version 2.0 (the
-# "License"); you may not use this file except in compliance
-# with the License. You may obtain a copy of the License at
-#
-# http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS,
-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-# See the License for the specific language governing permissions and
-# limitations under the License.
-
-slider.view.version=${project.version}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/ambari/blob/ec8deeba/contrib/views/slider/src/main/resources/ui/.gitignore
----------------------------------------------------------------------
diff --git a/contrib/views/slider/src/main/resources/ui/.gitignore b/contrib/views/slider/src/main/resources/ui/.gitignore
deleted file mode 100755
index 95fc1d7..0000000
--- a/contrib/views/slider/src/main/resources/ui/.gitignore
+++ /dev/null
@@ -1,31 +0,0 @@
-# Numerous always-ignore extensions
-*.diff
-*.err
-*.orig
-*.log
-*.rej
-*.swo
-*.swp
-*.vi
-*~
-*.sass-cache
-
-# OS or Editor folders
-.DS_Store
-.cache
-.project
-.settings
-.tmproj
-nbproject
-Thumbs.db
-
-# NPM packages folder.
-node_modules/
-
-# Brunch folder for temporary files.
-tmp/
-
-# Brunch output folder.
-public/
-
-bower_components/
http://git-wip-us.apache.org/repos/asf/ambari/blob/ec8deeba/contrib/views/slider/src/main/resources/ui/LICENSE
----------------------------------------------------------------------
diff --git a/contrib/views/slider/src/main/resources/ui/LICENSE b/contrib/views/slider/src/main/resources/ui/LICENSE
deleted file mode 100755
index 345b31a..0000000
--- a/contrib/views/slider/src/main/resources/ui/LICENSE
+++ /dev/null
@@ -1,21 +0,0 @@
-All of brunch-with-ember-reloaded is licensed under the MIT license.
-
-Copyright (c) 2013 Giovanni Collazo
-
-Permission is hereby granted, free of charge, to any person obtaining a copy of
-this software and associated documentation files (the "Software"), to deal in
-the Software without restriction, including without limitation the rights to
-use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
-of the Software, and to permit persons to whom the Software is furnished to do
-so, subject to the following conditions:
-
-The above copyright notice and this permission notice shall be included in all
-copies or substantial portions of the Software.
-
-THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
-IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
-FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
-AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
-LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
-OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
-SOFTWARE.