Java 如何以编程方式在azure云服务中设置输入端点?

Java 如何以编程方式在azure云服务中设置输入端点?,java,azure,sdk,Java,Azure,Sdk,我正在azure上创建一个云服务,其中包含2个使用java sdk的虚拟机。服务已成功创建并正在运行,但当我检查新创建的云服务的输入端点时,发现没有端点。但我正在虚拟机创建中设置端点细节。下面是代码片段 ArrayList<InputEndpoint> endPointList = new ArrayList<InputEndpoint>(); InputEndpoint endPoint = new InputEndpoint(); endPoint.setName

我正在azure上创建一个云服务,其中包含2个使用java sdk的虚拟机。服务已成功创建并正在运行,但当我检查新创建的云服务的输入端点时,发现没有端点。但我正在虚拟机创建中设置端点细节。下面是代码片段

ArrayList<InputEndpoint> endPointList = new ArrayList<InputEndpoint>();

InputEndpoint endPoint = new InputEndpoint();

endPoint.setName("ssh");

endPoint.setPort(22);

endPoint.setLocalPort(22);

endPoint.setProtocol("tcp");

endPointList.add(endPoint);


configurationSetList = new ArrayList<ConfigurationSet>();

configurationSet = new ConfigurationSet();


configurationSet.setConfigurationSetType(ConfigurationSetTypes.LINUXPROVISIONINGCONFIGURATION);

configurationSet.setComputerName(roleName);

configurationSet.setUserName(userName);

configurationSet.setUserPassword(pswd);
                        configurationSet.setAdminPassword(adminUserPassword);

configurationSet.setAdminUserName(adminUserName);

configurationSet.setEnableAutomaticUpdates(false);

configurationSet.setHostName(clusterName + ".cloudapp.net");

configurationSet.setInputEndpoints(endPointList);

configurationSetList.add(configurationSet);


ArrayList<Role> roleList = new ArrayList<Role>();

Role role = new Role();

role.setRoleName(roleName);

role.setRoleType(VirtualMachineRoleType.PersistentVMRole.toString());

role.setRoleSize(VirtualMachineRoleSize.SMALL);

role.setProvisionGuestAgent(true);

role.setConfigurationSets(configurationSetList);

role.setOSVirtualHardDisk(oSVirtualHardDisk);

roleList.add(role);

如果我做错了,请告诉我。

您需要创建其他配置集

ConfigurationSet configurationSetForNetwork = new ConfigurationSet(); 

configurationSetForNetwork.setConfigurationSetType(ConfigurationSetTypes.NETWORKCONFIGURATION);
configurationSetList.add(configurationSetForNetwork);
configurationSetList.add(otherConfigurationSet...);
...
configurationSetForNetwork.setInputEndpoints(endPointList);
//If you need the one public ip
PublicIP publicIP = new PublicIP();
publicIP.setName(vitualNetworkName);//VNET Name
ArrayList publicIPS = new ArrayList();
publicIPS.add(publicIP);
configurationSetForNetwork.setPublicIPs(publicIPS);

我可以使用更新调用设置输入端点。一旦我创建了虚拟机,我调用update方法来设置输入端点。但是现在有另一个问题。即使输入端点设置正确,我也无法在某些VM上执行ssh。事实上是一致的。有些时间起作用,有些时间不起作用。我可以在azure portal上查看端点的详细信息,一旦我使用azure portal在特定VM上重新启动,一切正常。我正在使用JavaSDK创建云服务和虚拟机,并设置输入端点。我在检查VM的状态后设置端点。一旦它变成ReadyRole,我就设置端点,然后重新启动VM。不过,我不确定是否需要重新启动。