[teiid-commits] teiid SVN: r883 - trunk/server/src/main/java/com/metamatrix/admin/server.

teiid-commits at lists.jboss.org teiid-commits at lists.jboss.org
Thu May 7 16:53:09 EDT 2009


Author: vhalbert at redhat.com
Date: 2009-05-07 16:53:09 -0400 (Thu, 07 May 2009)
New Revision: 883

Modified:
   trunk/server/src/main/java/com/metamatrix/admin/server/ServerConfigAdminImpl.java
   trunk/server/src/main/java/com/metamatrix/admin/server/ServerMonitoringAdminImpl.java
Log:
JBEDSP-977 - converting importcb to use admin.  The change to ServerConfigAdminImpl broke a test in the case a bad binding name is passed in, fixed that issue too.

Modified: trunk/server/src/main/java/com/metamatrix/admin/server/ServerConfigAdminImpl.java
===================================================================
--- trunk/server/src/main/java/com/metamatrix/admin/server/ServerConfigAdminImpl.java	2009-05-07 20:42:19 UTC (rev 882)
+++ trunk/server/src/main/java/com/metamatrix/admin/server/ServerConfigAdminImpl.java	2009-05-07 20:53:09 UTC (rev 883)
@@ -217,6 +217,9 @@
     }
 
     /**
+     * @param connectorBindingName, is nullable, indicates the name to assign to the importing {@link ConnectorBinding}.  
+     * 	If it is null, then the name defined in the xmlFile will be used.
+     * @param xmlFile is an xml formatted file that defines the connector binding 
      * @see com.metamatrix.admin.api.server.ServerConfigAdmin#addConnectorBinding(java.lang.String, char[], AdminOptions)
      * @since 4.3
      */
