You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@skywalking.apache.org by ha...@apache.org on 2018/10/28 02:22:39 UTC

[incubator-skywalking] 03/03: Add undefined node icon

This is an automated email from the ASF dual-hosted git repository.

hanahmily pushed a commit to branch webapp/proxy
in repository https://gitbox.apache.org/repos/asf/incubator-skywalking.git

commit 1328d1acadab545f8225a4c4a0f7cbbdfab5330a
Author: gaohongtao <ha...@gmail.com>
AuthorDate: Sun Oct 28 10:20:03 2018 +0800

    Add undefined node icon
---
 .../apm/webapp/proxy/CollectorServerList.java      | 69 ----------------
 .../skywalking/apm/webapp/proxy/MvcConfig.java     | 67 +++++++++++++++
 apm-webapp/src/main/resources/application.yml      |  5 +-
 .../apm/webapp/proxy/NIWSServerListTest.java       | 95 ----------------------
 4 files changed, 71 insertions(+), 165 deletions(-)

diff --git a/apm-webapp/src/main/java/org/apache/skywalking/apm/webapp/proxy/CollectorServerList.java b/apm-webapp/src/main/java/org/apache/skywalking/apm/webapp/proxy/CollectorServerList.java
deleted file mode 100644
index 5babc5f..0000000
--- a/apm-webapp/src/main/java/org/apache/skywalking/apm/webapp/proxy/CollectorServerList.java
+++ /dev/null
@@ -1,69 +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.skywalking.apm.webapp.proxy;
-
-import com.google.common.base.Strings;
-import com.google.common.collect.Lists;
-import com.google.gson.Gson;
-import com.google.gson.JsonArray;
-import com.netflix.client.config.CommonClientConfigKey;
-import com.netflix.client.config.IClientConfig;
-import com.netflix.loadbalancer.AbstractServerList;
-import com.netflix.loadbalancer.Server;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-import java.io.IOException;
-import java.util.List;
-import java.util.concurrent.CopyOnWriteArrayList;
-import java.util.stream.Collectors;
-import java.util.stream.StreamSupport;
-
-public class CollectorServerList extends AbstractServerList<Server> {
-    
-    private IClientConfig clientConfig;
-
-    public List<Server> getInitialListOfServers() {
-        return fetchServer();
-    }
-
-    public List<Server> getUpdatedListOfServers() {
-        return fetchServer();
-    }
-
-    public void initWithNiwsConfig(IClientConfig clientConfig) {
-        this.clientConfig = clientConfig;
-    }
-
-    protected List<Server> derive(String value) {
-        List<Server> list = Lists.newArrayList();
-        if (Strings.isNullOrEmpty(value)) {
-            return list;
-        }
-        String[] serverArray = value.split(",");
-        for (String s : serverArray) {
-            list.add(new Server(s.trim()));
-        }
-        return list;
-    }
-
-    private List<Server> fetchServer() {
-        return derive(this.clientConfig.get(CommonClientConfigKey.ListOfServers));
-    }
-}
diff --git a/apm-webapp/src/main/java/org/apache/skywalking/apm/webapp/proxy/MvcConfig.java b/apm-webapp/src/main/java/org/apache/skywalking/apm/webapp/proxy/MvcConfig.java
new file mode 100644
index 0000000..81c40ba
--- /dev/null
+++ b/apm-webapp/src/main/java/org/apache/skywalking/apm/webapp/proxy/MvcConfig.java
@@ -0,0 +1,67 @@
+/*
+ * 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.skywalking.apm.webapp.proxy;
+
+import java.io.IOException;
+import java.util.Arrays;
+import org.springframework.context.annotation.Configuration;
+import org.springframework.core.io.Resource;
+import org.springframework.web.servlet.config.annotation.EnableWebMvc;
+import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
+import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;
+import org.springframework.web.servlet.resource.PathResourceResolver;
+
+/**
+ * Additional MVC Configuration.
+ * 
+ * @author gaohongtao
+ */
+@Configuration
+@EnableWebMvc
+public class MvcConfig extends WebMvcConfigurerAdapter {
+    @Override
+    public void addResourceHandlers(final ResourceHandlerRegistry registry) {
+        registry
+            .addResourceHandler("/**")
+            .addResourceLocations("classpath:/public/")
+            .setCachePeriod(3600)
+            .resourceChain(true)
+            .addResolver(new PathResourceResolver() {
+                @Override protected Resource getResource(String resourcePath, Resource location) throws IOException {
+                    Resource raw =  super.getResource(resourcePath, location);
+                    if (raw != null || !resourcePath.startsWith("img/node")) {
+                        return raw;
+                    }
+                    Resource resource = location.createRelative("img/node/UNDEFINED.png");
+                    if (!resource.exists() || !resource.isReadable()) {
+                        return null;
+                    }
+                    if (this.checkResource(resource, location)) {
+                        return resource;
+                    }
+
+                    if (this.logger.isTraceEnabled()) {
+                        Resource[] allowedLocations = this.getAllowedLocations();
+                        this.logger.trace("Resource path \"" + resourcePath + "\" was successfully resolved but resource \"" + resource.getURL() + "\" is neither under the current location \"" + location.getURL() + "\" nor under any of the allowed locations " + (allowedLocations != null ? Arrays.asList(allowedLocations) : "[]"));
+                    }
+                    return null;
+                }
+            });
+    }
+}
\ No newline at end of file
diff --git a/apm-webapp/src/main/resources/application.yml b/apm-webapp/src/main/resources/application.yml
index c7aa9f4..aa9dde8 100644
--- a/apm-webapp/src/main/resources/application.yml
+++ b/apm-webapp/src/main/resources/application.yml
@@ -16,6 +16,7 @@
 
 server:
   port: 8080
