0001: /*
0002: * BEGIN_HEADER - DO NOT EDIT
0003: *
0004: * The contents of this file are subject to the terms
0005: * of the Common Development and Distribution License
0006: * (the "License"). You may not use this file except
0007: * in compliance with the License.
0008: *
0009: * You can obtain a copy of the license at
0010: * https://open-esb.dev.java.net/public/CDDLv1.0.html.
0011: * See the License for the specific language governing
0012: * permissions and limitations under the License.
0013: *
0014: * When distributing Covered Code, include this CDDL
0015: * HEADER in each file and include the License file at
0016: * https://open-esb.dev.java.net/public/CDDLv1.0.html.
0017: * If applicable add the following below this CDDL HEADER,
0018: * with the fields enclosed by brackets "[]" replaced with
0019: * your own identifying information: Portions Copyright
0020: * [year] [name of copyright owner]
0021: */
0022:
0023: /*
0024: * @(#)RegistryDiff.java
0025: * Copyright 2004-2007 Sun Microsystems, Inc. All Rights Reserved.
0026: *
0027: * END_HEADER - DO NOT EDIT
0028: */
0029: /**
0030: * RegistryDiff.java
0031: *
0032: * SUN PROPRIETARY/CONFIDENTIAL.
0033: * This software is the proprietary information of Sun Microsystems, Inc.
0034: * Use is subject to license terms.
0035: *
0036: *
0037: */package com.sun.jbi.management.registry;
0038:
0039: import com.sun.jbi.ComponentInfo;
0040: import com.sun.jbi.ComponentQuery;
0041: import com.sun.jbi.ComponentType;
0042: import com.sun.jbi.ServiceAssemblyInfo;
0043: import com.sun.jbi.ServiceAssemblyQuery;
0044: import com.sun.jbi.ServiceAssemblyState;
0045: import com.sun.jbi.ServiceUnitInfo;
0046: import com.sun.jbi.ServiceUnitState;
0047: import com.sun.jbi.management.ConfigurationCategory;
0048:
0049: import com.sun.jbi.management.ComponentInfo.Variable;
0050: import com.sun.jbi.management.registry.data.ComponentInfoImpl;
0051: import com.sun.jbi.management.registry.xml.ConfigCategoryType;
0052: import com.sun.jbi.management.registry.xml.PropertyType;
0053: import com.sun.jbi.management.registry.xml.GenericQueryImpl;
0054: import com.sun.jbi.management.registry.data.ServiceAssemblyInfoImpl;
0055: import java.util.HashMap;
0056: import java.util.HashSet;
0057: import java.util.Iterator;
0058: import java.util.LinkedList;
0059: import java.util.List;
0060: import java.util.Map;
0061: import java.util.Properties;
0062: import java.util.Set;
0063:
0064: /**
0065: * This class performs a logical difference between two open registry instances and
0066: * maintains state information about the changes that can be queried afterwards.
0067: *
0068: * @author Sun Microsystems, Inc.
0069: */
0070: public class RegistryDiff {
0071: List<String> mAddComponents;
0072: List<String> mRemoveComponents;
0073: List<String> mReplaceComponents;
0074: List<String> mUpdateComponents;
0075: List<String> mAddSharedLibraries;
0076: List<String> mRemoveSharedLibraries;
0077: List<String> mReplaceSharedLibraries;
0078: List<String> mAddServiceAssemblies;
0079: List<String> mRemoveServiceAssemblies;
0080: List<String> mReplaceServiceAssemblies;
0081: List<String> mAllTargetComponents;
0082: List<String> mAllMasterComponents;
0083: List<String> mComponentsAffectedByChanges;
0084: List<String> mServiceAssembliesAffectedByChanges;
0085: List<String> mChangedLifecycleComponents;
0086: List<String> mChangedLifecycleServiceAssemblies;
0087: List<String> mChangedConfigComponents;
0088: Map<String, ComponentInfo> mMasterSharedLibraries;
0089: Map<String, ComponentInfo> mTargetSharedLibraries;
0090: Map<String, ComponentInfo> mMasterComponents;
0091: Map<String, ComponentInfo> mTargetComponents;
0092: Map<String, ServiceAssemblyInfo> mMasterServiceAssemblies;
0093: Map<String, ServiceAssemblyInfo> mTargetServiceAssemblies;
0094: Map<String, HashMap> mDomainConfigChanges;
0095: Map<String, HashMap> mInstanceConfigChanges;
0096: Map<String, HashMap> mDomainConfigValues;
0097: Map<String, Properties> mComponentProperties;
0098: Map<String, String[]> mRemoveComponentAppVars;
0099: Map<String, Variable[]> mAddComponentAppVars;
0100: Map<String, String> mRemoveComponentConfig;
0101: Map<String, Map<String, Properties>> mAddComponentConfig;
0102: ComponentQuery mMasterQuery;
0103: ComponentQuery mTargetQuery;
0104: ServiceAssemblyQuery mMasterSAQuery;
0105: ServiceAssemblyQuery mTargetSAQuery;
0106: GenericQueryImpl mMasterCQuery;
0107: GenericQueryImpl mTargetCQuery;
0108: String mTarget;
0109: boolean mChanges;
0110:
0111: /**
0112: * Construct a RegistryDiff object using two given registries and the target
0113: * processing entity of interest.
0114: *
0115: * @param master - Registry that is considered to be the reference
0116: * @param target - Registry that is being upgraded to be consistent with the master
0117: * @param targetName - The target processing entity (instance, cluster)
0118: */
0119: public RegistryDiff(Registry master, Registry target,
0120: String targetName) {
0121: mTarget = targetName;
0122: mAddComponents = new LinkedList();
0123: mAddSharedLibraries = new LinkedList();
0124: mAddServiceAssemblies = new LinkedList();
0125: mRemoveComponents = new LinkedList();
0126: mRemoveSharedLibraries = new LinkedList();
0127: mRemoveServiceAssemblies = new LinkedList();
0128: mReplaceComponents = new LinkedList();
0129: mReplaceSharedLibraries = new LinkedList();
0130: mReplaceServiceAssemblies = new LinkedList();
0131: mUpdateComponents = new LinkedList();
0132: mAllTargetComponents = new LinkedList();
0133: mAllMasterComponents = new LinkedList();
0134: mComponentsAffectedByChanges = new LinkedList();
0135: mServiceAssembliesAffectedByChanges = new LinkedList();
0136: mChangedLifecycleComponents = new LinkedList();
0137: mChangedLifecycleServiceAssemblies = new LinkedList();
0138: mChangedConfigComponents = new LinkedList();
0139: mMasterComponents = new HashMap();
0140: mTargetComponents = new HashMap();
0141: mMasterSharedLibraries = new HashMap();
0142: mTargetSharedLibraries = new HashMap();
0143: mMasterServiceAssemblies = new HashMap();
0144: mTargetServiceAssemblies = new HashMap();
0145: mDomainConfigChanges = new HashMap();
0146: mInstanceConfigChanges = new HashMap();
0147: mDomainConfigValues = new HashMap();
0148: mComponentProperties = new HashMap();
0149: mRemoveComponentAppVars = new HashMap();
0150: mAddComponentAppVars = new HashMap();
0151: mAddComponentConfig = new HashMap();
0152: mRemoveComponentConfig = new HashMap();
0153: mChanges = false;
0154: try {
0155: mMasterQuery = master.getComponentQuery(targetName);
0156: mTargetQuery = target.getComponentQuery(targetName);
0157: mMasterSAQuery = master.getServiceAssemblyQuery(targetName);
0158: mTargetSAQuery = target.getServiceAssemblyQuery(targetName);
0159: mMasterCQuery = (GenericQueryImpl) master.getGenericQuery();
0160: mTargetCQuery = (GenericQueryImpl) target.getGenericQuery();
0161: } catch (RegistryException reX) {
0162:
0163: }
0164: }
0165:
0166: /**
0167: * Perform the actual difference computation.
0168: * @return indication if a difference was detected.
0169: */
0170: public boolean computeDiff() {
0171: //
0172: // Compute the differences between the master and the current for each of the entities.
0173: //
0174: diffSharedLibraries();
0175: diffComponents();
0176: diffServiceAssemblies();
0177: diffConfigs();
0178: diffComponentProperties();
0179: diffComponentAppVars();
0180: diffComponentConfigs();
0181:
0182: //
0183: // Analyze the differences. Basically tries to limit the work to be performed.
0184: //
0185: analyzeSharedLibraries();
0186: analyzeComponents();
0187: analyzeServiceAssemblies();
0188: analyzeConfigs();
0189: analyzeComponentConfig();
0190: return (mChanges);
0191: }
0192:
0193: /**
0194: * Compute differences in the components.
0195: */
0196: void diffComponents() {
0197: List<String> masterIds;
0198: List<String> targetIds;
0199:
0200: masterIds = mMasterQuery
0201: .getComponentIds(ComponentType.BINDINGS_AND_ENGINES);
0202: targetIds = mTargetQuery
0203: .getComponentIds(ComponentType.BINDINGS_AND_ENGINES);
0204: mAllMasterComponents = masterIds;
0205: mAllTargetComponents = targetIds;
0206:
0207: for (String component : masterIds) {
0208: if (!targetIds.contains(component)) {
0209: mAddComponents.add(component);
0210: mChanges = true;
0211: } else {
0212: mReplaceComponents.add(component);
0213: }
0214: }
0215: for (String component : targetIds) {
0216: if (!masterIds.contains(component)) {
0217: mRemoveComponents.add(component);
0218: mChanges = true;
0219: }
0220: }
0221: }
0222:
0223: /**
0224: * Compute differences in the shared libraries
0225: */
0226: void diffSharedLibraries() {
0227: List<String> masterIds;
0228: List<String> targetIds;
0229:
0230: masterIds = mMasterQuery
0231: .getComponentIds(ComponentType.SHARED_LIBRARY);
0232: targetIds = mTargetQuery
0233: .getComponentIds(ComponentType.SHARED_LIBRARY);
0234:
0235: for (String component : masterIds) {
0236: if (!targetIds.contains(component)) {
0237: mAddSharedLibraries.add(component);
0238: mChanges = true;
0239: } else {
0240: mReplaceSharedLibraries.add(component);
0241: }
0242: }
0243: for (String component : targetIds) {
0244: if (!masterIds.contains(component)) {
0245: mRemoveSharedLibraries.add(component);
0246: mChanges = true;
0247: }
0248: }
0249: }
0250:
0251: /**
0252: * Compute differences in the service assemblies.
0253: */
0254: void diffServiceAssemblies() {
0255: List<String> masterIds;
0256: List<String> targetIds;
0257:
0258: masterIds = mMasterSAQuery.getServiceAssemblies();
0259: targetIds = mTargetSAQuery.getServiceAssemblies();
0260:
0261: for (String component : masterIds) {
0262: if (!targetIds.contains(component)) {
0263: mAddServiceAssemblies.add(component);
0264: mChanges = true;
0265: } else {
0266: mReplaceServiceAssemblies.add(component);
0267: }
0268: }
0269: for (String component : targetIds) {
0270: if (!masterIds.contains(component)) {
0271: mRemoveServiceAssemblies.add(component);
0272: mChanges = true;
0273: }
0274: }
0275: }
0276:
0277: /**
0278: * Compute differences in the configs
0279: */
0280: void diffConfigs() {
0281: getConfigForCategory("domain",
0282: ConfigurationCategory.Deployment, mDomainConfigChanges,
0283: mDomainConfigValues);
0284: getConfigForCategory("domain",
0285: ConfigurationCategory.Installation,
0286: mDomainConfigChanges, mDomainConfigValues);
0287: getConfigForCategory("domain", ConfigurationCategory.System,
0288: mDomainConfigChanges, mDomainConfigValues);
0289: // getConfigForCategory("domain", ConfigurationCategory.Logger, mDomainConfigChanges, mDomainConfigValues);
0290: if (mDomainConfigChanges.size() != 0) {
0291: mChanges = true;
0292: }
0293: getConfigForCategory(mTarget, ConfigurationCategory.Deployment,
0294: mInstanceConfigChanges, null);
0295: getConfigForCategory(mTarget,
0296: ConfigurationCategory.Installation,
0297: mInstanceConfigChanges, null);
0298: getConfigForCategory(mTarget, ConfigurationCategory.System,
0299: mInstanceConfigChanges, null);
0300: // getConfigForCategory(mTarget, ConfigurationCategory.Logger, mInstanceConfigChanges, null);
0301: if (mInstanceConfigChanges.size() != 0) {
0302: mChanges = true;
0303: }
0304: }
0305:
0306: void diffComponentProperties() {
0307: List<String> masterIds;
0308:
0309: masterIds = mMasterQuery
0310: .getComponentIds(ComponentType.BINDINGS_AND_ENGINES);
0311: for (String component : masterIds) {
0312: ComponentInfoImpl master = (ComponentInfoImpl) mMasterQuery
0313: .getComponentInfo(component);
0314: ComponentInfoImpl target = (ComponentInfoImpl) mTargetQuery
0315: .getComponentInfo(component);
0316: Properties mProps = master.getConfiguration();
0317: Properties tProps = null;
0318: Properties props = new Properties();
0319:
0320: if (target != null) {
0321: tProps = target.getConfiguration();
0322: }
0323: for (Object mProp : mProps.keySet()) {
0324: if (tProps != null
0325: && tProps.getProperty((String) mProp) != null) {
0326: String mValue = mProps.getProperty((String) mProp);
0327: String tValue = tProps.getProperty((String) mProp);
0328:
0329: if (mValue != null && tValue != null
0330: && mValue.equals(tValue)) {
0331: continue;
0332: }
0333: }
0334: props.setProperty((String) mProp, mProps
0335: .getProperty((String) mProp));
0336: }
0337: if (props.size() != 0) {
0338: mComponentProperties.put(component, props);
0339: mChanges = true;
0340: }
0341: }
0342: }
0343:
0344: void diffComponentAppVars() {
0345: List<String> masterIds;
0346:
0347: masterIds = mMasterQuery
0348: .getComponentIds(ComponentType.BINDINGS_AND_ENGINES);
0349: for (String component : masterIds) {
0350: ComponentInfoImpl master = (ComponentInfoImpl) mMasterQuery
0351: .getComponentInfo(component);
0352: ComponentInfoImpl target = (ComponentInfoImpl) mTargetQuery
0353: .getComponentInfo(component);
0354: Variable mVars[] = master.getVariables();
0355: Variable tVars[] = null;
0356: boolean same = false;
0357: boolean found;
0358:
0359: if (target != null) {
0360: tVars = target.getVariables();
0361:
0362: //
0363: // Check if they are the same.
0364: //
0365: if (tVars.length == mVars.length) {
0366: if (tVars.length == 0) {
0367: continue;
0368: }
0369: for (int i = 0; i < tVars.length; i++) {
0370: found = false;
0371: same = true;
0372: for (int j = 0; j < mVars.length; j++) {
0373: if (mVars[j].getName() == tVars[i]
0374: .getName()) {
0375: found = true;
0376: if (mVars[j].getType().equals(
0377: tVars[i].getType())
0378: && mVars[j].getValue().equals(
0379: tVars[i].getValue())) {
0380: continue;
0381: }
0382: same = false;
0383: break;
0384: }
0385: }
0386: if (!found) {
0387: same = false;
0388: }
0389: if (!same) {
0390: break;
0391: }
0392: }
0393: }
0394: }
0395:
0396: //
0397: // Remember target names for delete and values for insert.
0398: //
0399: if (!same) {
0400: if (target != null) {
0401: String[] vars = new String[tVars.length];
0402: for (int i = 0; i < tVars.length; i++) {
0403: vars[i] = tVars[i].getName();
0404: }
0405: mRemoveComponentAppVars.put(component, vars);
0406: mChanges = true;
0407: }
0408: if (mVars.length > 0) {
0409: mAddComponentAppVars.put(component, mVars);
0410: mChanges = true;
0411: }
0412: }
0413: }
0414: }
0415:
0416: /**
0417: * Compute the actions needed to sync the config configuration changes. We don't try and
0418: * compute the changes at the configuration value level. If the configuration is different
0419: * in any way we just delete the old configuration and apply the new one. This is most likely
0420: * faster since each configuration operation is a registry commit.
0421: * meaning that it should be deleted.
0422: */
0423: void diffComponentConfigs() {
0424: List<String> masterIds;
0425:
0426: masterIds = mMasterQuery
0427: .getComponentIds(ComponentType.BINDINGS_AND_ENGINES);
0428: for (String component : masterIds) {
0429: ComponentInfoImpl master = (ComponentInfoImpl) mMasterQuery
0430: .getComponentInfo(component);
0431: ComponentInfoImpl target = (ComponentInfoImpl) mTargetQuery
0432: .getComponentInfo(component);
0433: String mNames[] = master.getApplicationConfigurationNames();
0434: HashSet<String> tNames = new HashSet();
0435:
0436: if (target != null) {
0437: String n[] = target.getApplicationConfigurationNames();
0438:
0439: for (int i = 0; i < n.length; i++) {
0440: tNames.add(n[i]);
0441: }
0442: }
0443: if (mNames.length > 0) {
0444: HashMap<String, Properties> result = new HashMap();
0445:
0446: for (int i = 0; i < mNames.length; i++) {
0447: Properties mProps = master
0448: .getApplicationConfiguration(mNames[i]);
0449: ;
0450:
0451: if (tNames.remove(mNames[i])) {
0452: Properties tProps = target
0453: .getApplicationConfiguration(mNames[i]);
0454:
0455: if (mProps.size() == tProps.size()) {
0456: boolean same = true;
0457:
0458: for (Object prop : mProps.keySet()) {
0459: String mValue = mProps
0460: .getProperty((String) prop);
0461: String tValue = tProps
0462: .getProperty((String) prop);
0463:
0464: if (mValue != null && tValue != null
0465: && mValue.equals(tValue)) {
0466: continue;
0467: }
0468: same = false;
0469: break;
0470: }
0471: if (same) {
0472: continue;
0473: }
0474: }
0475: mRemoveComponentConfig
0476: .put(component, mNames[i]);
0477: }
0478: mChanges = true;
0479: result.put(mNames[i], mProps);
0480: }
0481: if (!result.isEmpty()) {
0482: mAddComponentConfig.put(component, result);
0483: }
0484: }
0485: if (!tNames.isEmpty()) {
0486: mChanges = true;
0487: for (String cName : tNames) {
0488: mRemoveComponentConfig.put(component, cName);
0489: }
0490: }
0491: }
0492: }
0493:
0494: /**
0495: * Compute the actions needed to sync the config changes. In this case we
0496: * create a map with the (name, value) pairs for the change with a value==null
0497: * meaning that it should be deleted.
0498: */
0499: private void getConfigForCategory(String target,
0500: ConfigurationCategory cc, Map<String, HashMap> map,
0501: Map<String, HashMap> valueMap) {
0502: ConfigCategoryType mcct = mMasterCQuery.getConfigCategory(
0503: target, cc);
0504: ConfigCategoryType tcct = mTargetCQuery.getConfigCategory(
0505: target, cc);
0506: List<PropertyType> mprop = null;
0507: List<PropertyType> tprop = null;
0508: HashMap<String, String> changes = new HashMap();
0509: HashMap<String, String> values = new HashMap();
0510:
0511: if (mcct != null) {
0512: mprop = mcct.getProperty();
0513: }
0514: if (tcct != null) {
0515: (tprop = new LinkedList()).addAll(tcct.getProperty());
0516: }
0517: if (mprop != null) {
0518: for (PropertyType mp : mprop) {
0519: String name = mp.getName();
0520: String value = mp.getValue();
0521: PropertyType match = null;
0522:
0523: values.put(name, value);
0524: if (tprop != null) {
0525: for (Iterator<PropertyType> i = tprop.iterator(); i
0526: .hasNext();) {
0527: PropertyType tp = i.next();
0528: if (tp.getName().equals(name)) {
0529: if (value.equals(tp.getValue())) {
0530: i.remove();
0531: match = tp;
0532: }
0533: break;
0534: }
0535: }
0536: }
0537: if (match == null) {
0538: changes.put(name, value);
0539: }
0540: }
0541: }
0542: if (tprop != null) {
0543: for (PropertyType tp : tprop) {
0544: changes.put(tp.getName(), null);
0545: }
0546: }
0547: map.put(cc.name(), changes);
0548:
0549: //
0550: // Save the values by category if requested.
0551: //
0552: if (valueMap != null) {
0553: valueMap.put(cc.name(), values);
0554: }
0555: }
0556:
0557: /**
0558: * Analyze SharedLibraries to determine if a library has been replaced.
0559: * Also collect ComponentInfo for future use.
0560: */
0561: void analyzeSharedLibraries() {
0562: List<String> noChange = new LinkedList();
0563:
0564: //
0565: // Load ComponentInfo from the appropriate registry.
0566: //
0567: for (String component : mAddSharedLibraries) {
0568: ComponentInfo master = mMasterQuery
0569: .getSharedLibraryInfo(component);
0570:
0571: mMasterSharedLibraries.put(component, master);
0572: }
0573: for (String component : mRemoveSharedLibraries) {
0574: ComponentInfo target = mTargetQuery
0575: .getSharedLibraryInfo(component);
0576:
0577: mTargetSharedLibraries.put(component, target);
0578: }
0579: for (String component : mReplaceSharedLibraries) {
0580: ComponentInfo master = mMasterQuery
0581: .getSharedLibraryInfo(component);
0582: ComponentInfo target = mTargetQuery
0583: .getSharedLibraryInfo(component);
0584:
0585: //
0586: // If the timestamp of the archive is identical there is nothing to do.
0587: //
0588: mMasterSharedLibraries.put(component, master);
0589: mTargetSharedLibraries.put(component, target);
0590: if (((ComponentInfoImpl) master).getTimestamp() == ((ComponentInfoImpl) target)
0591: .getTimestamp()) {
0592: noChange.add(component);
0593: continue;
0594: }
0595: mChanges = true;
0596: }
0597:
0598: //
0599: // Make any deferred changes to the replace set.
0600: //
0601: mReplaceSharedLibraries.removeAll(noChange);
0602: }
0603:
0604: /**
0605: * Analyze Components to determine if a component has been replaced.
0606: * Also collect ComponentInfo for future use.
0607: */
0608: void analyzeComponents() {
0609: List<String> noChange = new LinkedList();
0610:
0611: for (String component : mAddComponents) {
0612: ComponentInfo master = mMasterQuery
0613: .getComponentInfo(component);
0614:
0615: mMasterComponents.put(component, master);
0616: }
0617: for (String component : mRemoveComponents) {
0618: ComponentInfo target = mTargetQuery
0619: .getComponentInfo(component);
0620:
0621: mTargetComponents.put(component, target);
0622: }
0623: for (String component : mReplaceComponents) {
0624: ComponentInfo master = mMasterQuery
0625: .getComponentInfo(component);
0626: ComponentInfo target = mTargetQuery
0627: .getComponentInfo(component);
0628:
0629: //
0630: // If the timestamp of the archive is identical then check for lifecycle changes
0631: //
0632: mMasterComponents.put(component, master);
0633: mTargetComponents.put(component, target);
0634: if (((ComponentInfoImpl) master).getTimestamp() == ((ComponentInfoImpl) target)
0635: .getTimestamp()) {
0636: noChange.add(component);
0637:
0638: if (((ComponentInfoImpl) master).getUpgradeNumber() != ((ComponentInfoImpl) target)
0639: .getUpgradeNumber()) {
0640: mUpdateComponents.add(component);
0641: continue;
0642: }
0643:
0644: //
0645: // If the lifecycle is the same than we are done. Otherwise note that we need
0646: // to correct the lifecycle state of this component.
0647: //
0648: if (master.getStatus().equals(target.getStatus())) {
0649: continue;
0650: }
0651: mChangedLifecycleComponents.add(component);
0652: }
0653: mChanges = true;
0654: }
0655:
0656: //
0657: // Make any deferred changes to the replace set.
0658: //
0659: mReplaceComponents.removeAll(noChange);
0660:
0661: //
0662: // Compute set of components using replaced shared libraries.
0663: //
0664: for (String component : mAllTargetComponents) {
0665: ComponentInfo comp = mTargetComponents.get(component);
0666:
0667: for (String sl : comp.getSharedLibraryNames()) {
0668: if (mReplaceSharedLibraries.contains(sl)) {
0669: if (!mComponentsAffectedByChanges
0670: .contains(component)) {
0671: mComponentsAffectedByChanges.add(component);
0672: }
0673: }
0674: }
0675: }
0676: }
0677:
0678: /**
0679: * Analyze ServiceAssemblies to determine if a service assembly has been replaced.
0680: * Compute the set of service assemblies that may be effected by components/shared-libraries
0681: * that have been replaced. Also collect ServiceAssemblyInfo for future use.
0682: */
0683: void analyzeServiceAssemblies() {
0684: List<String> noChange = new LinkedList();
0685:
0686: for (String sa : mAddServiceAssemblies) {
0687: ServiceAssemblyInfo master = mMasterSAQuery
0688: .getServiceAssemblyInfo(sa);
0689:
0690: mMasterServiceAssemblies.put(sa, master);
0691: }
0692: for (String sa : mRemoveServiceAssemblies) {
0693: ServiceAssemblyInfo target = mTargetSAQuery
0694: .getServiceAssemblyInfo(sa);
0695:
0696: mTargetServiceAssemblies.put(sa, target);
0697: }
0698: for (String assembly : mReplaceServiceAssemblies) {
0699: ServiceAssemblyInfo master = mMasterSAQuery
0700: .getServiceAssemblyInfo(assembly);
0701: ServiceAssemblyInfo target = mTargetSAQuery
0702: .getServiceAssemblyInfo(assembly);
0703:
0704: //
0705: // If the timestamp of the archive is identical there is nothing to do.
0706: //
0707: mMasterServiceAssemblies.put(assembly, master);
0708: mTargetServiceAssemblies.put(assembly, target);
0709: if (((ServiceAssemblyInfoImpl) master).getTimestamp() == ((ServiceAssemblyInfoImpl) target)
0710: .getTimestamp()) {
0711: noChange.add(assembly);
0712:
0713: //
0714: // If the lifecycle is the same than we are done. Otherwise note that we need
0715: // to correct the lifecycle state of this service assembly.
0716: //
0717: if (master.getStatus().equals(target.getStatus())) {
0718: continue;
0719: }
0720: mChangedLifecycleServiceAssemblies.add(assembly);
0721: }
0722: mChanges = true;
0723: }
0724:
0725: //
0726: // Make any deferred changes to the replace set.
0727: //
0728: mReplaceServiceAssemblies.removeAll(noChange);
0729:
0730: //
0731: // Compute set of service assemblies referenced by replaced components/shared-libraries.
0732: //
0733: List<String> comps = new LinkedList();
0734: comps.addAll(mReplaceComponents);
0735: comps.addAll(mComponentsAffectedByChanges);
0736:
0737: for (String compName : comps) {
0738: ComponentInfo comp = mTargetComponents.get(compName);
0739:
0740: for (ServiceUnitInfo sui : comp.getServiceUnitList()) {
0741: if (!mServiceAssembliesAffectedByChanges.contains(sui
0742: .getServiceAssemblyName())) {
0743: mServiceAssembliesAffectedByChanges.add(sui
0744: .getServiceAssemblyName());
0745: }
0746: }
0747: }
0748:
0749: }
0750:
0751: /**
0752: * Analyze Config changes. The one special case is a delete of a instance value is
0753: * replayed as a setting of the instance value to the global value.
0754: */
0755: void analyzeConfigs() {
0756: for (Map.Entry<String, HashMap> m : mInstanceConfigChanges
0757: .entrySet()) {
0758: String category = m.getKey();
0759: Map<String, String> props = m.getValue();
0760: for (Map.Entry<String, String> p : props.entrySet()) {
0761: if (p.getValue() == null) {
0762: p.setValue((String) mDomainConfigValues.get(
0763: category).get(p.getKey()));
0764: }
0765: }
0766: }
0767: }
0768:
0769: /**
0770: * Compute the components that need to be started to make configuration changes.
0771: */
0772: void analyzeComponentConfig() {
0773: for (String comp : mAddComponentAppVars.keySet()) {
0774: if (!mChangedConfigComponents.contains(comp)) {
0775: mChangedConfigComponents.add(comp);
0776: }
0777: }
0778: for (String comp : mRemoveComponentAppVars.keySet()) {
0779: if (!mChangedConfigComponents.contains(comp)) {
0780: mChangedConfigComponents.add(comp);
0781: }
0782: }
0783: for (String comp : mAddComponentConfig.keySet()) {
0784: if (!mChangedConfigComponents.contains(comp)) {
0785: mChangedConfigComponents.add(comp);
0786: }
0787: }
0788: for (String comp : mRemoveComponentConfig.keySet()) {
0789: if (!mChangedConfigComponents.contains(comp)) {
0790: mChangedConfigComponents.add(comp);
0791: }
0792: }
0793: for (String comp : mComponentProperties.keySet()) {
0794: if (!mChangedConfigComponents.contains(comp)) {
0795: mChangedConfigComponents.add(comp);
0796: }
0797: }
0798:
0799: }
0800:
0801: /**
0802: * Compute the set of components that need to be started so that a undeploy service assembly
0803: * operation can execute.
0804: * @return List of components name that need to be started.
0805: */
0806: public List<String> componentsToStartForUndeploy() {
0807: List<String> componentsToStart = new LinkedList();
0808:
0809: //
0810: // Find all old components with service units that reference removed or replaced
0811: // service assemblies.
0812: //
0813: for (String component : mAllTargetComponents) {
0814: ComponentInfo comp = mTargetComponents.get(component);
0815:
0816: for (ServiceUnitInfo su : comp.getServiceUnitList()) {
0817: if (mRemoveServiceAssemblies.contains(su
0818: .getServiceAssemblyName())
0819: || mReplaceServiceAssemblies.contains(su
0820: .getServiceAssemblyName())
0821: || mServiceAssembliesAffectedByChanges
0822: .contains(su.getServiceAssemblyName())) {
0823: componentsToStart.add(component);
0824: break;
0825: }
0826: }
0827: }
0828: return (componentsToStart);
0829: }
0830:
0831: /**
0832: * Compute the set of components that need to be started so that a deploy service assembly
0833: * operation can execute.
0834: * @return List of components name that need to be started.
0835: */
0836: public List<String> componentsToStartForDeploy() {
0837: List<String> componentsToStart = new LinkedList();
0838:
0839: //
0840: // Find all components with service units that reference the new service assemblies.
0841: //
0842: for (String component : mAllMasterComponents) {
0843: ComponentInfo comp = mMasterComponents.get(component);
0844:
0845: for (ServiceUnitInfo su : comp.getServiceUnitList()) {
0846: if (mAddServiceAssemblies.contains(su
0847: .getServiceAssemblyName())) {
0848: componentsToStart.add(component);
0849: break;
0850: }
0851: }
0852: }
0853:
0854: return (componentsToStart);
0855: }
0856:
0857: /**
0858: * Compute the state of a new service assembly (exists in master) from the state of the service units.
0859: * @param saName - name of the service assembly
0860: * @return service assembly state
0861: */
0862: public ServiceAssemblyState getNewServiceAssemblyState(String saName) {
0863: List<String> componentsToStart = new LinkedList();
0864: List<ServiceUnitState> suStates = new LinkedList();
0865:
0866: //
0867: // Find all components with service units that reference the new service assemblies.
0868: //
0869: for (String component : mAllMasterComponents) {
0870: ComponentInfo comp = mMasterComponents.get(component);
0871:
0872: for (ServiceUnitInfo su : comp.getServiceUnitList()) {
0873: if (su.getServiceAssemblyName().equals(saName)) {
0874: suStates.add(su.getState());
0875: break;
0876: }
0877: }
0878: }
0879:
0880: return (ServiceAssemblyState
0881: .computeServiceAssemblyState(suStates));
0882: }
0883:
0884: /**
0885: * Get the list of new shared libraries in the master.
0886: * @return List of shared library names.
0887: */
0888: public List<String> getNewSharedLibraries() {
0889: return (mAddSharedLibraries);
0890: }
0891:
0892: /**
0893: * Get ComponentInfo about a new SharedLibrary
0894: * @parm slName - name of shared library in master
0895: * @return ComponentInfo for the given shared library.
0896: */
0897: public ComponentInfo getNewSharedLibraryInfo(String slName) {
0898: return (mMasterSharedLibraries.get(slName));
0899: }
0900:
0901: /**
0902: * Get the list of old shared libraries in the target.
0903: * @return List of shared library names.
0904: */
0905: public List<String> getOldSharedLibraries() {
0906: return (mRemoveSharedLibraries);
0907: }
0908:
0909: /**
0910: * Get the list of replaced shared libraries in the target.
0911: * @return List of shared library names.
0912: */
0913: public List<String> getReplacedSharedLibraries() {
0914: return (mReplaceSharedLibraries);
0915: }
0916:
0917: /**
0918: * Get the list of replaced service assemblies in the target.
0919: * @return List of shared library names.
0920: */
0921: public List<String> getReplacedServiceAssemblies() {
0922: return (mReplaceServiceAssemblies);
0923: }
0924:
0925: /**
0926: * Get the list of new components in the master.
0927: * @return List of component names.
0928: */
0929: public List<String> getNewComponents() {
0930: return (mAddComponents);
0931: }
0932:
0933: /**
0934: * Get ComponentInfo about a new Component
0935: * @parm slName - name of component in master
0936: * @return ComponentInfo for the given component
0937: */
0938: public ComponentInfo getNewComponentInfo(String compName) {
0939: return (mMasterComponents.get(compName));
0940: }
0941:
0942: /**
0943: * Get the list of old components in the target.
0944: * @return List of component names.
0945: */
0946: public List<String> getOldComponents() {
0947: return (mRemoveComponents);
0948: }
0949:
0950: /**
0951: * Get the list of components affected by other changes. This typically
0952: * means a dependent shared libaray has changed.
0953: * @return List of components names.\
0954: */
0955: public List<String> getAffectedComponents() {
0956: return (mComponentsAffectedByChanges);
0957: }
0958:
0959: /**
0960: * Get the list of updated components
0961: * @return List of components names.
0962: */
0963: public List<String> getUpdatedComponents() {
0964: return (mUpdateComponents);
0965: }
0966:
0967: /**
0968: * Get the list of replaced components
0969: * @return List of components names.
0970: */
0971: public List<String> getReplacedComponents() {
0972: return (mReplaceComponents);
0973: }
0974:
0975: /**
0976: * Get the list of components with lifecycle changes.
0977: * @return List of components names.\
0978: */
0979: public List<String> getChangedLifeCycleComponents() {
0980: return (mChangedLifecycleComponents);
0981: }
0982:
0983: /**
0984: * Get ServiceAssemblyInfo about a new ServiceAssembly
0985: * @parm saName - name of service assmebly in master
0986: * @return ComponentInfo for the given service assembly
0987: */
0988: public ServiceAssemblyInfo getNewServiceAssemblyInfo(String saName) {
0989: return (mMasterServiceAssemblies.get(saName));
0990: }
0991:
0992: /**
0993: * Get the list of new service assemblies in the master.
0994: * @return List of service assemblies names.
0995: */
0996: public List<String> getNewServiceAssemblies() {
0997: return (mAddServiceAssemblies);
0998: }
0999:
1000: /**
1001: * Get the list of old service assemblies in the target.
1002: * @return List of service assemblies names.
1003: */
1004: public List<String> getOldServiceAssemblies() {
1005: return (mRemoveServiceAssemblies);
1006: }
1007:
1008: /**
1009: * Get the list of service assemblies affected by other changes. This typically
1010: * means a dependent component has changed.
1011: * @return List of service assembly names.
1012: */
1013: public List<String> getAffectedServiceAssemblies() {
1014: return (mServiceAssembliesAffectedByChanges);
1015: }
1016:
1017: /**
1018: * Get the list of service assemblies with lifecycle changes.
1019: * @return List of service assembly names.
1020: */
1021: public List<String> getChangedLifeCycleServiceAssemblies() {
1022: return (mChangedLifecycleServiceAssemblies);
1023: }
1024:
1025: public Map<String, String> getGlobalConfigChanges(String category) {
1026: return (mDomainConfigChanges.get(category));
1027: }
1028:
1029: public Map<String, String> getConfigChanges(String category) {
1030: return (mInstanceConfigChanges.get(category));
1031: }
1032:
1033: public List<String> getChangedConfigComponents() {
1034: return (mChangedConfigComponents);
1035: }
1036:
1037: public Map<String, Properties> getComponentPropertyUpdates() {
1038: return (mComponentProperties);
1039: }
1040:
1041: public Map<String, Variable[]> getAddComponentAppVars() {
1042: return (mAddComponentAppVars);
1043: }
1044:
1045: public Map<String, String[]> getRemoveComponentAppVars() {
1046: return (mRemoveComponentAppVars);
1047: }
1048:
1049: public Map<String, Map<String, Properties>> getAddComponentConfigs() {
1050: return (mAddComponentConfig);
1051: }
1052:
1053: public Map<String, String> getRemoveComponentConfigs() {
1054: return (mRemoveComponentConfig);
1055: }
1056:
1057: /**
1058: * Return a printable status that summarizes the changes and actions.
1059: * @return String describing changes.
1060: */
1061: public String toString() {
1062: StringBuilder sb = new StringBuilder();
1063:
1064: sb.append("Registry Differences for Target: " + mTarget
1065: + "\n Remove Shared Libraries:\n");
1066: for (String i : mRemoveSharedLibraries) {
1067: sb.append(" " + i + "\n");
1068: }
1069: sb.append(" Add Shared Libraries:\n");
1070: for (String i : mAddSharedLibraries) {
1071: sb.append(" " + i + "\n");
1072: }
1073: sb.append(" Replace Shared Libraries:\n");
1074: for (String i : mReplaceSharedLibraries) {
1075: sb.append(" " + i + "\n");
1076: }
1077: sb.append(" Remove Components:\n");
1078: for (String i : mRemoveComponents) {
1079: sb.append(" " + i + "\n");
1080: }
1081: sb.append(" Add Components:\n");
1082: for (String i : mAddComponents) {
1083: sb.append(" " + i + "\n");
1084: }
1085: sb.append(" Update Components:\n");
1086: for (String i : mUpdateComponents) {
1087: sb.append(" " + i + "\n");
1088: }
1089: sb.append(" Affected Components:\n");
1090: for (String i : mComponentsAffectedByChanges) {
1091: sb.append(" " + i + "\n");
1092: }
1093: sb.append(" Replace Components:\n");
1094: for (String i : mReplaceComponents) {
1095: sb.append(" " + i + "\n");
1096: }
1097: sb.append(" Component properties:\n");
1098: for (String i : mComponentProperties.keySet()) {
1099: Properties props = mComponentProperties.get(i);
1100:
1101: sb.append(" Component: " + i + "\n");
1102: for (Object prop : props.keySet()) {
1103: sb.append(" Name: " + (String) prop + " Value: "
1104: + props.get(prop) + "\n");
1105: }
1106: }
1107: sb.append(" Remove component application variables:\n");
1108: for (String i : mRemoveComponentAppVars.keySet()) {
1109: String[] vars = mRemoveComponentAppVars.get(i);
1110: sb.append(" Component: " + i + "\n");
1111: for (int j = 0; j < vars.length; j++) {
1112: sb.append(" Name: " + vars[j] + "\n");
1113: }
1114: }
1115: sb.append(" Add component application variables:\n");
1116: for (String i : mAddComponentAppVars.keySet()) {
1117: Variable[] vars = mAddComponentAppVars.get(i);
1118: sb.append(" Component: " + i + "\n");
1119: for (int j = 0; j < vars.length; j++) {
1120: sb.append(" Name: " + vars[j].getName() + "\n");
1121: sb.append(" Type: " + vars[j].getType() + "\n");
1122: sb
1123: .append(" Value: " + vars[j].getValue()
1124: + "\n");
1125: }
1126: }
1127: sb.append(" Remove component configuration:\n");
1128: for (String i : mRemoveComponentConfig.keySet()) {
1129: sb.append(" Component: " + i + " Configuration: "
1130: + mRemoveComponentConfig.get(i) + "\n");
1131: }
1132: sb.append(" Add component configuration:\n");
1133: for (String i : mAddComponentConfig.keySet()) {
1134: Map<String, Properties> config = mAddComponentConfig.get(i);
1135: sb.append(" Component: " + i + "\n");
1136: for (String configuration : config.keySet()) {
1137: Properties props;
1138:
1139: sb.append(" Configuration Name: " + configuration
1140: + "\n");
1141: for (Object prop : (props = config.get(configuration))
1142: .keySet()) {
1143: sb.append(" Name: " + (String) prop
1144: + "\n Value: "
1145: + props.getProperty((String) prop) + "\n");
1146: }
1147: }
1148: }
1149: sb.append(" Change Components Lifecycle:\n");
1150: for (String i : mChangedLifecycleComponents) {
1151: sb.append(" " + i + "\n");
1152: }
1153: sb.append(" Remove Service Assemblies:\n");
1154: for (String i : mRemoveServiceAssemblies) {
1155: sb.append(" " + i + "\n");
1156: }
1157: sb.append(" Add Service Assemblies:\n");
1158: for (String i : mAddServiceAssemblies) {
1159: sb.append(" " + i + "\n");
1160: }
1161: sb.append(" Replace Service Assemblies:\n");
1162: for (String i : mReplaceServiceAssemblies) {
1163: sb.append(" " + i + "\n");
1164: }
1165: sb.append(" Change Service Assemblies Lifecycle:\n");
1166: for (String i : mChangedLifecycleServiceAssemblies) {
1167: sb.append(" " + i + "\n");
1168: }
1169: sb.append(" Affected Service Assemblies:\n");
1170: for (String i : mServiceAssembliesAffectedByChanges) {
1171: sb.append(" " + i + "\n");
1172: }
1173: sb.append(" Components to Start for Undeploy:\n");
1174: for (String i : componentsToStartForUndeploy()) {
1175: sb.append(" " + i + "\n");
1176:
1177: }
1178: sb.append(" Components to Start for Deploy:\n");
1179: for (String i : componentsToStartForDeploy()) {
1180: sb.append(" " + i + "\n");
1181:
1182: }
1183: sb.append(" Components to Start for Config Changes:\n");
1184: for (String i : mChangedConfigComponents) {
1185: sb.append(" " + i + "\n");
1186: }
1187: sb.append(" Domain config changes:\n");
1188: for (Map.Entry<String, HashMap> e : mDomainConfigChanges
1189: .entrySet()) {
1190: sb.append(" Category: " + e.getKey() + "\n");
1191: java.util.Set<Map.Entry> x = e.getValue().entrySet();
1192: for (Map.Entry c : x) {
1193: if (c.getValue() == null) {
1194: sb
1195: .append(" Delete Name(" + c.getKey()
1196: + ")\n");
1197: } else {
1198: sb.append(" Change Name(" + c.getKey()
1199: + ") Value(" + c.getValue() + ")\n");
1200: }
1201: }
1202: }
1203: sb.append(" Instance config changes:\n");
1204: for (Map.Entry<String, HashMap> e : mInstanceConfigChanges
1205: .entrySet()) {
1206: sb.append(" Category: " + e.getKey() + "\n");
1207: java.util.Set<Map.Entry> x = e.getValue().entrySet();
1208: for (Map.Entry c : x) {
1209: if (c.getValue() == null) {
1210: sb
1211: .append(" Delete Name(" + c.getKey()
1212: + ")\n");
1213: } else {
1214: sb.append(" Change Name(" + c.getKey()
1215: + ") Value(" + c.getValue() + ")\n");
1216: }
1217: }
1218: }
1219: return (sb.toString());
1220: }
1221:
1222: }
|