fix blueprint.xml for ui module server, and unproxy beans from osgi in rest api 120/head
authorAlex Heneveld <alex.heneveld@cloudsoftcorp.com>
Wed, 30 Jan 2019 14:50:38 +0000 (14:50 +0000)
committerAlex Heneveld <alex.heneveld@cloudsoftcorp.com>
Wed, 30 Jan 2019 14:50:38 +0000 (14:50 +0000)
modularity-server/metadata-registry/src/main/resources/OSGI-INF/blueprint/blueprint.xml
modularity-server/module-api/src/main/java/org/apache/brooklyn/ui/modularity/module/api/UiModule.java
modularity-server/module-api/src/main/java/org/apache/brooklyn/ui/modularity/module/api/internal/UiModuleImpl.java
modularity-server/module-registry/src/main/java/org/apache/brooklyn/ui/modularity/module/registry/RestUiModuleRegistry.java
modularity-server/module-registry/src/main/resources/OSGI-INF/blueprint/blueprint.xml

index c838598..3c0293a 100644 (file)
         </cm:default-properties>
     </cm:property-placeholder>
 
+    <reference id="localManagementContext"
+               interface="org.apache.brooklyn.core.mgmt.internal.ManagementContextInternal"/>
+
+    <reference id="shutdownHandler" interface="org.apache.brooklyn.core.mgmt.ShutdownHandler"/>
+
+    <cm:property-placeholder persistent-id="org.apache.brooklyn.rest.filter.cors" placeholder-prefix="$cors{">
+        <!-- since we have properties above for this bundle we need a unique prefix/suffix here -->
+        <cm:default-properties>
+            <cm:property name="cors.enabled" value="true"/>
+            <cm:property name="cors.allow.origins" value=""/>
+            <cm:property name="cors.allow.headers" value=""/>
+            <cm:property name="cors.expose.headers" value=""/>
+            <cm:property name="cors.allow.credentials" value="true"/>
+            <cm:property name="cors.max.age" value="-1"/>
+            <cm:property name="cors.preflight.error.status" value="200"/>
+            <cm:property name="cors.block.if.unauthorized" value="false"/>
+        </cm:default-properties>
+    </cm:property-placeholder>
+    
+    <bean class="org.apache.brooklyn.rest.filter.CorsImplSupplierFilter" id="cors-filter">
+        <property name="enableCors" value="$cors{cors.enabled}"/>
+        <property name="allowOrigins" value="$cors{cors.allow.origins}"/>
+        <property name="allowHeaders" value="$cors{cors.allow.headers}"/>
+        <property name="exposeHeaders" value="$cors{cors.expose.headers}"/>
+        <property name="allowCredentials" value="$cors{cors.allow.credentials}"/>
+        <property name="maxAge" value="$cors{cors.max.age}"/>
+        <property name="preflightErrorStatus" value="$cors{cors.preflight.error.status}"/>
+        <property name="blockCorsIfUnauthorized" value="$cors{cors.block.if.unauthorized}"/>
+    </bean>
+    
     <bean id="registry" class="org.apache.brooklyn.ui.modularity.metadata.registry.impl.UiMetadataRegistryImpl"/>
 
     <service id="uiMetadataRegistryService" ref="registry" interface="org.apache.brooklyn.ui.modularity.metadata.registry.UiMetadataRegistry"/>
index 43bdeb2..e50d75b 100644 (file)
@@ -21,6 +21,8 @@ package org.apache.brooklyn.ui.modularity.module.api;
 import java.util.List;
 import java.util.Set;
 