@@ -224,71 +227,45 @@
                                     char[] xmlFile, AdminOptions options) throws AdminException {
         com.metamatrix.admin.api.objects.ConnectorBinding newBinding = null;
 
-        if (connectorBindingName == null) {
-            throw new AdminProcessingException(AdminServerPlugin.Util.getString("ServerConfigAdminImpl.Connector_Binding_can_not_be_null")); //$NON-NLS-1$
-        }
         if (xmlFile == null) {
             throw new AdminProcessingException(AdminServerPlugin.Util.getString("ServerConfigAdminImpl.CDK_File_Name_can_not_be_null")); //$NON-NLS-1$
         }
+        
+        // first, read the xmlfile to determine the defined connnector binding name
+        // because majority of the time, the file will determine the name
+        InputStream is = ObjectConverterUtil.convertToInputStream(xmlFile);
+        
+        XMLConfigurationImportExportUtility ciu = new XMLConfigurationImportExportUtility();
+        ConnectorBinding binding = null;
+        try {
+            binding = ciu.importConnectorBinding(is, new BasicConfigurationObjectEditor(false), connectorBindingName);
+        } catch (ConfigObjectsNotResolvableException e) {
+        	throw new AdminComponentException(e);
+        } catch (InvalidConfigurationElementException e) {
+        	throw new AdminComponentException(e);
+        } catch (IOException e) {
+        	throw new AdminComponentException(e);
+        } finally {
+        	if (is != null) {
+        		try {
+					is.close();
+				} catch (IOException e) {
+					// TODO Auto-generated catch block
+					e.printStackTrace();
+				}
+        	}
+        }
 
-        // Check if binding allready exists and look at admin options
-        Collection existingBindings = 
-            parent.getConnectorBindings(AdminObject.WILDCARD + AdminObject.DELIMITER + connectorBindingName);
-        Collection newBindingNames = new ArrayList(1);
-        newBindingNames.add(connectorBindingName);
-        Collection updateBindingNames = getBindingNamesToUpdate(existingBindings, newBindingNames, options);
+        // reassign the name in cases where null was passed in
+        connectorBindingName = binding.getName();
+        
+        return this.addConnectorBinding(connectorBindingName, binding.getComponentTypeID().getFullName(), binding.getProperties(), options);
 
-        if ( updateBindingNames.size() > 0 && updateBindingNames.iterator().next().equals(connectorBindingName) ) {
-            // Add the new binding
-            InputStream is = ObjectConverterUtil.convertToInputStream(xmlFile);
-            
-            XMLConfigurationImportExportUtility ciu = new XMLConfigurationImportExportUtility();
-            ConnectorBinding binding = null;
-            try {
-                binding = ciu.importConnectorBinding(is, new BasicConfigurationObjectEditor(false), connectorBindingName);
-                is.close();
-            } catch (ConfigObjectsNotResolvableException e) {
-            	throw new AdminComponentException(e);
-            } catch (InvalidConfigurationElementException e) {
-            	throw new AdminComponentException(e);
-            } catch (IOException e) {
-            	throw new AdminComponentException(e);
-            }
-            // Check that binding password is decryptable
-            AdminStatus status = checkDecryption(binding);
-            if ( status.getCode() == AdminStatus.CODE_DECRYPTION_FAILED && 
-                            ! options.containsOption(AdminOptions.BINDINGS_IGNORE_DECRYPT_ERROR)) {
-                throw new AdminProcessingException(status.getCode(), status.getMessage());
-            }
-            
-            try {
-                is = ObjectConverterUtil.convertToInputStream(xmlFile);
-                // pass "ALL" to deploy newly created binding to all vms
-                binding = getConfigurationServiceProxy().importConnectorBinding(is, connectorBindingName, "ALL", getUserName());
-                if (binding == null) {
-                    throwProcessingException("ServerConfigAdminImpl.Connector_Type_was_null", new Object[] {connectorBindingName}); //$NON-NLS-1$
-                }
-            } catch (ConfigurationException e) {
-            	throw new AdminComponentException(e);
-            } catch (ServiceException e) {
-            	throw new AdminComponentException(e);
-            }
-        
-            //return the new binding
-            Collection newBindings = 
-                parent.getConnectorBindings(AdminObject.WILDCARD + AdminObject.DELIMITER + connectorBindingName);
-            newBinding = (com.metamatrix.admin.api.objects.ConnectorBinding) newBindings.iterator().next();
-        } else {
-            // We didn't add the new connector binding. Return the existing.
-            if (existingBindings != null && existingBindings.size() > 0) {
-                // Only expecting one existing binding
-                newBinding = (com.metamatrix.admin.api.objects.ConnectorBinding) existingBindings.iterator().next();
-            }
-        }
-        return newBinding;
     }
     
     /**
+     * @param name, is nullable, indicates the name to assign to the connector type
+     * 		If name is null, then the name defined in the cdkFile will be used.
      * @throws MetaMatrixComponentException
      * @throws MetaMatrixProcessingException
      * @see com.metamatrix.admin.api.server.ServerConfigAdmin#addConnectorType(java.lang.String, char[])
@@ -298,15 +275,39 @@
                                  char[] cdkFile) throws AdminException {
         ComponentType connectorType = null;
 
-        if (name == null) {
-            throw new AdminProcessingException(AdminServerPlugin.Util.getString("ServerConfigAdminImpl.Connector_Type_can_not_be_null")); //$NON-NLS-1$
-        }
         if (cdkFile == null) {
             throw new AdminProcessingException(AdminServerPlugin.Util.getString("ServerConfigAdminImpl.CDK_File_Name_can_not_be_null")); //$NON-NLS-1$
         }
-        try {
-            InputStream is = ObjectConverterUtil.convertToInputStream(cdkFile);
 
+        InputStream is = null;
+        if (name == null || name.trim().length() == 0) {
+            is = ObjectConverterUtil.convertToInputStream(cdkFile);
+            
+            XMLConfigurationImportExportUtility ciu = new XMLConfigurationImportExportUtility();
+            try {
+            	connectorType = ciu.importComponentType(is, new BasicConfigurationObjectEditor(false), name);
+                // reassign name in case it was passed in
+                name = connectorType.getFullName();
+            } catch (InvalidConfigurationElementException e) {
+            	throw new AdminComponentException(e);
+            } catch (IOException e) {
+            	throw new AdminComponentException(e);
+            } finally {
+            	if (is != null) {
+            		try {
+    					is.close();
+    				} catch (IOException e) {
+    					// TODO Auto-generated catch block
+    					e.printStackTrace();
+    				}
+            	}
+            }
+        }
+            
+
+       try {           
+            is = ObjectConverterUtil.convertToInputStream(cdkFile);
+        
             connectorType = getConfigurationServiceProxy().importConnectorType(is, name, getUserName());
             if (connectorType == null) {
                 throwProcessingException("ServerConfigAdminImpl.Connector_Type_was_null", new Object[] {name}); //$NON-NLS-1$
@@ -315,7 +316,17 @@
         	throw new AdminComponentException(e);
         } catch (ServiceException e) {
         	throw new AdminComponentException(e);
-        } 
+        } finally {
+            	if (is != null) {
+            		try {
+    					is.close();
+    				} catch (IOException e) {
+    					// TODO Auto-generated catch block
+    					e.printStackTrace();
+    				}
+            	}
+            }
+
     }
 
     /** 
@@ -636,6 +647,8 @@
     }
 
     /**
+     * @param name, is nullable, indicates the name to assign to the vdb
+     * 		If name is null, then use the name defined in the vdbFile.
      * @see com.metamatrix.admin.api.server.ServerConfigAdmin#addVDB(java.lang.String, java.lang.String, byte[], char[])
      * @since 4.3
      */
