2016-08-09 7 views
0

スケールグループを編集しようとしていますが、Vlansを編集するときに例外が返されます。これは私がテストしたコードです。編集方法はオブジェクトの作成と同じですが、editObject()と一緒にgroupIdとpolicyIdを追加しました。ご不明な点がございましたら教えてください。 43:あなたのSLのスケールオブジェクトを編集する

RestApiClient client = getSoftlayerClient(); 
    groupService = Group.service(client, group.getGroupId()); 

    /** 
    * Network Vlans 
    */ 
    Long[] networkVlans = { group.getPublicVlanId(), group.getPrivateVlanId() }; 

    /** 
    * Define SoftLayer_Scale_Group object that you wish to create 
    */ 
    Group templateObject = new Group(); 
    templateObject.setName(group.getGroupName()); 
    templateObject.setRegionalGroupId(group.getRegionId()); 
    templateObject.setTerminationPolicyId(group.gettPolicyId()); 

    // Unit : SEC, MIN, HOUR, DAY 
    templateObject.setCooldown(getSec(group.getCooldownPeriod(), group.getCooldownUnit())); 

    templateObject.setMaximumMemberCount(group.getMaxMember()); 
    templateObject.setMinimumMemberCount(group.getMinMember()); 

    templateObject.setSuspendedFlag(false); 

    // Define SoftLayer_Virtual_Guest 
    Guest virtualGuestMemberTemplate = new Guest(); 
    virtualGuestMemberTemplate.setHostname(group.getHostName()); 
    virtualGuestMemberTemplate.setDomain(group.getDomain()); 
    virtualGuestMemberTemplate.setMaxMemory(group.getMaxMemory()); 
    virtualGuestMemberTemplate.setStartCpus(group.getStartCpu()); 

    List<AutoScaleStorageVO> storageList = group.getStorageList(); 

    for (AutoScaleStorageVO storage : storageList) { 
     Device block = new Device(); 
     block.setDevice(storage.getDiskOrder()); 
     Image image = new Image(); 
     image.setCapacity(storage.getCapacity()); 
     block.setDiskImage(image); 
     virtualGuestMemberTemplate.getBlockDevices().add(block); 
    } 

    // Define Location 

    if (group.getDatacenter() != "") { 
     Location location = new Location(); 
     location.setName(group.getDatacenter()); 
     virtualGuestMemberTemplate.setDatacenter(location); 
    } 

    // Define Hourly billing and local disk 
    virtualGuestMemberTemplate.setHourlyBillingFlag(true); 
    if (storageList.get(0).getDiskType().equals("LOCAL")) { 
     virtualGuestMemberTemplate.setLocalDiskFlag(true); 
    } else { 
     virtualGuestMemberTemplate.setLocalDiskFlag(false); 
    } 

    // Network Components 
    Component networkComponent = new Component(); 
    networkComponent.setMaxSpeed(group.getMaxSpeed()); 

    virtualGuestMemberTemplate.getNetworkComponents().add(networkComponent); 

    // OS 
    virtualGuestMemberTemplate.setOperatingSystemReferenceCode(group.getOsCode()); 

    virtualGuestMemberTemplate.setPrivateNetworkOnlyFlag(group.isPrivateOnly()); 

    // Ssh key 
    if (group.getSshKeyId() != null) { 
     Key newKey = new Key(); 
     newKey.setId(group.getSshKeyId()); 
     virtualGuestMemberTemplate.getSshKeys().add(newKey); 
    } 

    // Provision Script 
    if (group.getPostInstallUri() != "") { 
     virtualGuestMemberTemplate.setPostInstallScriptUri(group.getPostInstallUri()); 
    } 

    // Network Vlans : Edit vlans with new vlanIds. 

     for (int i = 0; i <= networkVlans.length; i++) { 
      Vlan vlan = new Vlan(); 
      vlan.setNetworkVlanId(networkVlans[i]); 
      templateObject.getNetworkVlans().add(vlan); 
     } 

    // Adding Virtual Guest member template to the template 
    templateObject.setVirtualGuestMemberTemplate(virtualGuestMemberTemplate); 

Boolean result = groupService.editObject(templateObject); 

20ありがとう21.814 [HTTP-バイオ8181-EXEC-2] ERROR - オートスケールグループの例外を編集することができませんでした:2

+0

ときあなたのコードをコピーしてください少なくともあなたの輸入を追加してください私はあなたがそれを把握しようと多くの時間を無駄に使用しているどのパッケージを知っていません –

答えて

0

これを試してみてください:

import java.util.ArrayList; 
import java.util.List; 

import com.google.gson.Gson; 
import com.softlayer.api.*; 
import com.softlayer.api.service.scale.network.Vlan; 
import com.softlayer.api.service.scale.Group; 


public class EditScale { 

    private static String user = "set me"; 

    private static String apiKey = "set me"; 

    private static ApiClient client = new RestApiClient().withCredentials(user, apiKey).withLoggingEnabled(); 

    private static Long idScaleGroup = new Long(11111); 

    public static void main(String[] args) { 

     Group.Service scaleGroupService = Group.service(client, idScaleGroup); 
     scaleGroupService.setMask("mask[networkVlans]"); 


     Group scaleGroupEdit = scaleGroupService.getObject(); 

     for(Vlan v:scaleGroupEdit.getNetworkVlans()){ 
      Vlan.Service vlanService = Vlan.service(client, v.getId()); 
      vlanService.deleteObject(); 
     } 

     Vlan.Service vlanService = Vlan.service(client); 

     Vlan templateObjectPrivate = new Vlan(); 
     templateObjectPrivate.setScaleGroupId(scaleGroupEdit.getId()); 
     templateObjectPrivate.setNetworkVlanId(2222222L); 
     Vlan vlanPrivate = vlanService.createObject(templateObjectPrivate); 

     Vlan templateObjectPublic = new Vlan(); 
     templateObjectPublic.setScaleGroupId(scaleGroupEdit.getId()); 
     templateObjectPublic.setNetworkVlanId(333333L); 
     Vlan vlanPublic = vlanService.createObject(templateObjectPublic); 

     List<Vlan> vlans = new ArrayList<Vlan>(); 
     vlans.add(vlanPrivate); 
     vlans.add(vlanPublic); 

     scaleGroupEdit.getNetworkVlans().clear(); 
     scaleGroupEdit.getNetworkVlans().addAll(vlans); 

     Gson gson = new Gson(); 
     System.out.println(gson.toJson(scaleGroupService.editObject(scaleGroupEdit))); 

    } 

} 
+0

私は実行可能コードを掲載したが、 –

+0

それは動作します!、ありがとう:) –

関連する問題