+import org.apache.brooklyn.ui.modularity.module.api.internal.UiModuleImpl;
+
 public interface UiModule {
     String DEFAULT_ICON = "fa-cogs";
 
@@ -69,4 +71,10 @@ public interface UiModule {
      * @return Registered module actions
      */
     List<UiModuleAction> getActions();
+    
+    public class Utils {
+        public static UiModule copyUiModule(UiModule src) {
+            return UiModuleImpl.copyOf(src);
+        }
+    }
 }
index 845cc8a..7d62fb1 100644 (file)
@@ -41,6 +41,20 @@ public class UiModuleImpl implements UiModule {
     private String path;
     private List<UiModuleAction> actions = new ArrayList<>();
 
+    public static UiModuleImpl copyOf(UiModule src) {
+        final UiModuleImpl result = new UiModuleImpl();
+        result.setId(src.getId());
+        result.setName(src.getName());
+        result.setSlug(src.getSlug());
+        result.setIcon(src.getIcon());
+        if (src.getTypes()!=null) result.types.addAll(src.getTypes());
+        if (src.getSupersedesBundles()!=null) result.supersedesBundles.addAll(src.getSupersedesBundles());
+        result.setStopExisting(src.getStopExisting());
+        result.setPath(src.getPath());
+        if (src.getActions()!=null) result.actions.addAll(src.getActions());
+        return result;
+    }
+    
     public static UiModuleImpl createFromMap(final Map<String, ?> incomingMap) {
         final UiModuleImpl result = new UiModuleImpl();
         result.setId(Optional.fromNullable((String) incomingMap.get("id")).or(UUID.randomUUID().toString()));
index 5aca5b5..86a2350 100644 (file)
  */
 package org.apache.brooklyn.ui.modularity.module.registry;
 
-import com.google.common.base.Function;
-import com.google.common.collect.Ordering;
-import org.apache.brooklyn.ui.modularity.module.api.UiModule;
-import org.apache.brooklyn.ui.modularity.module.api.UiModuleRegistry;
+import java.util.Collection;
 
 import javax.ws.rs.Consumes;
 import javax.ws.rs.GET;
 import javax.ws.rs.Path;
 import javax.ws.rs.Produces;
 import javax.ws.rs.core.MediaType;
-import java.util.Collection;
+
+import org.apache.brooklyn.ui.modularity.module.api.UiModule;
+import org.apache.brooklyn.ui.modularity.module.api.UiModuleRegistry;
+
+import com.google.common.base.Function;
+import com.google.common.collect.Iterables;
+import com.google.common.collect.Ordering;
 
 @Path("/")
 public class RestUiModuleRegistry {
@@ -50,7 +53,9 @@ public class RestUiModuleRegistry {
     public Collection<UiModule> getRegisteredWebComponents() {
         return Ordering.natural()
                 .onResultOf(GET_NAME_FUNCTION)
-                .immutableSortedCopy(uiModuleRegistry.getRegisteredModules());
+                .immutableSortedCopy(
+                    // turn it from a proxy to a serializable bean
+                    Iterables.transform(uiModuleRegistry.getRegisteredModules(), x -> UiModule.Utils.copyUiModule(x)));
     }
 
     public void setUiModuleRegistry(final UiModuleRegistry uiModuleRegistry) {
index fbb24b9..9cd0351 100644 (file)
         </service-properties>
     </service>
 
+    <reference id="localManagementContext"
+               interface="org.apache.brooklyn.core.mgmt.internal.ManagementContextInternal"/>
+
+    <reference id="shutdownHandler" interface="org.apache.brooklyn.core.mgmt.ShutdownHandler"/>
+
+    <cm:property-placeholder persistent-id="org.apache.brooklyn.rest.filter.cors" placeholder-prefix="$cors{">
+        <!-- since we have properties above for this bundle we need a unique prefix/suffix here -->
+        <cm:default-properties>
+            <cm:property name="cors.enabled" value="true"/>
+            <cm:property name="cors.allow.origins" value=""/>
+            <cm:property name="cors.allow.headers" value=""/>
+            <cm:property name="cors.expose.headers" value=""/>
+            <cm:property name="cors.allow.credentials" value="true"/>
+            <cm:property name="cors.max.age" value="-1"/>
+            <cm:property name="cors.preflight.error.status" value="200"/>
+            <cm:property name="cors.block.if.unauthorized" value="false"/>
+        </cm:default-properties>
+    </cm:property-placeholder>
+    
+    <bean class="org.apache.brooklyn.rest.filter.CorsImplSupplierFilter" id="cors-filter">
+        <property name="enableCors" value="$cors{cors.enabled}"/>
+        <property name="allowOrigins" value="$cors{cors.allow.origins}"/>
+        <property name="allowHeaders" value="$cors{cors.allow.headers}"/>
+        <property name="exposeHeaders" value="$cors{cors.expose.headers}"/>
+        <property name="allowCredentials" value="$cors{cors.allow.credentials}"/>
+        <property name="maxAge" value="$cors{cors.max.age}"/>
+        <property name="preflightErrorStatus" value="$cors{cors.preflight.error.status}"/>
+        <property name="blockCorsIfUnauthorized" value="$cors{cors.block.if.unauthorized}"/>
+    </bean>
+
     <bean id="module-registry"
           class="org.apache.brooklyn.ui.modularity.module.registry.UiModuleRegistryImpl"/>
     <reference-list interface="org.apache.brooklyn.ui.modularity.module.api.UiModule" availability="optional">