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

[ISSUE #2992] Use new code style for nacos-console module. #3195

Merged
merged 1 commit into from
Jun 29, 2020
Merged
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
16 changes: 8 additions & 8 deletions console/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@
~ limitations under the License.
-->
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>com.alibaba.nacos</groupId>
Expand All @@ -30,7 +30,7 @@
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>

<dependencies>
<dependency>
<groupId>${project.groupId}</groupId>
Expand All @@ -44,12 +44,12 @@
<groupId>${project.groupId}</groupId>
<artifactId>nacos-naming</artifactId>
</dependency>

<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>nacos-istio</artifactId>
</dependency>

<!-- log -->
<!-- log4j通过slf4j来代理 -->
<dependency>
Expand Down Expand Up @@ -91,7 +91,7 @@
<scope>runtime</scope>
</dependency>
</dependencies>

<build>
<resources>
<resource>
Expand All @@ -102,7 +102,7 @@
</resource>
</resources>
</build>

<reporting>
<plugins>
<plugin>
Expand All @@ -111,7 +111,7 @@
</plugin>
</plugins>
</reporting>

<profiles>
<profile>
<id>release-nacos</id>
Expand Down
6 changes: 3 additions & 3 deletions console/src/main/java/com/alibaba/nacos/Nacos.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,16 +21,16 @@
import org.springframework.boot.web.servlet.ServletComponentScan;
import org.springframework.scheduling.annotation.EnableScheduling;

import java.util.concurrent.*;

/**
* Nacos starter.
*
* @author nacos
*/
@SpringBootApplication(scanBasePackages = "com.alibaba.nacos")
@ServletComponentScan
@EnableScheduling
public class Nacos {

public static void main(String[] args) {
SpringApplication.run(Nacos.class, args);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.alibaba.nacos.console.config;

package com.alibaba.nacos.console.config;

import com.alibaba.nacos.core.code.ControllerMethodsCache;
import org.springframework.beans.factory.annotation.Autowired;
Expand All @@ -29,6 +29,8 @@
import javax.annotation.PostConstruct;

/**
* Console config.
*
* @author yshen
* @author nkorange
* @since 1.2.0
Expand All @@ -37,26 +39,29 @@
@EnableScheduling
@PropertySource("/application.properties")
public class ConsoleConfig {

@Autowired
private ControllerMethodsCache methodsCache;


/**
* Init.
*/
@PostConstruct
public void init() {
methodsCache.initClassMethod("com.alibaba.nacos.naming.controllers");
methodsCache.initClassMethod("com.alibaba.nacos.console.controller");
methodsCache.initClassMethod("com.alibaba.nacos.config.server.controller");
}

@Bean
public CorsFilter corsFilter() {
UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource();
CorsConfiguration config = new CorsConfiguration();
config.setAllowCredentials(true);
config.addAllowedOrigin("*");
config.addAllowedHeader("*");
config.setMaxAge(18000L);
config.addAllowedMethod("*");
UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource();
source.registerCorsConfiguration("/**", config);
return new CorsFilter(source);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package com.alibaba.nacos.console.controller;

import com.alibaba.nacos.config.server.service.repository.PersistService;
Expand All @@ -28,25 +29,28 @@
import javax.servlet.http.HttpServletRequest;

/**
* Health Controller.
*
* @author <a href="mailto:[email protected]">hxy1991</a>
*/
@RestController("consoleHealth")
@RequestMapping("/v1/console/health")
public class HealthController {

private static final Logger logger = LoggerFactory.getLogger(HealthController.class);

private static final Logger LOGGER = LoggerFactory.getLogger(HealthController.class);
private final PersistService persistService;

private final OperatorController apiCommands;

@Autowired
public HealthController(PersistService persistService, OperatorController apiCommands) {
this.persistService = persistService;
this.apiCommands = apiCommands;
}

/**
* Whether the Nacos is in broken states or not, and cannot recover except by being restarted
* Whether the Nacos is in broken states or not, and cannot recover except by being restarted.
*
* @return HTTP code equal to 200 indicates that Nacos is in right states. HTTP code equal to 500 indicates that
* Nacos is in broken states.
Expand All @@ -55,9 +59,9 @@ public HealthController(PersistService persistService, OperatorController apiCom
public ResponseEntity liveness() {
return ResponseEntity.ok().body("OK");
}

/**
* Ready to receive the request or not
* Ready to receive the request or not.
*
* @return HTTP code equal to 200 indicates that Nacos is ready. HTTP code equal to 500 indicates that Nacos is not
* ready.
Expand All @@ -66,39 +70,39 @@ public ResponseEntity liveness() {
public ResponseEntity readiness(HttpServletRequest request) {
boolean isConfigReadiness = isConfigReadiness();
boolean isNamingReadiness = isNamingReadiness(request);

if (isConfigReadiness && isNamingReadiness) {
return ResponseEntity.ok().body("OK");
}

if (!isConfigReadiness && !isNamingReadiness) {
return ResponseEntity.status(500).body("Config and Naming are not in readiness");
}

if (!isConfigReadiness) {
return ResponseEntity.status(500).body("Config is not in readiness");
}

return ResponseEntity.status(500).body("Naming is not in readiness");
}

private boolean isConfigReadiness() {
// check db
try {
persistService.configInfoCount("");
return true;
} catch (Exception e) {
logger.error("Config health check fail.", e);
LOGGER.error("Config health check fail.", e);
}
return false;
}

private boolean isNamingReadiness(HttpServletRequest request) {
try {
apiCommands.metrics(request);
return true;
} catch (Exception e) {
logger.error("Naming health check fail.", e);
LOGGER.error("Naming health check fail.", e);
}
return false;
}
Expand Down
Loading