forked from alibaba/nacos
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
alibaba#97 Support integrating to third-party CMDB to filter service …
…providers by their labels.
- Loading branch information
Showing
40 changed files
with
993 additions
and
388 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,17 @@ | ||
package com.alibaba.nacos.cmdb.plugin.spi; | ||
package com.alibaba.nacos.api.cmdb; | ||
|
||
import com.alibaba.nacos.cmdb.pojo.Entity; | ||
import com.alibaba.nacos.cmdb.pojo.Label; | ||
import com.alibaba.nacos.cmdb.pojo.LabelEvent; | ||
import com.alibaba.nacos.api.cmdb.pojo.Entity; | ||
import com.alibaba.nacos.api.cmdb.pojo.EntityEvent; | ||
import com.alibaba.nacos.api.cmdb.pojo.Label; | ||
|
||
import java.util.List; | ||
import java.util.Map; | ||
import java.util.Set; | ||
|
||
/** | ||
* Main service to interact with third-party CMDB. | ||
* | ||
* @author <a href="mailto:[email protected]">nkorange</a> | ||
*/ | ||
public interface ExternalCmdbService { | ||
public interface CmdbService { | ||
|
||
/** | ||
* Get all label names stored in CMDB | ||
|
@@ -61,12 +59,22 @@ public interface ExternalCmdbService { | |
* | ||
* @return all entities | ||
*/ | ||
Map<String, Set<Entity>> dumpAllEntities(); | ||
Map<String, Map<String, Entity>> dumpAllEntities(); | ||
|
||
/** | ||
* get label change events | ||
* | ||
* @param timestamp start time of generated events | ||
* @return label events | ||
*/ | ||
List<LabelEvent> getLabelEvents(); | ||
List<EntityEvent> getLabelEvents(long timestamp); | ||
|
||
/** | ||
* Get single entity | ||
* | ||
* @param entityName name of entity | ||
* @param entityType type of entity | ||
* @return | ||
*/ | ||
Entity getEntity(String entityName, String entityType); | ||
} |
37 changes: 37 additions & 0 deletions
37
api/src/main/java/com/alibaba/nacos/api/cmdb/pojo/Entity.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
package com.alibaba.nacos.api.cmdb.pojo; | ||
|
||
import java.util.Map; | ||
|
||
/** | ||
* @author <a href="mailto:[email protected]">nkorange</a> | ||
*/ | ||
public class Entity { | ||
|
||
private String type; | ||
private String name; | ||
private Map<String, String> labels; | ||
|
||
public String getType() { | ||
return type; | ||
} | ||
|
||
public void setType(String type) { | ||
this.type = type; | ||
} | ||
|
||
public String getName() { | ||
return name; | ||
} | ||
|
||
public void setName(String name) { | ||
this.name = name; | ||
} | ||
|
||
public Map<String, String> getLabels() { | ||
return labels; | ||
} | ||
|
||
public void setLabels(Map<String, String> labels) { | ||
this.labels = labels; | ||
} | ||
} |
35 changes: 35 additions & 0 deletions
35
api/src/main/java/com/alibaba/nacos/api/cmdb/pojo/EntityEvent.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
package com.alibaba.nacos.api.cmdb.pojo; | ||
|
||
/** | ||
* @author <a href="mailto:[email protected]">nkorange</a> | ||
*/ | ||
public class EntityEvent { | ||
|
||
private EntityEventType type; | ||
private String entityName; | ||
private String entityType; | ||
|
||
public EntityEventType getType() { | ||
return type; | ||
} | ||
|
||
public void setType(EntityEventType type) { | ||
this.type = type; | ||
} | ||
|
||
public String getEntityName() { | ||
return entityName; | ||
} | ||
|
||
public void setEntityName(String entityName) { | ||
this.entityName = entityName; | ||
} | ||
|
||
public String getEntityType() { | ||
return entityType; | ||
} | ||
|
||
public void setEntityType(String entityType) { | ||
this.entityType = entityType; | ||
} | ||
} |
9 changes: 9 additions & 0 deletions
9
api/src/main/java/com/alibaba/nacos/api/cmdb/pojo/EntityEventType.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
package com.alibaba.nacos.api.cmdb.pojo; | ||
|
||
/** | ||
* @author <a href="mailto:[email protected]">nkorange</a> | ||
*/ | ||
public enum EntityEventType { | ||
ENTITY_ADD_OR_UPDATE, | ||
ENTITY_REMOVE | ||
} |
37 changes: 37 additions & 0 deletions
37
api/src/main/java/com/alibaba/nacos/api/cmdb/pojo/Label.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
package com.alibaba.nacos.api.cmdb.pojo; | ||
|
||
import java.util.Set; | ||
|
||
/** | ||
* @author <a href="mailto:[email protected]">nkorange</a> | ||
*/ | ||
public class Label { | ||
|
||
private String name; | ||
private Set<String> values; | ||
private String description; | ||
|
||
public String getName() { | ||
return name; | ||
} | ||
|
||
public void setName(String name) { | ||
this.name = name; | ||
} | ||
|
||
public Set<String> getValues() { | ||
return values; | ||
} | ||
|
||
public void setValues(Set<String> values) { | ||
this.values = values; | ||
} | ||
|
||
public String getDescription() { | ||
return description; | ||
} | ||
|
||
public void setDescription(String description) { | ||
this.description = description; | ||
} | ||
} |
9 changes: 9 additions & 0 deletions
9
api/src/main/java/com/alibaba/nacos/api/cmdb/pojo/PreservedEntityTypes.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
package com.alibaba.nacos.api.cmdb.pojo; | ||
|
||
/** | ||
* @author <a href="mailto:[email protected]">nkorange</a> | ||
*/ | ||
public enum PreservedEntityTypes { | ||
ip, | ||
service | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
44 changes: 44 additions & 0 deletions
44
cmdb/src/main/java/com/alibaba/nacos/cmdb/controllers/OperationController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
package com.alibaba.nacos.cmdb.controllers; | ||
|
||
import com.alibaba.nacos.cmdb.core.SwitchAndOptions; | ||
import com.alibaba.nacos.cmdb.utils.UtilsAndCommons; | ||
import com.alibaba.nacos.common.util.WebUtils; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.web.bind.annotation.RequestMapping; | ||
import org.springframework.web.bind.annotation.RequestMethod; | ||
import org.springframework.web.bind.annotation.RestController; | ||
|
||
import javax.servlet.http.HttpServletRequest; | ||
|
||
/** | ||
* @author <a href="mailto:[email protected]">nkorange</a> | ||
*/ | ||
@RestController | ||
@RequestMapping(UtilsAndCommons.NACOS_CMDB_CONTEXT + "/ops") | ||
public class OperationController { | ||
|
||
@Autowired | ||
private SwitchAndOptions switches; | ||
|
||
@RequestMapping(value = "/updateSwitch", method = RequestMethod.POST) | ||
public String updateSwitch(HttpServletRequest request) throws Exception { | ||
|
||
String entry = WebUtils.required(request, "entry"); | ||
String value = WebUtils.required(request, "value"); | ||
|
||
switch (entry) { | ||
case "dumpTaskInterval": | ||
switches.setDumpTaskInterval(Integer.parseInt(value)); | ||
break; | ||
case "eventTaskInterval": | ||
switches.setEventTaskInterval(Integer.parseInt(value)); | ||
break; | ||
case "loadDataAtStart": | ||
switches.setLoadDataAtStart(Boolean.parseBoolean(value)); | ||
break; | ||
default: | ||
break; | ||
} | ||
return "ok"; | ||
} | ||
} |
7 changes: 7 additions & 0 deletions
7
cmdb/src/main/java/com/alibaba/nacos/cmdb/core/CmdbManager.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package com.alibaba.nacos.cmdb.core; | ||
|
||
/** | ||
* @author <a href="mailto:[email protected]">nkorange</a> | ||
*/ | ||
public class CmdbManager { | ||
} |
44 changes: 44 additions & 0 deletions
44
cmdb/src/main/java/com/alibaba/nacos/cmdb/core/SwitchAndOptions.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
package com.alibaba.nacos.cmdb.core; | ||
|
||
import org.springframework.beans.factory.annotation.Value; | ||
import org.springframework.stereotype.Component; | ||
|
||
/** | ||
* @author <a href="mailto:[email protected]">nkorange</a> | ||
*/ | ||
@Component | ||
public class SwitchAndOptions { | ||
|
||
@Value("${nacos.cmdb.dumpTaskInterval}") | ||
private int dumpTaskInterval; | ||
|
||
@Value("${nacos.cmdb.eventTaskInterval}") | ||
private int eventTaskInterval; | ||
|
||
@Value("${nacos.cmdb.loadDataAtStart}") | ||
private boolean loadDataAtStart; | ||
|
||
public int getDumpTaskInterval() { | ||
return dumpTaskInterval; | ||
} | ||
|
||
public void setDumpTaskInterval(int dumpTaskInterval) { | ||
this.dumpTaskInterval = dumpTaskInterval; | ||
} | ||
|
||
public int getEventTaskInterval() { | ||
return eventTaskInterval; | ||
} | ||
|
||
public void setEventTaskInterval(int eventTaskInterval) { | ||
this.eventTaskInterval = eventTaskInterval; | ||
} | ||
|
||
public boolean isLoadDataAtStart() { | ||
return loadDataAtStart; | ||
} | ||
|
||
public void setLoadDataAtStart(boolean loadDataAtStart) { | ||
this.loadDataAtStart = loadDataAtStart; | ||
} | ||
} |
Oops, something went wrong.