/* * storage_plugin_getFileInfo, <class * 'agent.api.storageplugin.StoragePlugin'> argument: impl_name - default: * None */ public FileProperties storagePluginGetFileInfo(String poolUuid, String host, String file) throws Ovm3ResourceException { /* file path is the full path */ String uuid = deDash(poolUuid); StorageServer ss = new StorageServer(); StorageDetails sd = new StorageDetails(); FileProperties fp = new FileProperties(); ss.setUuid(uuid); ss.setAccessHost(host); sd.setUuid(poolUuid); sd.setDetailsRelationalUuid(uuid); sd.setState(1); fp.setName(file); fp.setProperties( (HashMap<String, Object>) callWrapper( "storage_plugin_getFileInfo", getPluginType, ss.getDetails(), sd.getDetails(), fp.getProperties())); if ("".equals(fp.getName())) { throw new Ovm3ResourceException("Unable to get file info for " + file); } return fp; }
/* * Should do some input checking of ss and base * storage_plugin_getFileSystemInfo, * <class 'agent.api.storageplugin.StoragePlugin'> argument: impl_name - * default: None requires a minumum of uuid, access_host, storage_type * ss_uuid, access_path, uuid (the ss */ public StorageDetails storagePluginGetFileSystemInfo( String propUuid, String mntUuid, String nfsHost, String nfsRemotePath) throws Ovm3ResourceException { /* clean the props */ StorageServer ss = new StorageServer(); StorageDetails sd = new StorageDetails(); new FileProperties(); ss.setUuid(propUuid); sd.setDetailsRelationalUuid(propUuid); sd.setUuid(mntUuid); ss.setAccessHost(nfsHost); if (nfsRemotePath.contains(nfsHost + ":")) { sd.setAccessPath(nfsRemotePath); } else { sd.setAccessPath(nfsHost + ":" + nfsRemotePath); } ss.setStorageType(FILESYS); sd.setDetails( (HashMap<String, Object>) callWrapper( "storage_plugin_getFileSystemInfo", getPluginType, ss.getDetails(), sd.getDetails())); return sd; }
/* * now only for files * storage_plugin_create, <class * 'agent.api.storageplugin.StoragePlugin'> argument: impl_name - default: * None - calls resize secretly.. after "create" */ public FileProperties storagePluginCreate( String poolUuid, String host, String file, Long size, Boolean dir) throws Ovm3ResourceException { /* this is correct ordering stuff and correct naming!!! */ String uuid = deDash(poolUuid); StorageServer ss = new StorageServer(); StorageDetails sd = new StorageDetails(); FileProperties fp = new FileProperties(); ss.setUuid(uuid); ss.setStorageType(FILESYS); ss.setAccessHost(host); sd.setUuid(poolUuid); sd.setDetailsRelationalUuid(uuid); sd.setState(2); String type = "File"; if (dir) { type = "Directory"; } fp.setProperties( (HashMap<String, Object>) callWrapper( "storage_plugin_create", getPluginType, ss.getDetails(), sd.getDetails(), file, type, size)); return fp; }
// ------------------------------------------------------------ private void extractPacketData(StorageServer serv, DatagramPacket receivePacket) throws IOException { try { byte[] temp = new byte[4]; System.arraycopy(receivePacket.getData(), 3, temp, 0, 4); serv.IP = InetAddress.getByAddress(temp).getHostAddress(); // System.out.println("serv.ip: " + serv.IP); // serv.IP = receivePacket.getAddress().getHostAddress(); // System.out.println("serv.ip: " + serv.IP); // System.out.println("inetaddress.getbyname() : " + // InetAddress.getByName(gwIP)) /* * serv.IP = String.valueOf(receivePacket.getData()[3]) + "." + * String.valueOf(receivePacket.getData()[4]) + "." + * String.valueOf(receivePacket.getData()[5]) + "." + * String.valueOf(receivePacket.getData()[6]); */ serv.port = (int) (receivePacket.getData()[7] << 8) + receivePacket.getData()[8]; System.out.println("Connecting to: " + serv.IP + ":" + serv.port); Socket s = new Socket(InetAddress.getByName(serv.IP), serv.port); serv.sock = s; } catch (IOException e) { System.out.println( "BIG PROBLEM HERE BECAUSE YOU CANNOT CONNECT " + "BACK!!!!!!!! Trying other address"); try { serv.IP = receivePacket.getAddress().getHostAddress(); System.out.println("Connecting to: " + serv.IP + ":" + serv.port); Socket s = new Socket(InetAddress.getByName(serv.IP), serv.port); serv.sock = s; } catch (IOException f) { System.out.println("cannot connect here aswell\n"); throw new IOException(f); } } }
/* * storage_plugin_listFileSystems, <class * 'agent.api.storageplugin.StoragePlugin'> argument: impl_name - default: * None */ public Boolean storagePluginListFs(String host) throws Ovm3ResourceException { StorageServer ss = new StorageServer(); ss.setAccessHost(host); ss.setStorageType(FILESYS); ss.setDetails( (Map<String, Object>) callWrapper("storage_plugin_listFileSystems", getPluginType, ss.getDetails())); return true; }
/* * INFO: is used for files and dirs..., we only implement files for now... * storage_plugin_destroy, <class 'agent.api.storageplugin.StoragePlugin'> * argument: impl_name - default: None */ public Boolean storagePluginDestroy(String poolUuid, String file) throws Ovm3ResourceException { String uuid = deDash(poolUuid); StorageServer ss = new StorageServer(); StorageDetails sd = new StorageDetails(); FileProperties fp = new FileProperties(); ss.setUuid(uuid); sd.setDetailsRelationalUuid(uuid); sd.setUuid(poolUuid); fp.setType("file"); fp.setUuid(poolUuid); fp.setName(file); return nullIsTrueCallWrapper( "storage_plugin_destroy", getPluginType, ss.getDetails(), sd.getDetails(), fp.getProperties()); }
/** * . storage_plugin_unmount, <class 'agent.api.storageplugin.StoragePlugin'> argument: impl_name - * default: None * * @return boolean */ public final Boolean storagePluginUnmountNFS( String nfsHost, String remotePath, String mntUuid, String localPath) throws Ovm3ResourceException { StorageServer ss = new StorageServer(); StorageDetails sd = new StorageDetails(); sd.setUuid(mntUuid); sd.setDetailsRelationalUuid(deDash(mntUuid)); ss.setUuid(deDash(mntUuid)); ss.setAccessHost(nfsHost); sd.setAccessPath(nfsHost + ":" + remotePath); sd.setState(1); ss.setStorageType(FILESYS); String mountPoint = localPath + "/" + mntUuid; callWrapper( "storage_plugin_unmount", getPluginType, ss.getDetails(), sd.getDetails(), mountPoint, ACTIVE); return true; }
/** * . storage_plugin_mount, <class 'agent.api.storageplugin.StoragePlugin'> argument: impl_name - * default: None */ public final StorageDetails storagePluginMountNFS( String nfsHost, String nfsRemotePath, String mntUuid, String mountPoint) throws Ovm3ResourceException { String propUuid = deDash(mntUuid); StorageServer ss = new StorageServer(); StorageDetails sd = new StorageDetails(); ss.setUuid(propUuid); ss.setName(propUuid); ss.setAccessHost(nfsHost); sd.setDetailsRelationalUuid(propUuid); sd.setUuid(mntUuid); sd.setAccessPath(nfsHost + ":" + nfsRemotePath); if (!mountPoint.contains(mntUuid)) { mountPoint += "/" + mntUuid; } sd.setDetails( (HashMap<String, Object>) callWrapper( "storage_plugin_mount", getPluginType, ss.getDetails(), sd.getDetails(), mountPoint, EMPTY_STRING, ACTIVE, someList)); /* this magically means it's already mounted.... * double check */ if (sd.getDetails() == null) { sd = storagePluginGetFileSystemInfo(propUuid, mntUuid, nfsHost, nfsRemotePath); } if (EMPTY_STRING.contains(ss.getUuid())) { throw new Ovm3ResourceException("Unable to mount NFS FileSystem"); } return sd; }
// ------------------------------------------------------------ private boolean respondToDatagram( DatagramPacket receivePacket, ServerDescription[] validServers, boolean addToFile, int expectedServers) throws IOException { boolean serverAdded = false; StorageServer serv = new StorageServer(); try { if (receivePacket.getData()[0] == MessageType.ADD_SERV_RQT.getType()) { extractPacketData(serv, receivePacket); int servNo = findServer(validServers, serv.IP, serv.port); int index = servAlreadyConnected(serv); /* * if(expectedServers == 0) { Message m = new * Message(MessageType.COPY_FILE_RQT); m.send(serv.sock); return(false); * } else if(expectedServers == 1) { Message m = new * Message(MessageType.COPY_FILE_RSP); m.send(serv.sock); return(false); * } else if(expectedServers == 2) { Message m = new * Message(MessageType.DELETE_DIR_RQT); m.send(serv.sock); * return(false); } else { Message m = new * Message(MessageType.DELETE_DIR_RSP); m.send(serv.sock); } * if(expectedServers > 2) { return false; } */ if (servNo > 0 || addToFile) { if (index >= 0) { System.out.println("Reconnection of a server, removing stale values"); serverList.remove(index); } Message m = new Message(MessageType.SEND_NEXT_PARAM); m.send(serv.sock); m = Message.receive(serv.sock); if (m.getMessageType() != MessageType.NEXT_PARAM_RQT) { m = new Message(MessageType.ERR_UNEXPECTED_CLT); m.send(serv.sock); return (false); } else { byte[] payload = new byte[2]; payload = m.getPayload(); serv.httpPort = payload[0] & 0xff; serv.httpPort <<= 8; serv.httpPort += payload[1] & 0xff; if (servNo > 0) { serv.servNo = servNo; } if (servNo < 0) { try { validServers[expectedServers].IP = ServerDescription.IPStrToByteArr(serv.IP); validServers[expectedServers].port = serv.port; validServers[expectedServers].serverNumber = findMinUnusedServNum(validServers); serv.servNo = validServers[expectedServers].serverNumber; addToFile(serv, validServers[expectedServers].serverNumber); serverAdded = true; } catch (GenericException e) { m = new Message(MessageType.ERR_UNEXPECTED_CLT); m.send(serv.sock); return (false); } } // By default, external IP = internal IP serv.externalName = serv.IP; Iterator itr = ipPairs.iterator(); // if we find an external IP that is associated with the // internal IP for this server, change the external IP // address for this server to match while (itr.hasNext()) { String[] pair = (String[]) itr.next(); // mylog.write("pair[0]: " + pair[0] + "servIP: " + serv.IP + // "\n", true); if (pair[0].equals(serv.IP)) { // mylog.write("found ext int match\n", true); serv.externalName = pair[1]; /* * Runtime runtime = Runtime.getRuntime(); String[] args = new * String[]{"sh", "-c", "ssh -f -i " + keyfile + " root@" + gwIP * + " \"perl stoptcppr.pl " + serv.externalIP + "\""}; Process * proc = runtime.exec(args); args = new String[]{"sh", "-c", * "ssh -f -i " + keyfile + " root@" + gwIP + * " \"perl tcppr.pl " + serv.externalIP + " " + serv.IP + * "\""}; proc = runtime.exec(args); */ break; } } serverList.add(serv); m = new Message(MessageType.ADD_SERV_RSP); payload[0] = (byte) ((servNo >> 8) & 0xff); payload[1] = (byte) (servNo & 0xff); m.addPayload(payload); m.send(serv.sock); } } else { Message m = new Message(MessageType.ERR_UNEXPECTED_CLT); m.send(serv.sock); } } return (serverAdded); } catch (IOException e) { Message m = new Message(MessageType.INTERNAL_SERVER_ERR); m.send(serv.sock); throw new IOException(e); } catch (GenericException e) { Message m = new Message(MessageType.INTERNAL_SERVER_ERR); m.send(serv.sock); throw new IOException(e.getMessage()); } }