Thomas Vachuska
Committed by Gerrit Code Review

Sketching out basis for network configuration subsystem API.

Change-Id: I9d56a8392bd300566fb333607102cc965b2fa66e
/*
* Copyright 2015 Open Networking Laboratory
*
* 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.onosproject.exp.net.config;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.node.ObjectNode;
import static com.google.common.base.Preconditions.checkNotNull;
/**
* Base abstraction of a configuration facade for a specific subject. Derived
* classes should keep all state in the specified JSON tree.
*
* @param <S> type of subject
*/
public abstract class Config<S> {
protected ObjectMapper mapper;
protected ObjectNode node;
private S subject;
private ConfigApplyDelegate<S> delegate;
/**
* Returns the specific subject to which this configuration pertains.
*
* @return configuration subject
*/
S subject() {
return subject;
}
/**
* Initializes the configuration behaviour with necessary context.
*
* @param subject configuration subject
* @param node JSON object node where configuration data is stored
* @param mapper JSON object mapper
*/
public void init(S subject, ObjectNode node, ObjectMapper mapper,
ConfigApplyDelegate<S> delegate) {
this.subject = checkNotNull(subject);
this.node = checkNotNull(node);
this.mapper = checkNotNull(mapper);
this.delegate = checkNotNull(delegate);
}
/**
* Applies any configuration changes made via this configuration.
*/
public void apply() {
delegate.onApply(this);
}
}
/*
* Copyright 2015 Open Networking Laboratory
*
* 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.onosproject.exp.net.config;
/**
* Delegate for notification when configuration changes have been applied.
*/
public interface ConfigApplyDelegate<S> {
/**
* Processes changes applied to the specified configuration.
*
* @param config changed configuration
*/
void onApply(Config<S> config);
}
/*
* Copyright 2015 Open Networking Laboratory
*
* 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.onosproject.exp.net.config;
/**
* Base abstract factory for creating configurations for the specified subject type.
*
* @param <S> subject class
*/
public abstract class ConfigFactory<S> {
private final Class<S> subjectClass;
private final String key;
/**
* Creates a new configuration factory for the specified class of subjects
* and bound to the given subject configuration key.
*
* @param subjectClass subject class
* @param key subject configuration key
*/
protected ConfigFactory(Class<S> subjectClass, String key) {
this.subjectClass = subjectClass;
this.key = key;
}
/**
* Returns the class of the subject to which this factory applies.
*
* @return subject type
*/
public Class<S> subjectClass() {
return subjectClass;
}
/**
* Returns the key to which produced configurations should be bound.
*
* @return subject configuration key
*/
public String key() {
return key;
}
/**
* Creates a new but uninitialized configuration. Framework will initialize
* the configuration via {@link Config#init} method.
*
* @return new uninitialized configuration
*/
public abstract Config<S> createConfig();
}
/*
* Copyright 2015 Open Networking Laboratory
*
* 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.onosproject.exp.net.config;
import java.util.Set;
/**
* Service for tracking network configuration factories.
*/
public interface NetworkConfigRegistry {
/**
* Registers the specified configuration factory.
*
* @param configFactory configuration factory
*/
void registerConfigFactory(ConfigFactory configFactory);
/**
* Unregisters the specified configuration factory.
*
* @param configFactory configuration factory
*/
void unregisterConfigFactory(ConfigFactory configFactory);
/**
* Returns set of configuration factories available for the specified
* class of subject.
*
* @param subjectClass subject class
*/
<T> Set<ConfigFactory<T>> getConfigFactories(Class<T> subjectClass);
/**
* Returns the configuration type registered for the specified
* subject type and key.
*
* @param subjectClass subject class
*/
<T> ConfigFactory<T> getConfigFactory(Class<T> subjectClass, String configKey);
/**
* Returns the configuration type registered for the specified
* configuration class.
*
* @param configClass configuration class
*/
<T> ConfigFactory<T> getConfigFactory(Class<Config<T>> configClass);
}
/*
* Copyright 2015 Open Networking Laboratory
*
* 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.onosproject.exp.net.config;
import java.util.Set;
/**
* Service for tracking network configurations which specify how the discovered
* network information should be interpretted and how the network should be
* configured.
*/
public interface NetworkConfigService {
/**
* Returns the set of subjects for which some configuration is available.
*
* @param subjectClass subject class
* @return set of configured subjects
*/
<T> Set<T> getSubjects(Class<T> subjectClass);
/**
* Returns the set of subjects for which the specified configuration is
* available.
*
* @param subjectClass subject class
* @param configClass configuration class
* @return set of configured subjects
*/
<T> Set<T> getSubjects(Class<T> subjectClass, Class<Config<T>> configClass);
/**
* Returns all configurations for the specified subject.
*
* @param subject configuration subject
* @return set of configurations
*/
<T> Set<Config<T>> getConfigs(T subject);
/**
* Returns the configuration for the specified subject and configuration
* class if one is available; null otherwise.
*
* @param subject configuration subject
* @param configClass configuration class
* @return configuration or null if one is not available
*/
<T> Config<T> getConfig(T subject, Class<Config<T>> configClass);
}
/*
* Copyright 2015 Open Networking Laboratory
*
* 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.
*/
/**
* Subsystem for tracking network environment configuration.
*/
package org.onosproject.exp.net.config;
\ No newline at end of file