@@ -643,7 +656,9 @@
         VDBArchive vdb = null;
         try {
 			vdb = new VDBArchive(new ByteArrayInputStream(vdbFile));
-			vdb.setName(name);
+			if (name != null) {
+				vdb.setName(name);
+			}
 		} catch (IOException e) {
 			throw new AdminComponentException(e);
 		}

Modified: trunk/server/src/main/java/com/metamatrix/admin/server/ServerMonitoringAdminImpl.java
===================================================================
--- trunk/server/src/main/java/com/metamatrix/admin/server/ServerMonitoringAdminImpl.java	2009-05-07 20:42:19 UTC (rev 882)
+++ trunk/server/src/main/java/com/metamatrix/admin/server/ServerMonitoringAdminImpl.java	2009-05-07 20:53:09 UTC (rev 883)
@@ -204,19 +204,32 @@
 			            binding.setServiceID(serviceBinding.getServiceID().getID());
 
 			        } else {
+			        	
 					    String[] identifierParts = new String[] {
 						        deployedComponent.getHostID().getName(), 
 						        deployedComponent.getVMComponentDefnID().getName(), 
 						        deployedComponent.getName()
 						    };
-				        String key = MMAdminObject.buildIdentifier(identifierParts).toUpperCase();
+				            
+				        if (identifierMatches(identifier, identifierParts)) {
+				        	
+				            //not in config - create new MMConnectorBinding
+				            binding = new MMConnectorBinding(identifierParts);
+				            binding.setDeployed(false);
+				            binding.setState(MMConnectorBinding.STATE_NOT_DEPLOYED);
 
-			            //not in config - create new MMConnectorBinding
-			            binding = new MMConnectorBinding(identifierParts);
-			            binding.setDeployed(false);
-			            binding.setState(MMConnectorBinding.STATE_NOT_DEPLOYED);
-			            
-			            results.add(binding);
+	
+				            binding.setConnectorTypeName(deployedComponent.getComponentTypeID().getFullName());
+				            binding.setDescription(deployedComponent.getDescription());
+				            binding.setState(serviceBinding.getCurrentState());
+				            binding.setStateChangedTime(serviceBinding.getStateChangeTime());
+				            binding.setRegistered(true);
+				            binding.setServiceID(serviceBinding.getServiceID().getID());
+				            
+				            results.add(binding);
+			        	
+				        }
+			        	
 			        }
 			    }
 			}




More information about the teiid-commits mailing list