Skip to content

Commit

Permalink
#187 provide CMDB module
Browse files Browse the repository at this point in the history
  • Loading branch information
nkorange committed Dec 5, 2018
1 parent 3ae5e20 commit aace496
Show file tree
Hide file tree
Showing 42 changed files with 630 additions and 290 deletions.
2 changes: 1 addition & 1 deletion api/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
<parent>
<groupId>com.alibaba.nacos</groupId>
<artifactId>nacos-all</artifactId>
<version>0.5.0</version>
<version>0.5.0-cmdb-SNAPSHOT</version>
</parent>

<modelVersion>4.0.0</modelVersion>
Expand Down
19 changes: 17 additions & 2 deletions api/src/main/java/com/alibaba/nacos/api/cmdb/CmdbService.java
Original file line number Diff line number Diff line change
@@ -1,3 +1,18 @@
/*
* Copyright 1999-2018 Alibaba Group Holding Ltd.
*
* Licensed 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 com.alibaba.nacos.api.cmdb;

import com.alibaba.nacos.api.cmdb.pojo.Entity;
Expand Down Expand Up @@ -59,15 +74,15 @@ public interface CmdbService {
*
* @return all entities
*/
Map<String, Map<String, Entity>> dumpAllEntities();
Map<String, Map<String, Entity>> getAllEntities();

/**
* get label change events
*
* @param timestamp start time of generated events
* @return label events
*/
List<EntityEvent> getLabelEvents(long timestamp);
List<EntityEvent> getEntityEvents(long timestamp);