+
 zuul:
   ignoredServices: '*'
   routes:
@@ -27,9 +28,11 @@ collector:
   path: /graphql
   ribbon:
     listOfServers: 127.0.0.1:10800
-    NIWSServerListClassName: org.apache.skywalking.apm.webapp.proxy.CollectorServerList
 
 security:
   user:
     admin:
       password: admin
+logging:
+  config: classpath
+      
diff --git a/apm-webapp/src/test/java/org/apache/skywalking/apm/webapp/proxy/NIWSServerListTest.java b/apm-webapp/src/test/java/org/apache/skywalking/apm/webapp/proxy/NIWSServerListTest.java
deleted file mode 100644
index 38748ce..0000000
--- a/apm-webapp/src/test/java/org/apache/skywalking/apm/webapp/proxy/NIWSServerListTest.java
+++ /dev/null
@@ -1,95 +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.skywalking.apm.webapp.proxy;
-
-import org.junit.Before;
-import org.junit.Test;
-import org.junit.runner.RunWith;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotNull;
-import java.util.HashMap;
-import java.util.Iterator;
-import java.util.Map;
-import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.boot.test.context.SpringBootTest;
-import org.springframework.core.env.AbstractEnvironment;
-import org.springframework.core.env.Environment;
-import org.springframework.core.env.MapPropertySource;
-import org.springframework.test.annotation.DirtiesContext;
-import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
-import com.netflix.loadbalancer.Server;
-import com.netflix.loadbalancer.ServerList;
-import com.netflix.loadbalancer.ZoneAwareLoadBalancer;
-import org.springframework.cloud.netflix.ribbon.SpringClientFactory;
-
-@RunWith(SpringJUnit4ClassRunner.class)
-@SpringBootTest
-@DirtiesContext
-public class NIWSServerListTest {
-    @Autowired
-    private Environment env;
-
-    @Autowired
-    private SpringClientFactory factory;
-
-    private Map<String, String> serverListClassNames = new HashMap<String, String>();
-
-    @Before
-    public void initServerListClassNames() {
-        for (Iterator<?> iter = ((AbstractEnvironment) env).getPropertySources().iterator(); iter.hasNext();) {
-            Object propertySource = iter.next();
-            if (propertySource instanceof MapPropertySource) {
-                Map<String, Object> mapPropertySource = ((MapPropertySource) propertySource).getSource();
-                for (Map.Entry<String, Object> entry : mapPropertySource.entrySet()) {
-                    String key = entry.getKey();
-                    int index;
-                    if (key.endsWith(".NIWSServerListClassName") &&
-                            (index = key.indexOf(".ribbon")) > 0) {
-                        String clientName = key.substring(0, index);
-                        serverListClassNames.put(clientName,(String)entry.getValue());
-                    }
-                }
-            }
-        }
-    }
-
-    @Test
-    public void serverListClass() throws ClassNotFoundException {
-        for (String serverListClassName : serverListClassNames.values()) {
-            Class<?> clazz = Class.forName(serverListClassName);
-        }
-    }
-
-    @Test
-    public void serverListFliter() {
-        for (Map.Entry<String, String> entry : serverListClassNames.entrySet()) {
-            String clientName = entry.getKey();
-            String serverListClassName = entry.getValue();
-            ServerList<Server> serverList = getLoadBalancer(clientName).getServerListImpl();
-            assertNotNull("Client: " + clientName + "'s ServerListImpl is null",serverList);
-            assertEquals("Clinet: " + clientName + "'s ServerListImpl not Same with setting in configs",
-                    serverListClassName, serverList.getClass().getName());
-        }
-    }
-
-    @SuppressWarnings("unchecked")
-    private ZoneAwareLoadBalancer<Server> getLoadBalancer(String name) {
-        return (ZoneAwareLoadBalancer<Server>)this.factory.getLoadBalancer(name);
-    }
-}