DhcpMgrImpl.java revision 7c478bd95313f5f23a4c958a745db2134aa03244
/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License, Version 1.0 only
* (the "License"). You may not use this file except in compliance
* with the License.
*
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
* See the License for the specific language governing permissions
* and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at usr/src/OPENSOLARIS.LICENSE.
* If applicable, add the following below this CDDL HEADER, with the
* fields enclosed by brackets "[]" replaced with your own identifying
* information: Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*/
/*
* ident "%Z%%M% %I% %E% SMI"
*
* Copyright (c) 1998-2001 by Sun Microsystems, Inc.
* All rights reserved.
*/
public class DhcpMgrImpl implements DhcpMgr {
private DhcpNetMgrImpl netMgr;
private DhcptabMgrImpl dtMgr;
private DhcpServiceMgrImpl srvMgr;
// Global lock file used to ensure only one export or import is running
public DhcpMgrImpl() {
}
public DhcpNetMgr getNetMgr() {
}
return netMgr;
}
public DhcptabMgr getDhcptabMgr() {
}
return dtMgr;
}
public DhcpServiceMgr getDhcpServiceMgr() {
}
return srvMgr;
}
/**
* Set the file which is currently open.
*/
// Some other file is currently listed as open; deny the request
if (currentlyOpenFile != null) {
return null;
}
// Get system-wide lock by atomically creating lockfile
if (!lockFile.createNewFile()) {
return null;
}
return currentlyOpenFile;
}
// If this is truly the currently open file, then clear our reference
if (isFileOpen(file)) {
// Release system-wide lock by deleting lockfile
}
}
/**
* Get the file which is currently open.
*/
return currentlyOpenFile;
}
/**
* Test whether a file is currently open.
*/
return (file == currentlyOpenFile);
}
/**
* Returns the fullpath to the lock file.
* @return the fullpath to the lock file.
*/
public String getLockPath() {
return (LOCK_FILE);
}
/**
* Opens an export file and writes a header record to it.
* @param fileName the fullpath to the export file to create.
* @param user the name of the user creating this file
* @param nets an array of networks which will be exported
* @param overwrite true if file should be forcible overwritten
* @return a reference key for this file instance, or null if there is
* another file already open for import or export
*/
throws ExistsException, IOException {
// Grab the lock
// File exists and not supposed to overwrite, throw exception
throw new ExistsException(fileName);
}
try {
// Open a stream to write on
// Construct a header record, and write it
// Save stream reference
} catch (IOException e) {
// Something went wrong, release the lock and re-throw
throw e;
}
}
// Give caller a reference to use for writing additional data
return file;
} // openExportFile
/**
* Close an export file, delete it if need be
* @param ref Reference to the open file, returned from openExportFile
* @param delete true if file is to be deleted on close, false otherwise.
*/
}
try {
if (delete) {
}
} catch (IOException e) {
// Just re-throw, let finally block clean up
throw e;
} finally {
/*
* Always release the lock, we consider the file no longer useful
* no matter the outcome above.
*/
}
}
/**
* Open an import file
* @param fileName Name of file to open
* @return A reference to the opened import file, or null if another
* export or import is already in progress.
*/
throw new FileNotFoundException(fileName);
}
try {
new FileInputStream(file)));
} catch (IOException e) {
throw e;
}
}
// Return reference caller can use to actually do the import
return file;
}
/**
* Close an import file, delete it if need be
* @param ref Reference to the open file, returned from openImportFile
* @param delete true if file is to be deleted on close, false otherwise.
*/
}
try {
if (delete) {
}
} catch (IOException e) {
// Just re-throw and let finally do the cleanup
throw e;
} finally {
}
}
/**
* Retrieve the export header for the import file
* @param ref Reference to the file we're reading from
* @return The ExportHeader written at export time.
*/
throws IOException, ClassNotFoundException {
// No such file open; throw an exception
} else {
return rec;
}
}
// Get the desired records out of an array
throws NoEntryException {
// Grab only the ones we want
}
}
// We didn't find one of the requested records
}
return recArr;
}
/**
* Export a list of macros specified by name to a file.
* @param ref A reference to the file, acquired from openExportFile()
* @param allMacros true if all macros are to be exported
* @param names names of macros to be exported if allMacros is false
*/
throws BridgeException, IOException {
// throw an exception that this is a bad reference
}
if (!allMacros) {
// Grab only the ones we want
}
}
/**
* Export a list of options specified by name to a file.
* @param ref A reference to the file, acquired from openExportFile()
* @param allOptions true if all options are to be exported
* @param names names of options to be exported if allOptions is false
*/
throws BridgeException, IOException {
// throw an exception that this is a bad reference
}
if (!allOptions) {
// Grab only the ones we want
}
}
/**
* Export a network and its client records to a file
* @param ref A reference to the file, acquired from openExportFile()
* @param net Network to be exported
*/
throws BridgeException, IOException {
// throw an exception that this is a bad reference
}
// Get clients from database
DhcpClientRecord [] clients =
// Now write client array for this net
}
/**
* Import dhcptab records from an export file into the configuration.
* @param recType The type of record to import; must be either
* DhcptabRecord.MACRO or DhcptabRecord.OPTION
* @param ref The file reference returned by openImportFile()
* @param overwrite true if this data should overwrite existing data
* @return An array of import results; empty if all records were imported.
*/
boolean overwrite)
// No such file open; throw an exception
}
// Try to cast to appropriate type to ensure data is OK.
} else {
}
try {
if (overwrite) {
/*
* Hack alert! We reset the signature to a default value
* that the datastores will not interpret. This allows us
* to forcibly delete the record, even if it came from a
* previous attempt to import this record. Without this
* step, the datastore may (correctly) signal an update
* collision and refuse to perform the delete. An
* alternative that might be used is to mark the signature
* member of DhcptabRecord as transient; however, that would
* have the future undesirable effect of dropping that
* field when we put a remote communication method
* in the mix which uses serialization, such as RMI.
*/
}
} catch (Throwable t) {
// Do nothing; we'll probably have an error on the create
}
try {
} catch (Exception e) {
// Record the error, we try all of them no matter what
}
}
}
/**
* Import options from an export file.
* @param ref Reference to import file returned by openImportFile
* @param overwrite true if existing data should be overwritten.
* @return An array of errors in the import process; empty if all OK
*/
}
/**
* Import macros from an export file.
* @param ref Reference to import file returned by openImportFile
* @param overwrite true if existing data should be overwritten.
* @return An array of errors in the import process; empty if all OK
*/
}
/**
* Import network records from an export file into the configuration.
* @param net The network which is expected to be imported
* @param ref The file reference returned by openImportFile()
* @param overwrite true if this data should overwrite existing data
* @return An array of import results; empty if all records were imported.
*/
// No such file open; throw an exception
}
// Create the network table. It may already exist.
boolean netExisted = false;
try {
} catch (TableExistsException e) {
/*
* This is o.k. no matter whether overwrite is true or not;
* however, record the fact that it existed so that we don't
* optimize out the delete in the loop below.
*/
netExisted = true;
}
// Add the addresses to the table and record any exceptions.
/*
* If we're supposed to overwrite and the network table
* existed before we started, then try to delete the client
*/
if (overwrite && netExisted) {
try {
/*
* Hack alert! We reset the signature to a default value
* that the datastores will not interpret. This allows us
* to forcibly delete the record, even if it came from a
* previous attempt to import this record. Without this
* step, the datastore may "correctly" signal an update
* collision and refuse to perform the delete. An
* alternative that might be used is to mark the signature
* member of DhcptabRecord as transient; however, that would
* have the future undesirable effect of dropping that
* field when we put a remote communication method
* in the mix which uses serialization, such as RMI.
*/
} catch (Throwable t) {
// Ignore delete error, we'll probably have an error on add
}
}
try {
// Now add the client
} catch (Exception e) {
}
}
}
}