Thomas Vachuska
Committed by Gerrit Code Review

Fixed SubjectFactories to support app subject properly.

Change-Id: Ib9de2c0f4af815c54f18954d83f4259089274e91
......@@ -16,6 +16,7 @@
package org.onosproject.incubator.net.config.basics;
import org.onosproject.core.ApplicationId;
import org.onosproject.core.CoreService;
import org.onosproject.incubator.net.config.SubjectFactory;
import org.onosproject.net.ConnectPoint;
import org.onosproject.net.DeviceId;
......@@ -33,12 +34,14 @@ public final class SubjectFactories {
private SubjectFactories() {
}
// Required for resolving application identifiers
private static CoreService coreService;
public static final SubjectFactory<ApplicationId> APP_SUBJECT_FACTORY =
new SubjectFactory<ApplicationId>(ApplicationId.class, "apps") {
@Override
public ApplicationId createSubject(String key) {
// FIXME: figure out how to safely create sanctioned app ids
return null;
return coreService.registerApplication(key);
}
};
......@@ -77,4 +80,14 @@ public final class SubjectFactories {
}
};
/**
* Provides reference to the core service, which is required for
* application subject factory.
*
* @param service core service reference
*/
public static void setCoreService(CoreService service) {
coreService = service;
}
}
......
......@@ -21,12 +21,14 @@ import org.apache.felix.scr.annotations.Component;
import org.apache.felix.scr.annotations.Deactivate;
import org.apache.felix.scr.annotations.Reference;
import org.apache.felix.scr.annotations.ReferenceCardinality;
import org.onosproject.core.CoreService;
import org.onosproject.incubator.net.config.ConfigFactory;
import org.onosproject.incubator.net.config.NetworkConfigRegistry;
import org.onosproject.incubator.net.config.basics.BasicDeviceConfig;
import org.onosproject.incubator.net.config.basics.BasicHostConfig;
import org.onosproject.incubator.net.config.basics.BasicLinkConfig;
import org.onosproject.incubator.net.config.basics.BasicPortConfig;
import org.onosproject.incubator.net.config.basics.SubjectFactories;
import org.onosproject.net.ConnectPoint;
import org.onosproject.net.DeviceId;
import org.onosproject.net.HostId;
......@@ -36,10 +38,7 @@ import org.slf4j.LoggerFactory;
import java.util.Set;
import static org.onosproject.incubator.net.config.basics.SubjectFactories.CONNECT_POINT_SUBJECT_FACTORY;
import static org.onosproject.incubator.net.config.basics.SubjectFactories.DEVICE_SUBJECT_FACTORY;
import static org.onosproject.incubator.net.config.basics.SubjectFactories.HOST_SUBJECT_FACTORY;
import static org.onosproject.incubator.net.config.basics.SubjectFactories.LINK_SUBJECT_FACTORY;
import static org.onosproject.incubator.net.config.basics.SubjectFactories.*;
/**
* Component for registration of builtin basic network configurations.
......@@ -59,8 +58,8 @@ public class BasicNetworkConfigs {
}
},
new ConfigFactory<ConnectPoint, BasicPortConfig>(CONNECT_POINT_SUBJECT_FACTORY,
BasicPortConfig.class,
"basic") {
BasicPortConfig.class,
"basic") {
@Override
public BasicPortConfig createConfig() {
return new BasicPortConfig();
......@@ -85,10 +84,14 @@ public class BasicNetworkConfigs {
);
@Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
protected CoreService coreService;
@Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
protected NetworkConfigRegistry registry;
@Activate
public void activate() {
SubjectFactories.setCoreService(coreService);
factories.forEach(registry::registerConfigFactory);
log.info("Started");
}
......