~ubuntu-core-dev/ubuntu/maverick/eucalyptus/devel

« back to all changes in this revision

Viewing changes to clc/modules/storage-controller/src/main/java/com/eucalyptus/storage/ISCSIManager.java

  • Committer: Dustin Kirkland
  • Date: 2010-07-22 08:41:57 UTC
  • mfrom: (1050.1.19 ubuntu)
  • Revision ID: kirkland@x200-20100722084157-zh2p8dkawznvxxpn
Approving Dave Walker's merge of new upstream Eucalyptus 2.0 release.

Dustin Kirkland <kirkland@canonical.com>

* New major upstream version merge, 2.0 (r1211).
  - 01-wsdl-stubs.patch, debian/wsdl.md5sums: wsdl stubs updated.
  - 11-state-cleanup-memleakfix.patch: Removed, fixed upstream.
  - 21-eucalyptus-1.7-with-gwt-1.6.4.patch: New patch, allows 
    eucalyptus-1.7 to be built against gwt 1.6.4. Based on patch courtesy 
    of Dmitrii Zagorodnov, upstream. (LP: #597330)
* debian/eucalyptus-java-common.links: 
  - Changed symlink for groovy, point to groovy.all.jar, making compatiable 
    with groovy versions >1.7. (LP: #595421)
  - Added ant.jar & jetty-rewrite-handler.jar as they are now required.
* debian/control
  - & debian/build-jars: Added libjavassist-java and libjetty-extra-java as 
    build dependencies.
  - Added libjetty-extra-java as a dependency of eucalyptus-java-common
* The binary resulting jar's have been renamed from eucalyptus-*-1.6.2.jar
  to eucalyptus-*-main.jar:    
  - debian/eucalyptus-cc.upstart
  - debian/eucalyptus-cloud.install
  - debian/eucalyptus-common.eucalyptus.upstart
  - debian/eucalyptus-java-common.install
  - debian/eucalyptus-network.upstart
  - debian/eucalyptus-sc.install
  - debian/eucalyptus-walrus.install
* debian/eucalyptus-java-common.install: New upstream jars that have been
  installed:
  - eucalyptus-db-hsqldb-ext-main.jar
  - eucalyptus-component-main.jar
* debian/control:
  - Updated Standards Version to 3.8.4 (no change)
  - Updated the upstream Homepage to: http://open.eucalyptus.com/
  - Changed Vcs-Bzr to reflect new location of Ubuntu hosted development branch.
  - Made the Build Dependency of groovy and the binary eucalyptus-java-common
    package depend on version >=1.7.

Show diffs side-by-side

added added

removed removed

Lines of Context:
103
103
                returnValue = SystemUtil.run(new String[]{"sudo", "tgtadm", "--help"});
104
104
                if(returnValue.length() == 0) {
105
105
                        throw new EucalyptusCloudException("tgtadm not found: Is tgt installed?");
106
 
                } else {
107
 
                        LOG.info(returnValue);
108
106
                }
109
107
                if(SystemUtil.runAndGetCode(new String[]{"sudo", "tgtadm", "--lld", "iscsi", "--mode", "target", "--op", "show"}) != 0) {
110
 
                        throw new EucalyptusCloudException("Unable to connect to tgt daemon. Is tgtd loaded?");
 
108
                        LOG.warn("Unable to connect to tgt daemon. Is tgtd loaded?");
 
109
                        LOG.info("Attempting to start tgtd ISCSI daemon");
 
110
                        if(SystemUtil.runAndGetCode(new String[]{"sudo", "tgtd"}) != 0) {
 
111
                                throw new EucalyptusCloudException("Unable to start tgt daemon. Cannot proceed.");
 
112
                        }
111
113
                }
112
114
        }
113
115
 
174
176
        public void unexportTarget(int tid, int lun) {
175
177
                try
176
178
                {
177
 
                        Runtime rt = Runtime.getRuntime();
178
 
                        Process proc = rt.exec(new String[]{"sudo", "tgtadm", "--lld", "iscsi", "--op", "unbind", "--mode", "target", "--tid", String.valueOf(tid),  "-I", "ALL"});
179
 
                        StreamConsumer error = new StreamConsumer(proc.getErrorStream());
180
 
                        StreamConsumer output = new StreamConsumer(proc.getInputStream());
181
 
                        error.start();
182
 
                        output.start();
183
 
                        proc.waitFor();
184
 
 
185
 
                        proc = rt.exec(new String[]{"sudo", "tgtadm", "--lld", "iscsi", "--op", "delete", "--mode", "logicalunit", "--tid" , String.valueOf(tid), "--lun", String.valueOf(lun)});
186
 
                        error = new StreamConsumer(proc.getErrorStream());
187
 
                        output = new StreamConsumer(proc.getInputStream());
188
 
                        error.start();
189
 
                        output.start();
190
 
                        proc.waitFor();
191
 
                        output.join();
192
 
                        String errorValue = error.getReturnValue();
193
 
                        if(errorValue.length() > 0)
194
 
                                throw new EucalyptusCloudException(errorValue);
195
 
 
196
 
                        proc = rt.exec(new String[]{"sudo", "tgtadm", "--lld", "iscsi", "--op", "delete", "--mode", "target", "--tid ", String.valueOf(tid)});
197
 
                        error = new StreamConsumer(proc.getErrorStream());
198
 
                        output = new StreamConsumer(proc.getInputStream());
199
 
                        error.start();
200
 
                        output.start();
201
 
                        proc.waitFor();                 
 
179
                        if(SystemUtil.runAndGetCode(new String[]{"sudo", "tgtadm", "--lld", "iscsi", "--op", "unbind", "--mode", "target", "--tid", String.valueOf(tid),  "-I", "ALL"}) != 0) {
 
180
                                LOG.error("Unable to unbind tid: " + tid);
 
181
                                return;
 
182
                        }
 
183
 
 
184
                        if(SystemUtil.runAndGetCode(new String[]{"sudo", "tgtadm", "--lld", "iscsi", "--op", "delete", "--mode", "logicalunit", "--tid" , String.valueOf(tid), "--lun", String.valueOf(lun)}) != 0) {
 
185
                                LOG.error("Unable to delete lun for tid: " + tid);
 
186
                                return;
 
187
                        }
 
188
 
 
189
                        if(SystemUtil.runAndGetCode(new String[]{"sudo", "tgtadm", "--lld", "iscsi", "--op", "delete", "--mode", "target", "--tid", String.valueOf(tid)}) != 0) {
 
190
                                LOG.error("Unable to delete target: " + tid);
 
191
                                return;
 
192
                        }                       
202
193
                } catch (Throwable t) {
203
194
                        LOG.error(t);
204
195
                }
215
206
        @Override
216
207
        public void configure() {
217
208
                EntityWrapper<ISCSIMetaInfo> db = StorageProperties.getEntityWrapper();
218
 
                ISCSIMetaInfo metaInfo = new ISCSIMetaInfo();
 
209
                ISCSIMetaInfo metaInfo = new ISCSIMetaInfo(StorageProperties.NAME);
219
210
                try {
220
211
                        List<ISCSIMetaInfo> metaInfoList = db.query(metaInfo);
221
212
                        if(metaInfoList.size() <= 0) {
267
258
        public synchronized void allocateTarget(LVMVolumeInfo volumeInfo) {
268
259
                if(volumeInfo instanceof ISCSIVolumeInfo) {
269
260
                        ISCSIVolumeInfo iscsiVolumeInfo = (ISCSIVolumeInfo) volumeInfo;         
270
 
                        ISCSIMetaInfo metaInfo = new ISCSIMetaInfo();
271
261
                        EntityWrapper<ISCSIMetaInfo> db = StorageProperties.getEntityWrapper();
272
 
                        List<ISCSIMetaInfo> metaInfoList = db.query(metaInfo);
 
262
                        List<ISCSIMetaInfo> metaInfoList = db.query(new ISCSIMetaInfo(StorageProperties.NAME));
 
263
                        int tid = -1, storeNumber = -1;
273
264
                        if(metaInfoList.size() > 0) {
274
265
                                ISCSIMetaInfo foundMetaInfo = metaInfoList.get(0);
275
 
                                int storeNumber = foundMetaInfo.getStoreNumber();
276
 
                                int tid = foundMetaInfo.getTid();
277
 
                                iscsiVolumeInfo.setStoreName(foundMetaInfo.getStorePrefix() + StorageProperties.NAME + ":store" + storeNumber);
278
 
                                iscsiVolumeInfo.setStoreUser(foundMetaInfo.getStoreUser());
279
 
                                iscsiVolumeInfo.setTid(tid);
280
 
                                iscsiVolumeInfo.setLun(1);
281
 
                                foundMetaInfo.setStoreNumber(++storeNumber);
282
 
                                foundMetaInfo.setTid(++tid);
 
266
                                storeNumber = foundMetaInfo.getStoreNumber();
 
267
                                tid = foundMetaInfo.getTid();
 
268
                        }                       
 
269
                        db.commit();
 
270
                        //check if tid is in use
 
271
                        int i = tid;
 
272
                        do {
 
273
                                try {
 
274
                                        String returnValue = SystemUtil.run(new String[]{"sudo", "tgtadm", "--lld", "iscsi", "--op", "show", "--mode", "target", "--tid" , String.valueOf(i)});
 
275
                                        if(returnValue.length() == 0) {
 
276
                                                tid = i;
 
277
                                                break;
 
278
                                        }
 
279
                                } catch (ExecutionException e) {
 
280
                                        LOG.error(e);
 
281
                                        iscsiVolumeInfo.setTid(-1);
 
282
                                        return;
 
283
                                }
 
284
                                i = (i + 1) % Integer.MAX_VALUE;
 
285
                        } while(i != tid);
 
286
                        if(tid > 0) {
 
287
                                db = StorageProperties.getEntityWrapper();
 
288
                                metaInfoList = db.query(new ISCSIMetaInfo(StorageProperties.NAME));
 
289
                                if(metaInfoList.size() > 0) {
 
290
                                        ISCSIMetaInfo foundMetaInfo = metaInfoList.get(0);
 
291
                                        foundMetaInfo.setStoreNumber(++storeNumber);
 
292
                                        foundMetaInfo.setTid(tid + 1);
 
293
                                        iscsiVolumeInfo.setStoreName(foundMetaInfo.getStorePrefix() + StorageProperties.NAME + ":store" + storeNumber);
 
294
                                        iscsiVolumeInfo.setStoreUser(foundMetaInfo.getStoreUser());
 
295
                                        iscsiVolumeInfo.setTid(tid);
 
296
                                        //LUN cannot be 0 (some clients don't like that).
 
297
                                        iscsiVolumeInfo.setLun(1);
 
298
                                }
 
299
                                db.commit();
 
300
                        } else {
 
301
                                iscsiVolumeInfo.setTid(-1);
 
302
                                LOG.fatal("Unable to allocate ISCSI target id.");
283
303
                        }
284
 
                        db.commit();
285
304
                }
286
305
        }
287
306