This repository has been archived by the owner on Apr 5, 2022. It is now read-only.
XD-1036: Composed module deletion #390
Closed
ericbottard
wants to merge
4
commits into
spring-attic:master
from
ericbottard:XD-1036-ComposedDeletion
Closed
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
59 changes: 59 additions & 0 deletions
59
spring-xd-dirt/src/main/java/org/springframework/xd/dirt/module/DependencyException.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,59 @@ | ||
/* | ||
* Copyright 2013 the original author or authors. | ||
* | ||
* 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 org.springframework.xd.dirt.module; | ||
|
||
import java.util.Set; | ||
|
||
import org.springframework.xd.dirt.core.XDRuntimeException; | ||
import org.springframework.xd.module.ModuleType; | ||
|
||
|
||
/** | ||
* Thrown when performing an action cannot be carried over because some dependency would be broken. | ||
* | ||
* @author Eric Bottard | ||
*/ | ||
@SuppressWarnings("serial") | ||
public class /* Module? */DependencyException extends XDRuntimeException { | ||
|
||
private final Set<String> dependents; | ||
|
||
private final String name; | ||
|
||
private final ModuleType type; | ||
|
||
public DependencyException(String message, String name, ModuleType type, Set<String> dependents) { | ||
super(String.format(message, name, type, dependents)); | ||
this.name = name; | ||
this.type = type; | ||
this.dependents = dependents; | ||
} | ||
|
||
public Set<String> getDependents() { | ||
return dependents; | ||
} | ||
|
||
public String getName() { | ||
return name; | ||
} | ||
|
||
public ModuleType getType() { | ||
return type; | ||
} | ||
|
||
|
||
} |
48 changes: 48 additions & 0 deletions
48
...-xd-dirt/src/main/java/org/springframework/xd/dirt/module/ModuleDependencyRepository.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,48 @@ | ||
/* | ||
* Copyright 2013 the original author or authors. | ||
* | ||
* 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 org.springframework.xd.dirt.module; | ||
|
||
import java.util.Set; | ||
|
||
import org.springframework.xd.module.ModuleType; | ||
|
||
|
||
/** | ||
* Used to track usage of modules from streams and composed modules. | ||
* | ||
* @author Eric Bottard | ||
*/ | ||
public interface ModuleDependencyRepository { | ||
|
||
/** | ||
* Store one atomic dependency from a module (composed or not) to some target (stream, or composed module). | ||
*/ | ||
void store(String moduleName, ModuleType type, /* BaseDefinition? */String target); | ||
|
||
/** | ||
* Return the set of things that depend on the given module. | ||
* | ||
* @return a set of Strings of the form {@code type:name}, never {@code null} | ||
*/ | ||
Set</* BaseDefinition? */String> findDependents(String name, ModuleType type); | ||
|
||
/** | ||
* Remove an atomic dependency from a module (composed or not) to some target (stream, or composed module). | ||
*/ | ||
void delete(String module, ModuleType type, /* BaseDefinition? */String target); | ||
|
||
} |
72 changes: 72 additions & 0 deletions
72
spring-xd-dirt/src/main/java/org/springframework/xd/dirt/module/ModuleDependencyTracker.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,72 @@ | ||
/* | ||
* Copyright 2013 the original author or authors. | ||
* | ||
* 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 org.springframework.xd.dirt.module; | ||
|
||
import java.util.Set; | ||
|
||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.xd.module.ModuleType; | ||
|
||
|
||
/** | ||
* Used to compute and track dependencies between modules and other elements of the system. | ||
* | ||
* @author Eric Bottard | ||
*/ | ||
public class ModuleDependencyTracker { | ||
|
||
private final ModuleDependencyRepository dependencyRepository; | ||
|
||
@Autowired | ||
public ModuleDependencyTracker(ModuleDependencyRepository dependencyRepository) { | ||
this.dependencyRepository = dependencyRepository; | ||
} | ||
|
||
public void record(ModuleDeploymentRequest source, String target) { | ||
dependencyRepository.store(source.getModule(), source.getType(), target); | ||
if (source instanceof CompositeModuleDeploymentRequest) { | ||
CompositeModuleDeploymentRequest composed = (CompositeModuleDeploymentRequest) source; | ||
for (ModuleDeploymentRequest child : composed.getChildren()) { | ||
record(child, target); | ||
} | ||
} | ||
} | ||
|
||
|
||
/** | ||
* Return the set of things that depend on the given module. | ||
* | ||
* @return a set of Strings of the form {@code type:name}, never {@code null} | ||
*/ | ||
public Set<String> findDependents(String name, ModuleType type) { | ||
return dependencyRepository.findDependents(name, type); | ||
} | ||
|
||
/** | ||
* @param request | ||
* @param dependencyKey | ||
*/ | ||
public void remove(ModuleDeploymentRequest source, String target) { | ||
dependencyRepository.delete(source.getModule(), source.getType(), target); | ||
if (source instanceof CompositeModuleDeploymentRequest) { | ||
CompositeModuleDeploymentRequest composed = (CompositeModuleDeploymentRequest) source; | ||
for (ModuleDeploymentRequest child : composed.getChildren()) { | ||
remove(child, target); | ||
} | ||
} | ||
} | ||
} |
67 changes: 67 additions & 0 deletions
67
...in/java/org/springframework/xd/dirt/module/memory/InMemoryModuleDependencyRepository.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,67 @@ | ||
/* | ||
* Copyright 2013 the original author or authors. | ||
* | ||
* 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 org.springframework.xd.dirt.module.memory; | ||
|
||
import java.util.HashMap; | ||
import java.util.HashSet; | ||
import java.util.Map; | ||
import java.util.Set; | ||
|
||
import org.springframework.xd.dirt.module.ModuleDependencyRepository; | ||
import org.springframework.xd.module.ModuleType; | ||
|
||
|
||
/** | ||
* In memory implementation of {@link ModuleDependencyRepository}. | ||
* | ||
* @author Eric Bottard | ||
*/ | ||
public class InMemoryModuleDependencyRepository implements ModuleDependencyRepository { | ||
|
||
private Map<String, Set<String>> dependencies = new HashMap<String, Set<String>>() { | ||
|
||
@Override | ||
public Set<String> get(Object key) { | ||
Set<String> result = super.get(key); | ||
if (result == null) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. technically, this allows for a race condition; should probably use a ConcurrentHashMap There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. fixing on merge |
||
result = new HashSet<String>(); | ||
put((String) key, result); | ||
} | ||
return result; | ||
} | ||
}; | ||
|
||
@Override | ||
public void store(String moduleName, ModuleType type, String target) { | ||
dependencies.get(keyFor(moduleName, type)).add(target); | ||
} | ||
|
||
@Override | ||
public void delete(String module, ModuleType type, String target) { | ||
dependencies.get(keyFor(module, type)).remove(target); | ||
} | ||
|
||
@Override | ||
public Set<String> findDependents(String name, ModuleType type) { | ||
return dependencies.get(keyFor(name, type)); | ||
} | ||
|
||
private String keyFor(String moduleName, ModuleType type) { | ||
return type.name() + ":" + moduleName; | ||
} | ||
|
||
} |
62 changes: 62 additions & 0 deletions
62
...c/main/java/org/springframework/xd/dirt/module/redis/RedisModuleDependencyRepository.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,62 @@ | ||
/* | ||
* Copyright 2013 the original author or authors. | ||
* | ||
* 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 org.springframework.xd.dirt.module.redis; | ||
|
||
import java.util.Set; | ||
|
||
import org.springframework.data.redis.core.BoundSetOperations; | ||
import org.springframework.data.redis.core.RedisOperations; | ||
import org.springframework.xd.dirt.module.ModuleDependencyRepository; | ||
import org.springframework.xd.module.ModuleType; | ||
|
||
|
||
/** | ||
* Redis implementation of {@link ModuleDependencyRepository}. Uses sets whose name is of the form | ||
* {@code dependencies.module.<type>:<name>}. | ||
* | ||
* @author Eric Bottard | ||
*/ | ||
public class RedisModuleDependencyRepository implements ModuleDependencyRepository { | ||
|
||
private RedisOperations<String, String> redisOperations; | ||
|
||
public RedisModuleDependencyRepository(RedisOperations<String, String> redisOperations) { | ||
this.redisOperations = redisOperations; | ||
} | ||
|
||
|
||
@Override | ||
public void store(String moduleName, ModuleType type, String target) { | ||
setOpsFor(moduleName, type).add(target); | ||
} | ||
|
||
@Override | ||
public void delete(String module, ModuleType type, String target) { | ||
setOpsFor(module, type).remove(target); | ||
} | ||
|
||
private BoundSetOperations<String, String> setOpsFor(String moduleName, ModuleType type) { | ||
return redisOperations.boundSetOps(String.format("dependencies.module.%s:%s", type.name(), moduleName)); | ||
} | ||
|
||
|
||
@Override | ||
public Set<String> findDependents(String name, ModuleType type) { | ||
return setOpsFor(name, type).members(); | ||
} | ||
|
||
} |
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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if the other methods are "store" and "delete" (no mention of "dependents" since it's understood), shouldn't this one be simply "find"?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
changing "findDependents" to "find" on merge