/**
* Get single entity
Expand Down
15 changes: 15 additions & 0 deletions api/src/main/java/com/alibaba/nacos/api/cmdb/pojo/Entity.java
Original file line number Diff line number Diff line change
@@ -1,3 +1,18 @@
/*
* Copyright 1999-2018 Alibaba Group Holding Ltd.
*
* Licensed 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 com.alibaba.nacos.api.cmdb.pojo;

import java.util.Map;
Expand Down
15 changes: 15 additions & 0 deletions api/src/main/java/com/alibaba/nacos/api/cmdb/pojo/EntityEvent.java
Original file line number Diff line number Diff line change
@@ -1,3 +1,18 @@
/*
* Copyright 1999-2018 Alibaba Group Holding Ltd.
*
* Licensed 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 com.alibaba.nacos.api.cmdb.pojo;

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,30 @@
/*
* Copyright 1999-2018 Alibaba Group Holding Ltd.
*
* Licensed 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 com.alibaba.nacos.api.cmdb.pojo;

/**
* @author <a href="mailto:[email protected]">nkorange</a>
*/
public enum EntityEventType {
/**
*
*/
ENTITY_ADD_OR_UPDATE,
/**
*
*/
ENTITY_REMOVE
}
15 changes: 15 additions & 0 deletions api/src/main/java/com/alibaba/nacos/api/cmdb/pojo/Label.java
Original file line number Diff line number Diff line change
@@ -1,3 +1,18 @@
/*
* Copyright 1999-2018 Alibaba Group Holding Ltd.
*
* Licensed 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 com.alibaba.nacos.api.cmdb.pojo;

import java.util.Set;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,30 @@
/*
* Copyright 1999-2018 Alibaba Group Holding Ltd.
*
* Licensed 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 com.alibaba.nacos.api.cmdb.pojo;

/**
* @author <a href="mailto:[email protected]">nkorange</a>
*/
public enum PreservedEntityTypes {
/**
*
*/
ip,
/**
*
*/
service
}
17 changes: 15 additions & 2 deletions api/src/main/java/com/alibaba/nacos/api/naming/pojo/Service.java
Original file line number Diff line number Diff line change
Expand Up @@ -39,15 +39,20 @@ public class Service {
private String app;

/**
* Service group is meant to classify services into different sets.
* Service group is meant to classify services into different sets
*/
private String group;

/**
* Health check mode.
* Health check mode
*/
private String healthCheckMode;

/**
* Selector name of this service
*/
private String selectorName;

private Map<String, String> metadata = new HashMap<String, String>();

public Service(String name) {
Expand Down Expand Up @@ -105,4 +110,12 @@ public void setMetadata(Map<String, String> metadata) {
public void addMetadata(String key, String value) {
this.metadata.put(key, value);
}

public String getSelectorName() {
return selectorName;
}

public void setSelectorName(String selectorName) {
this.selectorName = selectorName;
}
}
2 changes: 1 addition & 1 deletion client/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
<parent>
<groupId>com.alibaba.nacos</groupId>
<artifactId>nacos-all</artifactId>
<version>0.5.0</version>
<version>0.5.0-cmdb-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>

Expand Down
90 changes: 51 additions & 39 deletions cmdb/pom.xml
Original file line number Diff line number Diff line change
@@ -1,18 +1,32 @@
<?xml version="1.0" encoding="UTF-8"?>

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
<!--
Copyright 1999-2018 Alibaba Group Holding Ltd.
Licensed 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.
-->
<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">

<parent>
<artifactId>nacos-all</artifactId>
<groupId>com.alibaba.nacos</groupId>
<version>0.5.0</version>
<version>0.5.0-cmdb-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>
<modelVersion>4.0.0</modelVersion>

<artifactId>nacos-cmdb</artifactId>
<packaging>war</packaging>
<packaging>jar</packaging>

<name>nacos-cmdb Maven Webapp</name>
<name>nacos-cmdb ${project.version}</name>
<!-- FIXME change it to the project's website -->
<url>http://www.example.com</url>

Expand Down Expand Up @@ -56,39 +70,37 @@
</dependencies>

<build>
<finalName>nacos-cmdb</finalName>
<pluginManagement><!-- lock down plugins versions to avoid using Maven defaults (may be moved to parent pom) -->
<plugins>
<plugin>
<artifactId>maven-clean-plugin</artifactId>
<version>3.0.0</version>
</plugin>
<!-- see http://maven.apache.org/ref/current/maven-core/default-bindings.html#Plugin_bindings_for_war_packaging -->
<plugin>
<artifactId>maven-resources-plugin</artifactId>
<version>3.0.2</version>
</plugin>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.7.0</version>
</plugin>
<plugin>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.20.1</version>
</plugin>
<plugin>
<artifactId>maven-war-plugin</artifactId>
<version>3.2.0</version>
</plugin>
<plugin>
<artifactId>maven-install-plugin</artifactId>
<version>2.5.2</version>
</plugin>
<plugin>
<artifactId>maven-deploy-plugin</artifactId>
<version>2.8.2</version>
</plugin>
</plugins>
</pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<skipTests>true</skipTests>
<argLine>-Dnacos.standalone=true</argLine>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-assembly-plugin</artifactId>
<configuration>
<archive>
<manifest>
<mainClass>com.alibaba.nacos.cmdb.CmdbApp</mainClass>
</manifest>
</archive>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
</configuration>
</plugin>
</plugins>
<resources>
<resource>
<directory>src/main/resources</directory>
<excludes>
<exclude>application.properties</exclude>
</excludes>
</resource>
</resources>
</build>
</project>
15 changes: 15 additions & 0 deletions cmdb/src/main/java/com/alibaba/nacos/cmdb/CmdbApp.java
Original file line number Diff line number Diff line change
@@ -1,3 +1,18 @@
/*
* Copyright 1999-2018 Alibaba Group Holding Ltd.
*
* Licensed 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 com.alibaba.nacos.cmdb;

import org.springframework.boot.SpringApplication;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.alibaba.nacos.cmdb.controllers;

import com.alibaba.nacos.cmdb.core.SwitchAndOptions;
import com.alibaba.nacos.cmdb.memory.CmdbProvider;
import com.alibaba.nacos.cmdb.utils.UtilsAndCommons;
import com.alibaba.nacos.common.util.WebUtils;
import org.springframework.beans.factory.annotation.Autowired;
Expand All @@ -20,6 +21,9 @@ public class OperationController {
@Autowired
private SwitchAndOptions switches;

@Autowired
private CmdbProvider cmdbProvider;

@RequestMapping(value = "/updateSwitch", method = RequestMethod.POST)
public String updateSwitch(HttpServletRequest request) throws Exception {

Expand All @@ -41,4 +45,11 @@ public String updateSwitch(HttpServletRequest request) throws Exception {
}
return "ok";
}

@RequestMapping(value = "/queryLabel", method = RequestMethod.GET)
public String queryLabel(HttpServletRequest request) throws Exception {
String entry = WebUtils.required(request, "entry");
String label = WebUtils.required(request, "label");
return cmdbProvider.queryLabel(entry, "ip", label);
}
}
15 changes: 15 additions & 0 deletions cmdb/src/main/java/com/alibaba/nacos/cmdb/core/CmdbManager.java
Original file line number Diff line number Diff line change
@@ -1,3 +1,18 @@
/*
* Copyright 1999-2018 Alibaba Group Holding Ltd.
*
* Licensed 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 com.alibaba.nacos.cmdb.core;

/**
Expand Down
Loading

0 comments on commit aace496

Please sign in to comment.