Package org.globus.workspace.network

Examples of org.globus.workspace.network.Association


            this.persistence.replaceAssocations(new_associations);

            final Enumeration en = new_associations.keys();
            while (en.hasMoreElements()) {
                final String assocName = (String) en.nextElement();
                final Association assoc =
                        (Association) new_associations.get(assocName);
                int numEntries = 0;
                if (assoc.getEntries() != null) {
                    numEntries = assoc.getEntries().size();
                }

                if (numEntries == 1) {
                    logger.info("Network '" +
                            assocName + "' loaded with one address.");
View Full Code Here


    }

    private void writeNetworkFiles(Map<String,Association> associations) {
        if (this.netSampleResource != null) {
            if (this.netSampleNetwork != null && this.netSampleNetwork.length() != 0) {
                final Association assoc = associations.get(this.netSampleNetwork);
               
                if (assoc == null || assoc.getEntries() == null || assoc.getEntries().isEmpty()) {
                    logger.warn ("Not writing netsample file because network '" +
                            this.netSampleNetwork + "' does not exist or has no entries");
                } else {
                    final List entries = assoc.getEntries();
                    final File netsampleFile;
                    try {

                        netsampleFile = this.netSampleResource.getFile();

                        FileUtil.writeNetSample(netsampleFile,
                                (AssociationEntry) entries.get(0),
                            this.netSampleNetwork, assoc.getDns());

                    } catch (IOException e) {
                        logger.warn("Failed to write netsample file to "+
                            this.netSampleResource.getFilename(), e);
                    }
View Full Code Here


        final Set<String> explicit = new HashSet<String>();
        for (Map.Entry<String, Association> assocPair : current.entrySet()) {
            final String assocName = assocPair.getKey();
            final Association assoc = assocPair.getValue();
            if (assoc == null || assoc.getEntries() == null) {
                continue;
            }
            for (Object entryObject : assoc.getEntries()) {
                final AssociationEntry entry = (AssociationEntry) entryObject;
                if (entry.isExplicitMac()) {
                    final AssociationEntry inUseEntry = inUse.get(entry.getMac());
                    if (inUseEntry != null) {
                        final String inUseIp = inUseEntry.getIpAddress();
                        if (inUseIp == null || !inUseIp.equals(entry.getIpAddress())) {
                            logger.error("An explicit MAC in network '"+assocName+
                                    "' collides with an in-use network entry! "+
                                    "Explicit: "+ entry.toString() + "\nIn use: "+
                                    inUseEntry.toString());
                            entry.setMac(null);
                            entry.setExplicitMac(false);
                        }

                    }

                }
                if (entry.isExplicitMac()) {
                    if (!explicit.add(entry.getMac())) {
                        logger.warn("Duplicate explicit MAC? "+ entry.getMac());
                    }
                }
            }
        }

        final List<String> macList =
                new ArrayList<String>();
        macList.addAll(inUse.keySet());
        macList.addAll(explicit);

        for (Association assoc : current.values()) {
            for (Object entryObject : assoc.getEntries()) {
                final AssociationEntry entry = (AssociationEntry) entryObject;
                _setMac(entry, macPrefix, macList, explicit);
            }
        }
View Full Code Here

        if (db == null) {
            throw new IllegalArgumentException("null persistence adapter");
        }

        final Hashtable associations = db.currentAssociations();
        final Association assoc = (Association)associations.get(name);
        if (assoc == null) {
            logger.error("no network '" + name + "'");
            return;
        }

        final List entries = assoc.getEntries();
        if (entries == null || entries.isEmpty()) {
            logger.error(Lager.id(trackingID) +
                    " network '" + name + "' has no entries");
            return;
        }
View Full Code Here

    private static Object[] nextAssociationEntry(String name,
                                                 Hashtable associations)
            throws ResourceRequestDeniedException {

        final Association assoc = (Association)associations.get(name);
        if (assoc == null) {
            final String err = "'" + name + "' is not a valid network name";
            logger.error(err);
            throw new ResourceRequestDeniedException(err);
        }

        final List entries = assoc.getEntries();
        if (entries == null || entries.isEmpty()) {
            return null; // *** EARLY RETURN ***
        }

        final Iterator iter = assoc.getEntries().iterator();
        AssociationEntry entry = null;
        while (iter.hasNext()) {
            entry = (AssociationEntry)iter.next();
            if (!entry.isInUse()) {
                entry.setInUse(true);
                break;
            }
            entry = null;
        }

        if (entry == null) {
            return null; // *** EARLY RETURN ***
        }
           
        final Object[] objs = new Object[2];

        objs[0] = entry;

        final String DNS = assoc.getDns();
        if (DNS == null || DNS.equalsIgnoreCase("none")) {
            objs[1] = "null";
        } else {
            objs[1] = DNS;
        }
View Full Code Here

                continue;
            }

            final String assocName = associationFile.getName();

            Association oldassoc = null;
            if (previous != null) {
                oldassoc = (Association) previous.get(assocName);

                // skip reading if file modification time isn't newer than last
                // container boot
                if (oldassoc != null) {
                    if (oldassoc.getFileTime() ==
                            associationFile.lastModified()) {

                        logger.info("file modification time for network '"
                                + assocName
                                + "' is not newer, using old configuration");

                        newAssocSet.put(assocName,
                                        oldassoc);

                        continue;
                    }
                }
            }

            final Association newassoc =
                            getNewAssoc(assocName, associationFile, oldassoc);

            if (newassoc != null) {
                newAssocSet.put(assocName, newassoc);
            }
        }

        if (previous == null || previous.isEmpty()) {
            return newAssocSet;
        }

        // Now look at previous entries in database for entries that were
        // there and now entirely gone.
        // If in use, we don't do anything.  When retired and the entry is
        // not in DB, a warning will trip but that is it.  From then on, the
        // address will be gone.

        final Enumeration en = previous.keys();

        while (en.hasMoreElements()) {

            final String assocname = (String) en.nextElement();
            final Association oldassoc = (Association) previous.get(assocname);
            if (oldassoc == null) {
                throw new ProgrammingError("all networks " +
                                    "in the hashmap should be non-null");
            }
            if (newAssocSet.containsKey(assocname)) {
View Full Code Here

    private static Association getNewAssoc(String assocName,
                                           File file,
                                           Association oldassoc)
            throws IOException {

        final Association assoc = loadOne(file);
        if (assoc == null) {
            return null;
        }

        if (oldassoc == null) {
            return assoc;
        }

        final List assocEntries = assoc.getEntries();
        if (assocEntries == null || assocEntries.isEmpty()) {
            // no conflicts are possible
            return assoc;
        }

        final List oldassocEntries = oldassoc.getEntries();
        if (oldassocEntries == null || oldassocEntries.isEmpty()) {
            return assoc;
        }

        if (assoc.getDns() != null && !assoc.getDns().equals(oldassoc.getDns())) {
            logger.info("Network '" + assocName + "': DNS changed from " +
                        oldassoc.getDns() + " to " + assoc.getDns());
        }

        for (Object assocEntry : assocEntries) {
            final AssociationEntry entry = (AssociationEntry) assocEntry;
            final AssociationEntry oldentry =
View Full Code Here

   
    private static Association loadOne(File file)
           
            throws IOException {

        Association association = null;
        final List associationList = new LinkedList();

        // Read the contents of file

        InputStream in = null;
        InputStreamReader isr = null;
        BufferedReader bufrd = null;
        String line;
        try {
            in = new FileInputStream(file);
            isr = new InputStreamReader(in);
            bufrd = new BufferedReader(isr);

            line = bufrd.readLine();
            if (line != null) {
                // find first non-comment, non-empty line
                boolean notfound = true;
                while (notfound) {
                    try {
                        association = parseDNS(line);
                        notfound = false;
                    } catch (Exception e) {
                        line = bufrd.readLine();
                        if (line == null) {
                            association = null;
                            break;
                        }
                    }
                }
                if (association == null) {
                    logger.error("DNS information incorrectly" +
                            " specified, skipping entire network. " +
                            "Path: " + file.getAbsolutePath());
                    return null;
                }

            } else {
                logger.warn("network file '" + file.getAbsolutePath() +
                                "' is empty, skipping");
                return null;
            }

            // the rest
            while ((line = bufrd.readLine()) != null) {
                line = line.trim();
                if (line.length() > 0) {
                    AssociationEntry entry = parseAssoc(line);
                    if (entry != null) {
                        associationList.add(entry);
                    }
                }
                // can have an association with no entries
            }

        } finally {
            try {
                if (bufrd != null) {
                    bufrd.close();
                }
                if (isr != null) {
                    isr.close();
                }
                if (in != null) {
                    in.close();
                }
            } catch (Exception e) {
                logger.error("",e);
            }
        }

        association.setEntries(associationList);
        association.setFileTime(file.lastModified());

        return association;
    }
View Full Code Here

        if (dns.startsWith(COMMENT_CHAR)) {
            throw new CommentException();
        }

        if (dns.equals(NOENTRY)) {
            return new Association(null);
        } else {
            return new Association(dns);
        }
    }
View Full Code Here

            Hashtable cAssociations = persistenceAdapter.currentAssociations();
            List<Association> assocs = new ArrayList<Association>();
            Enumeration keys = cAssociations.keys();

            while(keys.hasMoreElements()) {
                Association a = (Association) cAssociations.get(keys.nextElement());
                assocs.add(a);
            }

            if(assocs == null || assocs.size() == 0)
                return null;
View Full Code Here

TOP

Related Classes of org.globus.workspace.network.Association

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.