~ubuntu-branches/ubuntu/maverick/eucalyptus/maverick

« back to all changes in this revision

Viewing changes to clc/modules/msgs/src/main/java/com/eucalyptus/configurable/PropertyDirectory.java

  • Committer: Bazaar Package Importer
  • Author(s): Dave Walker (Daviey)
  • Date: 2010-07-21 17:27:10 UTC
  • mfrom: (1.1.38 upstream)
  • Revision ID: james.westby@ubuntu.com-20100721172710-7xv07dmdqgivc3t9
Tags: 2.0~bzr1211-0ubuntu1
* New major upstream version merge, 2.0 (r1211).
* debian/patches/:
  - 01-wsdl-stubs.patch, debian/wsdl.md5sums: wsdl stubs updated.
  - 02-Makefile.patch: Updated to reflect new code layout.
  - 07-local_support_euca_conf-in.patch: Updated to reflect new code layout.
  - 08-ubuntu-default-networking.patch: Refreshed.
  - 09-small-128-192MB.patch: Updated to point to new location.
  - 10-disable-iscsi.patch: Refreshed.
  - 11-state-cleanup-memleakfix.patch: Removed, fixed upstream.
  - 15-fix-default-ramdisk.patch: Updated to point to new location.
  - 16-kvm_libvirt_xml_default_use_kvm.patch: Updated to reflect changes.
  - 17-fix_walrus_OOM_errors.patch: Removed, fixed upstream.
  - 18-priv_security.patch: Updated to reflect upstream changes.
  - 20-brute-force-webui.patch: Updated to reflect upstream changes. 
  - 21-eucalyptus-1.7-with-gwt-1.6.4.patch: New patch, allows 
    eucalyptus-1.7 to be built against gwt 1.6.4. Based on patch courtesy 
    of Dmitrii Zagorodnov, upstream. (LP: #597330)
* debian/eucalyptus-java-common.links: 
  - Changed symlink for groovy, point to groovy.all.jar, making compatiable 
    with groovy versions >1.7. (LP: #595421)
  - Added ant.jar & jetty-rewrite-handler.jar as they are now required.
* debian/control
  - & debian/build-jars: Added libjavassist-java and libjetty-extra-java as 
    build dependencies.
  - Added libjetty-extra-java as a dependency of eucalyptus-java-common
* The binary resulting jar's have been renamed from eucalyptus-*-1.6.2.jar
  to eucalyptus-*-main.jar:    
  - debian/eucalyptus-cc.upstart
  - debian/eucalyptus-cloud.install
  - debian/eucalyptus-common.eucalyptus.upstart
  - debian/eucalyptus-java-common.install
  - debian/eucalyptus-network.upstart
  - debian/eucalyptus-sc.install
  - debian/eucalyptus-walrus.install
* debian/eucalyptus-java-common.install: New upstream jars that have been
  installed:
  - eucalyptus-db-hsqldb-ext-main.jar
  - eucalyptus-component-main.jar
* debian/control:
  - Updated Standards Version to 3.8.4 (no change)
  - Updated the upstream Homepage to: http://open.eucalyptus.com/
  - Changed Vcs-Bzr to reflect new location of Ubuntu hosted development branch.
  - Made the Build Dependency of groovy and the binary eucalyptus-java-common
    package depend on version >=1.7.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
package com.eucalyptus.configurable;
 
2
 
 
3
import java.lang.reflect.Field;
 
4
import java.util.List;
 
5
import java.util.Map;
 
6
import org.apache.log4j.Logger;
 
7
import com.eucalyptus.event.PassiveEventListener;
 
8
import com.google.common.collect.Lists;
 
9
import com.google.common.collect.Maps;
 
10
import com.google.common.collect.Multimap;
 
11
import com.google.common.collect.Multimaps;
 
12
import edu.ucsb.eucalyptus.msgs.ComponentProperty;
 
13
 
 
14
public class PropertyDirectory {
 
15
  private static Logger                                 LOG         = Logger.getLogger( PropertyDirectory.class );
 
16
  private static Map<String, ConfigurableProperty>      fqMap       = Maps.newHashMap( );
 
17
  private static Multimap<String, ConfigurableProperty> fqPrefixMap = Multimaps.newHashMultimap( );
 
18
  private static Map<String, ConfigurableProperty>      fqPendingMap       = Maps.newHashMap( );
 
19
 private static Multimap<String, ConfigurableProperty> fqPendingPrefixMap = Multimaps.newHashMultimap( );
 
20
 
 
21
  private static List<ConfigurablePropertyBuilder>      builders    = Lists.newArrayList( new StaticPropertyEntry.StaticPropertyBuilder( ),
 
22
                                                                                          new SingletonDatabasePropertyEntry.DatabasePropertyBuilder( ),
 
23
                                                                                          new MultiDatabasePropertyEntry.DatabasePropertyBuilder( )); //FIXME: make this dynamic kkthx.
 
24
                                                                                                                                                  
 
25
  public static class NoopEventListener extends PassiveEventListener<ConfigurableProperty> {
 
26
    public static NoopEventListener NOOP = new NoopEventListener( );
 
27
    @Override
 
28
    public void firingEvent( ConfigurableProperty t ) {}
 
29
  }
 
30
  @SuppressWarnings( { "unchecked" } )
 
31
  public static ConfigurableProperty buildPropertyEntry( Class c, Field field ) {
 
32
    for ( ConfigurablePropertyBuilder b : builders ) {
 
33
      try {
 
34
        ConfigurableProperty prop = null;
 
35
        try {
 
36
          prop = b.buildProperty( c, field );
 
37
        } catch ( ConfigurablePropertyException e ) {
 
38
          throw e;
 
39
        } catch ( Throwable t ) {
 
40
          LOG.error( "Failed to prepare configurable field: " + c.getCanonicalName( ) + "." + field.getName( ) );
 
41
          System.exit( 1 );
 
42
        }
 
43
        if ( prop != null ) {
 
44
          ConfigurableClass configurableAnnot = (ConfigurableClass) c.getAnnotation(ConfigurableClass.class);
 
45
          if ( configurableAnnot.deferred() ) {
 
46
                if ( !fqPendingMap.containsKey( prop.getQualifiedName( ) ) ) {
 
47
              fqPendingMap.put( prop.getQualifiedName( ), prop );
 
48
              fqPendingPrefixMap.put( prop.getEntrySetName( ), prop );
 
49
              return prop;
 
50
            }    
 
51
          } else {
 
52
            if ( !fqMap.containsKey( prop.getQualifiedName( ) ) ) {
 
53
              fqMap.put( prop.getQualifiedName( ), prop );
 
54
              fqPrefixMap.put( prop.getEntrySetName( ), prop );
 
55
              return prop;
 
56
            } else {
 
57
              RuntimeException r = new RuntimeException( "Duplicate configurable field in same config file: \n" + "-> "
 
58
                                                       + fqMap.get( prop.getQualifiedName( ) ).getDefiningClass( ).getCanonicalName( ) + "." + field.getName( )
 
59
                                                       + "\n" + "-> " + c.getCanonicalName( ) + "." + field.getName( ) + "\n" );
 
60
              LOG.fatal( r, r );
 
61
              System.exit( 1 );
 
62
              throw r;
 
63
            }
 
64
          }
 
65
        }
 
66
      } catch ( ConfigurablePropertyException e ) {
 
67
        LOG.debug( e, e );
 
68
      }
 
69
    }
 
70
    return null;
 
71
  }
 
72
  
 
73
  public static List<String> getPropertyEntrySetNames( ) {
 
74
    return Lists.newArrayList( fqPrefixMap.keySet( ) );
 
75
  }
 
76
  
 
77
  public static List<ConfigurableProperty> getPropertyEntrySet( ) {
 
78
    List<ConfigurableProperty> props = Lists.newArrayList( );
 
79
    for ( String fqPrefix : fqPrefixMap.keySet( ) ) {
 
80
      props.addAll( getPropertyEntrySet( fqPrefix ) );
 
81
    }
 
82
    return props;
 
83
  }
 
84
  
 
85
  public static List<ConfigurableProperty> getPropertyEntrySet( String prefix ) {
 
86
    List<ConfigurableProperty> props = Lists.newArrayList( );
 
87
    for ( ConfigurableProperty fq : fqPrefixMap.get( prefix ) ) {
 
88
      props.add( fq );
 
89
    }
 
90
    return props;
 
91
  }
 
92
 
 
93
  public static List<ConfigurableProperty> getPropertyEntrySet( String prefix, String alias ) {
 
94
        List<ConfigurableProperty> props = Lists.newArrayList( );
 
95
        for ( ConfigurableProperty fq : fqPrefixMap.get( prefix ) ) {
 
96
        if(fq.getAlias().equals(alias))
 
97
            props.add( fq );
 
98
        }
 
99
        return props;
 
100
  }
 
101
 
 
102
  public static ConfigurableProperty getPropertyEntry( String fq ) throws IllegalAccessException {
 
103
    if ( !fqMap.containsKey( fq ) ) {
 
104
      throw new IllegalAccessException( "No such property: " + fq );
 
105
    } else {
 
106
      return fqMap.get( fq );
 
107
    }
 
108
  }
 
109
  
 
110
  public static List<ConfigurableProperty> getPendingPropertyEntrySet( String prefix ) {
 
111
        List<ConfigurableProperty> props = Lists.newArrayList( );
 
112
        for ( ConfigurableProperty fq : fqPendingPrefixMap.get( prefix ) ) {
 
113
          props.add( fq );
 
114
        }
 
115
        return props;
 
116
  }
 
117
 
 
118
  public static String getEntrySetDescription( String entrySetName ) {
 
119
    return "Temporary description";
 
120
  }
 
121
  
 
122
  public static List<ComponentProperty> getComponentPropertySet( String prefix ) {
 
123
          List<ComponentProperty> componentProps = Lists.newArrayList();
 
124
          List<ConfigurableProperty> props = getPropertyEntrySet( prefix );
 
125
          for (ConfigurableProperty prop : props) {
 
126
                  componentProps.add(new ComponentProperty(prop.getWidgetType().toString(), prop.getDisplayName(), prop.getValue(), prop.getQualifiedName()));
 
127
          }
 
128
          return componentProps;
 
129
  }
 
130
  
 
131
  public static void addProperty(ConfigurableProperty prop) {
 
132
        if ( !fqMap.containsKey( prop.getQualifiedName( ) ) ) {
 
133
          fqMap.put( prop.getQualifiedName( ), prop );
 
134
      fqPrefixMap.put( prop.getEntrySetName( ), prop );
 
135
    }
 
136
  }
 
137
  
 
138
  public static void removeProperty(ConfigurableProperty prop) {
 
139
    if ( fqMap.containsKey( prop.getQualifiedName( ) ) ) {
 
140
      fqMap.remove( prop.getQualifiedName( ) );
 
141
          fqPrefixMap.remove( prop.getEntrySetName( ), prop );
 
142
        }        
 
143
  }
 
144
 
 
145
  public static List<ComponentProperty> getComponentPropertySet(String prefix, String alias) {
 
146
        List<ComponentProperty> componentProps = Lists.newArrayList();
 
147
        List<ConfigurableProperty> props = getPropertyEntrySet( prefix, alias );
 
148
        for (ConfigurableProperty prop : props) {
 
149
         componentProps.add(new ComponentProperty(prop.getWidgetType().toString(), prop.getDisplayName(), prop.getValue(), prop.getQualifiedName()));
 
150
        }
 
151
        return componentProps;
 
152
  }
 
153
}