1
1
/*******************************************************************************
2
*Copyright (c) 2009 Eucalyptus Systems, Inc.
4
* This program is free software: you can redistribute it and/or modify
5
* it under the terms of the GNU General Public License as published by
6
* the Free Software Foundation, only version 3 of the License.
9
* This file is distributed in the hope that it will be useful, but WITHOUT
10
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14
* You should have received a copy of the GNU General Public License along
15
* with this program. If not, see <http://www.gnu.org/licenses/>.
17
* Please contact Eucalyptus Systems, Inc., 130 Castilian
18
* Dr., Goleta, CA 93101 USA or visit <http://www.eucalyptus.com/licenses/>
19
* if you need additional information or have any questions.
21
* This file may incorporate work covered under the following copyright and
24
* Software License Agreement (BSD License)
26
* Copyright (c) 2008, Regents of the University of California
27
* All rights reserved.
29
* Redistribution and use of this software in source and binary forms, with
30
* or without modification, are permitted provided that the following
33
* Redistributions of source code must retain the above copyright notice,
34
* this list of conditions and the following disclaimer.
36
* Redistributions in binary form must reproduce the above copyright
37
* notice, this list of conditions and the following disclaimer in the
38
* documentation and/or other materials provided with the distribution.
40
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
41
* IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
42
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
43
* PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER
44
* OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
45
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
46
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
47
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
48
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
49
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
50
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. USERS OF
51
* THIS SOFTWARE ACKNOWLEDGE THE POSSIBLE PRESENCE OF OTHER OPEN SOURCE
52
* LICENSED MATERIAL, COPYRIGHTED MATERIAL OR PATENTED MATERIAL IN THIS
53
* SOFTWARE, AND IF ANY SUCH MATERIAL IS DISCOVERED THE PARTY DISCOVERING
54
* IT MAY INFORM DR. RICH WOLSKI AT THE UNIVERSITY OF CALIFORNIA, SANTA
55
* BARBARA WHO WILL THEN ASCERTAIN THE MOST APPROPRIATE REMEDY, WHICH IN
56
* THE REGENTS’ DISCRETION MAY INCLUDE, WITHOUT LIMITATION, REPLACEMENT
57
* OF THE CODE SO IDENTIFIED, LICENSING OF THE CODE SO IDENTIFIED, OR
58
* WITHDRAWAL OF THE CODE CAPABILITY TO THE EXTENT NEEDED TO COMPLY WITH
59
* ANY SUCH LICENSES OR RIGHTS.
60
*******************************************************************************/
2
*Copyright (c) 2009 Eucalyptus Systems, Inc.
4
* This program is free software: you can redistribute it and/or modify
5
* it under the terms of the GNU General Public License as published by
6
* the Free Software Foundation, only version 3 of the License.
9
* This file is distributed in the hope that it will be useful, but WITHOUT
10
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14
* You should have received a copy of the GNU General Public License along
15
* with this program. If not, see <http://www.gnu.org/licenses/>.
17
* Please contact Eucalyptus Systems, Inc., 130 Castilian
18
* Dr., Goleta, CA 93101 USA or visit <http://www.eucalyptus.com/licenses/>
19
* if you need additional information or have any questions.
21
* This file may incorporate work covered under the following copyright and
24
* Software License Agreement (BSD License)
26
* Copyright (c) 2008, Regents of the University of California
27
* All rights reserved.
29
* Redistribution and use of this software in source and binary forms, with
30
* or without modification, are permitted provided that the following
33
* Redistributions of source code must retain the above copyright notice,
34
* this list of conditions and the following disclaimer.
36
* Redistributions in binary form must reproduce the above copyright
37
* notice, this list of conditions and the following disclaimer in the
38
* documentation and/or other materials provided with the distribution.
40
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
41
* IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
42
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
43
* PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER
44
* OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
45
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
46
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
47
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
48
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
49
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
50
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. USERS OF
51
* THIS SOFTWARE ACKNOWLEDGE THE POSSIBLE PRESENCE OF OTHER OPEN SOURCE
52
* LICENSED MATERIAL, COPYRIGHTED MATERIAL OR PATENTED MATERIAL IN THIS
53
* SOFTWARE, AND IF ANY SUCH MATERIAL IS DISCOVERED THE PARTY DISCOVERING
54
* IT MAY INFORM DR. RICH WOLSKI AT THE UNIVERSITY OF CALIFORNIA, SANTA
55
* BARBARA WHO WILL THEN ASCERTAIN THE MOST APPROPRIATE REMEDY, WHICH IN
56
* THE REGENTS’ DISCRETION MAY INCLUDE, WITHOUT LIMITATION, REPLACEMENT
57
* OF THE CODE SO IDENTIFIED, LICENSING OF THE CODE SO IDENTIFIED, OR
58
* WITHDRAWAL OF THE CODE CAPABILITY TO THE EXTENT NEEDED TO COMPLY WITH
59
* ANY SUCH LICENSES OR RIGHTS.
60
*******************************************************************************/
62
62
* Author: chris grzegorczyk <grze@eucalyptus.com>
159
158
String serviceTag;
161
160
String launchIndex;
162
Integer networkIndex;
163
161
ArrayList<String> groupNames = new ArrayList<String>();
164
162
ArrayList<AttachedVolume> volumes = new ArrayList<AttachedVolume>();
166
163
String placement;
168
165
ArrayList<String> productCodes = new ArrayList<String>();
171
168
public String toString( ) {
172
169
return String.format(
173
"VmInfo [groupNames=%s, imageId=%s, instanceId=%s, instanceType=%s, kernelId=%s, keyValue=%s, launchIndex=%s, launchTime=%s, netParams=%s, networkIndex=%s, ownerId=%s, placement=%s, productCodes=%s, ramdiskId=%s, reservationId=%s, serviceTag=%s, stateName=%s, userData=%s, volumes=%s]",
174
this.groupNames, this.imageId, this.instanceId, this.instanceType, this.kernelId,
175
this.keyValue, this.launchIndex, this.launchTime, this.netParams, this.networkIndex,
176
this.ownerId, this.placement, this.productCodes, this.ramdiskId, this.reservationId,
177
this.serviceTag, this.stateName, this.userData, this.volumes );
170
"VmInfo [groupNames=%s, imageId=%s, instanceId=%s, instanceType=%s, kernelId=%s, keyValue=%s, launchIndex=%s, launchTime=%s, netParams=%s, ownerId=%s, placement=%s, productCodes=%s, ramdiskId=%s, reservationId=%s, serviceTag=%s, stateName=%s, userData=%s, volumes=%s]",
171
this.groupNames, this.imageId, this.instanceId, this.instanceType, this.kernelId,
172
this.keyValue, this.launchIndex, this.launchTime, this.netParams,
173
this.ownerId, this.placement, this.productCodes, this.ramdiskId, this.reservationId,
174
this.serviceTag, this.stateName, this.userData, this.volumes );
183
180
public class VmRunType extends EucalyptusMessage {
185
182
/** these are for more convenient binding later on but really should be done differently... sigh **/
187
184
String reservationId, userData;
188
185
int min, max, vlan, launchIndex;
190
187
VmImageInfo imageInfo;
191
188
VmTypeInfo vmTypeInfo;
192
189
VmKeyInfo keyInfo;
194
191
List<String> instanceIds = new ArrayList<String>();
195
192
List<String> macAddresses = new ArrayList<String>();
196
193
List<String> networkNames = new ArrayList<String>();
197
194
ArrayList<String> networkIndexList = new ArrayList<String>();
202
def VmRunType(final RunInstancesType request,
203
final String reservationId, final String userData, final int amount,
204
final VmImageInfo imageInfo, final VmTypeInfo vmTypeInfo, final VmKeyInfo keyInfo,
205
final List<String> instanceIds, final List<String> macAddresses,
206
final int vlan, final List<String> networkNames, final List<String> networkIndexList ) {
207
this.correlationId = request.correlationId;
208
this.userId = request.userId;
209
this.effectiveUserId = request.effectiveUserId;
199
def VmRunType(final String reservationId, final String userData, final int amount,
200
final VmImageInfo imageInfo, final VmTypeInfo vmTypeInfo, final VmKeyInfo keyInfo,
201
final List<String> instanceIds, final List<String> macAddresses,
202
final int vlan, final List<String> networkNames, final List<String> networkIndexList ) {
210
203
this.reservationId = reservationId;
211
204
this.userData = userData;
212
205
this.min = amount;
220
213
this.networkNames = networkNames;
221
214
this.networkIndexList = networkIndexList;
224
217
def VmRunType(RunInstancesType request) {
225
218
this.effectiveUserId = request.effectiveUserId;
226
219
this.correlationId = request.correlationId;
227
220
this.userId = request.userId;
230
223
public VmRunType(RunInstancesType request, String reservationId, String userData,
231
int amount, VmImageInfo imageInfo, VmTypeInfo vmTypeInfo, VmKeyInfo keyInfo,
232
ArrayList<String> instanceIds, List<String> macAddresses, int vlan,
233
List<String> networkNames, ArrayList<String> networkIndexList) {
234
this.correlationId = request.correlationId;
235
this.userId = request.userId;
236
this.effectiveUserId = request.effectiveUserId;
237
this.reservationId = reservationId;
238
this.userData = userData;
242
this.imageInfo = imageInfo;
243
this.vmTypeInfo = vmTypeInfo;
244
this.keyInfo = keyInfo;
245
this.instanceIds = instanceIds;
246
this.macAddresses = macAddresses;
247
this.networkNames = networkNames;
248
this.networkIndexList = networkIndexList;
224
int amount, VmImageInfo imageInfo, VmTypeInfo vmTypeInfo, VmKeyInfo keyInfo,
225
ArrayList<String> instanceIds, List<String> macAddresses, int vlan,
226
List<String> networkNames, ArrayList<String> networkIndexList) {
227
this.correlationId = request.correlationId;
228
this.userId = request.userId;
229
this.effectiveUserId = request.effectiveUserId;
230
this.reservationId = reservationId;
231
this.userData = userData;
235
this.imageInfo = imageInfo;
236
this.vmTypeInfo = vmTypeInfo;
237
this.keyInfo = keyInfo;
238
this.instanceIds = instanceIds;
239
this.macAddresses = macAddresses;
240
this.networkNames = networkNames;
241
this.networkIndexList = networkIndexList;
252
245
public String toString( ) {
253
246
return String.format(
254
"VmRunType [imageInfo=%s, instanceIds=%s, keyInfo=%s, launchIndex=%s, macAddresses=%s, max=%s, min=%s, networkIndexList=%s, networkNames=%s, reservationId=%s, userData=%s, vlan=%s, vmTypeInfo=%s]",
255
this.imageInfo, this.instanceIds, this.keyInfo, this.launchIndex, this.macAddresses,
256
this.max, this.min, this.networkIndexList, this.networkNames, this.reservationId,
257
this.userData, this.vlan, this.vmTypeInfo );
247
"VmRunType [imageInfo=%s, instanceIds=%s, keyInfo=%s, launchIndex=%s, macAddresses=%s, max=%s, min=%s, networkIndexList=%s, networkNames=%s, reservationId=%s, userData=%s, vlan=%s, vmTypeInfo=%s]",
248
this.imageInfo, this.instanceIds, this.keyInfo, this.launchIndex, this.macAddresses,
249
this.max, this.min, this.networkIndexList, this.networkNames, this.reservationId,
250
this.userData, this.vlan, this.vmTypeInfo );
263
256
public class VmImageInfo {
267
260
String ramdiskId;
281
274
this.ramdiskLocation = ramdiskLocation;
282
275
this.productCodes = productCodes;
288
282
public String toString( ) {
289
283
return String.format(
290
"VmImageInfo [ancestorIds=%s, imageId=%s, imageLocation=%s, kernelId=%s, kernelLocation=%s, productCodes=%s, ramdiskId=%s, ramdiskLocation=%s, size=%s]",
291
this.ancestorIds, this.imageId, this.imageLocation, this.kernelId, this.kernelLocation,
292
this.productCodes, this.ramdiskId, this.ramdiskLocation, this.size );
284
"VmImageInfo [ancestorIds=%s, imageId=%s, imageLocation=%s, kernelId=%s, kernelLocation=%s, productCodes=%s, ramdiskId=%s, ramdiskLocation=%s, size=%s]",
285
this.ancestorIds, this.imageId, this.imageLocation, this.kernelId, this.kernelLocation,
286
this.productCodes, this.ramdiskId, this.ramdiskLocation, this.size );
298
292
public class VmKeyInfo {
300
294
String name = "";
301
295
String value = "";
302
296
String fingerprint = "";
304
298
def VmKeyInfo(final name, final value, final fingerprint) {
305
299
this.name = name;
306
300
this.value = value;
307
301
this.fingerprint = fingerprint;
313
308
public String toString( ) {
314
309
return String.format( "VmKeyInfo [fingerprint=%s, name=%s, value=%s]", this.fingerprint, this.name, this.value );
320
315
public class Network implements HasName {
393
389
public Integer allocateNetworkIndex( String cluster ) {
394
390
Integer nextIndex = this.availableNetworkIndexes.pollFirst( );
395
391
if( nextIndex == null ) {
396
LOG.debug( EventRecord.caller( this.getClass( ), EucalyptusProperties.TokenState.preallocate, "network=${this.name}","cluster=${cluster}","networkIndex=${nextIndex}") );
392
EventRecord.caller( this.getClass( ), EventType.TOKEN_RESERVED, "network=${this.name}","cluster=${cluster}","networkIndex=${nextIndex}").debug( );
398
394
this.assignedNetworkIndexes.add( nextIndex );
399
395
this.getClusterToken( cluster )?.getIndexes().add( nextIndex );
400
LOG.debug( EventRecord.caller( this.getClass( ), EucalyptusProperties.TokenState.preallocate, "network=${this.name}","cluster=${cluster}","networkIndex=${nextIndex}") );
396
EventRecord.caller( this.getClass( ), EventType.TOKEN_RESERVED, "network=${this.name}","cluster=${cluster}","networkIndex=${nextIndex}").debug( );
402
398
return nextIndex;
405
401
public void returnNetworkIndexes( Collection<Integer> indexes ) {
406
402
indexes.each{ this.returnNetworkIndex( it ); };
407
403
LOG.debug( this.toString( ) );
410
406
public void returnNetworkIndex( Integer index ) {
411
LOG.debug( EventRecord.caller( this.getClass( ), EucalyptusProperties.TokenState.returned, "network=${this.name}","networkIndex=${index}") );
407
EventRecord.caller( this.getClass( ), EventType.TOKEN_RETURNED, "network=${this.name}","networkIndex=${index}").debug( );
412
408
this.assignedNetworkIndexes.remove( index );
413
409
this.clusterTokens.values().each {
414
410
it.getIndexes().remove( index );
439
435
return !this.clusterTokens.values( ).isEmpty( );
442
438
public void removeToken(String cluster) {
443
439
this.clusterTokens.remove(cluster);
446
442
public boolean isPeer( String peerName, String peerNetworkName ) {
447
443
return (Boolean) this.rules.collect{ pf -> pf.peers.contains( new VmNetworkPeer( peerName, peerNetworkName )) }.max();
450
446
public int compareTo(final Object o) {
451
447
Network that = (Network) o;
452
448
return this.getName().compareTo(that.getName());
456
452
public String toString( ) {
457
return String.format(
458
"Network [availableNetworkIndexes=%s, assignedNetworkIndexes=%s, name=%s, networkName=%s, clusterTokens=%s, rules=%s, userName=%s]",
459
this.availableNetworkIndexes, this.assignedNetworkIndexes, this.name, this.networkName, this.clusterTokens, this.rules,
453
return String.format("Network [available=%s, assigned=%s, name=%s, networkName=%s, clusterTokens=%s, rules=%s, userName=%s]",
454
LogUtil.rangedIntegerList( this.availableNetworkIndexes ), LogUtil.rangedIntegerList( this.assignedNetworkIndexes ),
455
this.name, this.networkName, this.clusterTokens, this.rules, this.userName );
466
461
public class NetworkToken implements Comparable {
468
463
String networkName;
471
466
NavigableSet<Integer> indexes = new ConcurrentSkipListSet<Integer>( );
475
470
def NetworkToken(final String cluster, final String userName, final String networkName, final int vlan ) {
476
471
this.networkName = networkName;
477
472
this.cluster = cluster;
485
480
if ( this.is( o ) ) return true;
486
481
if ( !(o instanceof NetworkToken) ) return false;
487
482
NetworkToken that = (NetworkToken) o;
489
484
if ( !cluster.equals(that.cluster) ) return false;
490
485
if ( !networkName.equals(that.networkName) ) return false;
491
486
if ( !userName.equals(that.userName) ) return false;
500
495
result = networkName.hashCode();
501
496
result = 31 * result + cluster.hashCode();
502
497
result = 31 * result + userName.hashCode();
509
504
public int compareTo(Object o) {
510
505
NetworkToken that = (NetworkToken) o;
511
506
return (!this.cluster.equals(that.cluster) && (this.getVlan().equals( that.getVlan() ) ) ) ? this.getVlan() - that.getVlan() : this.cluster.compareTo(that.cluster);
515
510
public String toString( ) {
516
511
return String.format( "NetworkToken [cluster=%s, indexes=%s, name=%s, networkName=%s, userName=%s, vlan=%s]",
517
this.cluster, this.indexes, this.name, this.networkName, this.userName, this.vlan);
512
this.cluster, this.indexes, this.name, this.networkName, this.userName, this.vlan);
521
516
public class ResourceToken implements Comparable {
524
519
String correlationId;
568
563
result = 31 * result + creationTime.hashCode();
573
568
public int compareTo(final Object o) {
574
569
ResourceToken that = (ResourceToken) o;
575
570
return this.getSequenceNumber() - that.getSequenceNumber();
579
574
public String toString( ) {
580
575
return String.format(
581
"ResourceToken [addresses=%s, amount=%s, cluster=%s, correlationId=%s, creationTime=%s, instanceIds=%s, networkTokens=%s, sequenceNumber=%s, userName=%s, vmType=%s]",
582
this.addresses, this.amount, this.cluster, this.correlationId, this.creationTime,
583
this.instanceIds, this.networkTokens, this.sequenceNumber, this.userName, this.vmType );
576
"ResourceToken [addresses=%s, amount=%s, cluster=%s, correlationId=%s, creationTime=%s, instanceIds=%s, networkTokens=%s, sequenceNumber=%s, userName=%s, vmType=%s]",
577
this.addresses, this.amount, this.cluster, this.correlationId, this.creationTime,
578
this.instanceIds, this.networkTokens, this.sequenceNumber, this.userName, this.vmType );
588
583
public class NodeInfo implements Comparable {
590
585
String serviceTag;
593
588
NodeCertInfo certs = new NodeCertInfo();
594
589
NodeLogInfo logs = new NodeLogInfo();
596
591
def NodeInfo(final String serviceTag) {
597
592
this.name = (new URI(serviceTag)).getHost();
598
593
this.serviceTag = serviceTag;