当前位置: 首页>>代码示例>>Java>>正文


Java OpenStackResponseException类代码示例

本文整理汇总了Java中com.woorea.openstack.base.client.OpenStackResponseException的典型用法代码示例。如果您正苦于以下问题:Java OpenStackResponseException类的具体用法?Java OpenStackResponseException怎么用?Java OpenStackResponseException使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


OpenStackResponseException类属于com.woorea.openstack.base.client包,在下文中一共展示了OpenStackResponseException类的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: delete

import com.woorea.openstack.base.client.OpenStackResponseException; //导入依赖的package包/类
@Override
public void delete(String groupId) {

    String endpoint = WooreaAuths.getStrageEndpoint(authRepository.findById(groupId));
    Client client = createClient();
    Response response = client.target(endpoint).path(groupId).request()
        .header(X_AUTH_TOKEN, provider.getToken(groupId)).accept(MediaType.APPLICATION_JSON).get();
    if (!isSuccess(response)) {
        throw new OpenStackResponseException(response.getStatusInfo().getReasonPhrase(), response.getStatus()); 
    }
    List<File> files = response.readEntity(new GenericType<List<File>>() {});
    for (File file : files) {
        response = client.target(endpoint).path(groupId).path(file.getName()).request()
            .header(X_AUTH_TOKEN, provider.getToken(groupId)).accept(MediaType.APPLICATION_JSON).delete();
        if (!isSuccess(response)) {
            throw new OpenStackResponseException(response.getStatusInfo().getReasonPhrase(), response.getStatus()); 
        }
    }
    response = client.target(endpoint).path(groupId).request().header(X_AUTH_TOKEN, provider.getToken(groupId)).delete();
    if (!isSuccess(response)) {
        throw new OpenStackResponseException(response.getStatusInfo().getReasonPhrase(), response.getStatus()); 
    }
}
 
开发者ID:ctc-g,项目名称:rack-java,代码行数:24,代码来源:WooreaFileSystemConnector.java

示例2: toResponse

import com.woorea.openstack.base.client.OpenStackResponseException; //导入依赖的package包/类
/**
 * {@inheritDoc}
 */
@Override
public Response toResponse(OpenStackResponseException exception) {
    if (L.isDebugEnabled()) {
        L.debug("予期しない例外が発生しました。");
    }
    ErrorMessage error = ErrorMessages.create()
        .status(500)
        .id()
        .code(ErrorCode.UNKNOWN_ERROR.code())
        .resolve()
        .get();
    L.error("予期しない例外が発生しました。", exception);
    return Response.status(500)
        .entity(error)
        .type(MediaType.APPLICATION_JSON)
        .build();
}
 
开发者ID:ctc-g,项目名称:rack-java,代码行数:21,代码来源:OpenStackExceptionMapper.java

示例3: getAccess

import com.woorea.openstack.base.client.OpenStackResponseException; //导入依赖的package包/类
private Access getAccess(Tenant tenant) {
   	if (getAccess().getToken().getTenant().getId() == tenant.getId()) {
   		return getAccess();
   	}

   	// Use our existing token to authenticate with Keystone to create new tenant-specific tokens
	Authentication tokenAuth = new TokenAuthentication(getAccess().getToken().getId());

	// Now, *try* to create a NEW token on this tenant.
	// NOTE: even "admin" users are not authorized on every tenant, though
	//    oddly they are authorized to add themselves to tenants!?
	try {
		return keystone.tokens()
				.authenticate(tokenAuth)
				.withTenantId(tenant.getId())
				.execute();
	} catch (OpenStackResponseException err) {
		System.out.println("\nFailed to access tenant \"" + tenant.getName() + "\" - user must not have authorization for this tenant!");
		return null;  // Cannot access nova
	}
}
 
开发者ID:jdutton,项目名称:java-openstack-sdk-cli-example,代码行数:22,代码来源:Cli.java

示例4: testDeleteVolumeType

import com.woorea.openstack.base.client.OpenStackResponseException; //导入依赖的package包/类
@Test
public void testDeleteVolumeType() throws InterruptedException {
    final String newVolumeTypeId = createVolumeType("test_delete").getId();

    deleteVolumeType(newVolumeTypeId);
    try {
        getVolumeTypeById(newVolumeTypeId);
    } catch (OpenStackResponseException e) {
        Assert.assertEquals(e.getStatus(), HttpStatus.SC_NOT_FOUND);
    }
}
 
开发者ID:danielerez,项目名称:openstack-java-sdk-cinder-tests,代码行数:12,代码来源:CinderVolumeTypesTest.java

示例5: testDeleteSnapshot

import com.woorea.openstack.base.client.OpenStackResponseException; //导入依赖的package包/类
@Test(timeout = TIMEOUT)
public void testDeleteSnapshot() throws InterruptedException {
    final String volumeId = createVolume("test_delete").getId();

    Timer timer = new Timer();
    timer.scheduleAtFixedRate(new TimerTask() {
        Snapshot snapshot = null;

        public void run() {
            if (snapshot == null) {
                Volume volume = getVolumeById(volumeId);
                switch (CinderVolumeStatus.forValue(volume.getStatus())) {
                    case Available:
                        snapshot = createSnapshot("test_create", volume.getId());
                        break;
                }
            } else {
                try {
                    snapshot = getSnapshotById(snapshot.getId());
                    switch (CinderVolumeStatus.forValue(snapshot.getStatus())) {
                        case Available:
                            deleteSnaphsot(snapshot.getId());
                            break;
                    }
                } catch (OpenStackResponseException e) {
                    cancel();
                    Assert.assertEquals(e.getStatus(), HttpStatus.SC_NOT_FOUND);
                    completedMap.put("testDeleteSnapshot", true);
                }
            }
        }
    }, 0, 1000);
    while (completedMap.get("testDeleteSnapshot") == null);
}
 
开发者ID:danielerez,项目名称:openstack-java-sdk-cinder-tests,代码行数:35,代码来源:CinderSnapshotsTest.java

示例6: testDeleteVolume

import com.woorea.openstack.base.client.OpenStackResponseException; //导入依赖的package包/类
@Test(timeout = TIMEOUT)
public void testDeleteVolume() throws InterruptedException {
    final String newVolumeId = createVolume("test_delete").getId();
    Timer timer = new Timer();
    timer.scheduleAtFixedRate(new TimerTask() {
        public void run() {
            try {
                Volume volume = getVolumeById(newVolumeId);
                switch (CinderVolumeStatus.forValue(volume.getStatus())) {
                    case Available:
                        deleteVolume(newVolumeId);
                        break;
                    case Deleting:
                        log.info(String.format("Deleting volume %s", newVolumeId));
                        break;
                    case ErrorDeleting:
                        log.error(String.format("Failed to delete volume %s", newVolumeId));
                        cancel();
                        completedMap.put("testDeleteVolume", true);
                        break;
                }
            } catch (OpenStackResponseException e) {
                cancel();
                Assert.assertEquals(e.getStatus(), HttpStatus.SC_NOT_FOUND);
                completedMap.put("testDeleteVolume", true);
            }
        }
    }, 0, 1000);
    while (completedMap.get("testDeleteVolume") == null);
}
 
开发者ID:danielerez,项目名称:openstack-java-sdk-cinder-tests,代码行数:31,代码来源:CinderVolumesTest.java

示例7: getHypervisors

import com.woorea.openstack.base.client.OpenStackResponseException; //导入依赖的package包/类
private ArrayList<String> getHypervisors(){
	Access access = getAccessWithTenantId();
    
    Nova novaClient = new Nova(NOVA_ENDPOINT.concat("/").concat(TENANT_ID));
    novaClient.token(access.getToken().getId());

    OpenStackRequest<String> request = new OpenStackRequest<String>(
        novaClient, HttpMethod.GET, "/os-hypervisors", null,
        String.class);
    	    
    String hypervisors = null;
    try{
    	hypervisors = novaClient.execute(request);
    } catch(OpenStackResponseException e){
      LOGGER.log(Level.SEVERE, e.getMessage());
      return null;
    }
    ArrayList<String> hypervisors_list = new ArrayList<String>() ;
    try{
	    JSONParser parser = new JSONParser() ;	
		JSONObject object = (JSONObject) parser.parse(hypervisors) ;
	    JSONArray json_hypervisors = (JSONArray) object.get("hypervisors") ;
	    for (Object o : json_hypervisors){
	    	JSONObject obj = (JSONObject) o ;
	    	hypervisors_list.add(obj.get("hypervisor_hostname").toString()) ;
	    }
    }catch(ParseException pe){
    	LOGGER.log(Level.WARNING,"Cannot parse result.");
   	}
    
    return hypervisors_list;
}
 
开发者ID:FITeagle,项目名称:adapters,代码行数:33,代码来源:OpenstackClient.java

示例8: create

import com.woorea.openstack.base.client.OpenStackResponseException; //导入依赖的package包/类
@Override
public String create(String groupId) {

    String endpoint = WooreaAuths.getStrageEndpoint(authRepository.findById(groupId));
    Response response = createClient().target(endpoint).path(groupId).request()
        .header(X_AUTH_TOKEN, provider.getToken(groupId)).put(Entity.entity("", MediaType.TEXT_PLAIN));
    if (!isSuccess(response)) {
        throw new OpenStackResponseException(response.getStatusInfo().getReasonPhrase(), response.getStatus()); 
    }
    return provider.getToken(groupId);
}
 
开发者ID:ctc-g,项目名称:rack-java,代码行数:12,代码来源:WooreaFileSystemConnector.java

示例9: list

import com.woorea.openstack.base.client.OpenStackResponseException; //导入依赖的package包/类
@Override
public FileSystem list(String groupId) {

    String endpoint = WooreaAuths.getStrageEndpoint(authRepository.findById(groupId));
    Response response = createClient().target(endpoint).path(groupId).request()
        .header(X_AUTH_TOKEN, provider.getToken(groupId)).accept(MediaType.APPLICATION_JSON).get();
    if (!isSuccess(response)) {
        throw new OpenStackResponseException(response.getStatusInfo().getReasonPhrase(), response.getStatus()); 
    }
    List<File> files = response.readEntity(new GenericType<List<File>>() {});
    FileSystem fs = new FileSystem();
    fs.setToken(provider.getToken(groupId));
    fs.setFiles(files);
    return fs;
}
 
开发者ID:ctc-g,项目名称:rack-java,代码行数:16,代码来源:WooreaFileSystemConnector.java

示例10: AuthenticationCriteria

import com.woorea.openstack.base.client.OpenStackResponseException; //导入依赖的package包/类
@Test
public void 登録されていないユーザの場合はエラーが発生する() {
    thrown.expect(OpenStackResponseException.class);
    AuthenticationCriteria criteria = new AuthenticationCriteria();
    criteria.setUsername("user9999");
    criteria.setPassword("user9999");
    connector.authentication(criteria);
}
 
开发者ID:ctc-g,项目名称:rack-java,代码行数:9,代码来源:WooreaAuthConnectorTest.java

示例11: getEntity

import com.woorea.openstack.base.client.OpenStackResponseException; //导入依赖的package包/类
@Override
public <T> T getEntity(Class<T> returnType) {
	if(response.getStatus() >= 400) {
		throw new OpenStackResponseException(response.getStatusInfo().getReasonPhrase(),
				response.getStatusInfo().getStatusCode());
	}
	return response.readEntity(returnType);
}
 
开发者ID:CIETstudents,项目名称:openstack-maven-CIET-students,代码行数:9,代码来源:JaxRs20Response.java

示例12: getEntity

import com.woorea.openstack.base.client.OpenStackResponseException; //导入依赖的package包/类
@Override
public <T> T getEntity(Class<T> returnType) {
	if(response.getStatus() >= 400) {
		throw new OpenStackResponseException(response.getClientResponseStatus().getReasonPhrase(), 
				response.getStatus());
	}
	if(response.hasEntity() && returnType != null && Void.class != returnType) {
		return response.getEntity(returnType);
	} else {
		return null;
	}
}
 
开发者ID:CIETstudents,项目名称:openstack-maven-CIET-students,代码行数:13,代码来源:JerseyResponse.java

示例13: getHostName

import com.woorea.openstack.base.client.OpenStackResponseException; //导入依赖的package包/类
public String getHostName(String vm_id){
	ArrayList<String> hypervisors = getHypervisors() ;
	
	Access access = getAccessWithTenantId();
    
    Nova novaClient = new Nova(NOVA_ENDPOINT.concat("/").concat(TENANT_ID));
    novaClient.token(access.getToken().getId());
    
    String result = null ;
    for (String hostname : hypervisors){
    	OpenStackRequest<String> request = new OpenStackRequest<String>(
    			novaClient, HttpMethod.GET, "/os-hypervisors/" + hostname + "/servers", null,
    	        String.class);
    	String servers = null;
    	
    	try{
	    	servers = novaClient.execute(request);
	    } catch(OpenStackResponseException e){
	      LOGGER.log(Level.SEVERE, e.getMessage());
	      return null;
	    }
    	
    	try{
	    	JSONParser parser = new JSONParser() ;			
			JSONObject object = (JSONObject) parser.parse(servers) ;
		    JSONArray json_servers = (JSONArray) object.get("hypervisors") ;
		    JSONObject obj = (JSONObject) json_servers.get(0) ;
		    JSONArray arr = (JSONArray) obj.get("servers") ;
			for (Object o : arr){
				JSONObject ob = (JSONObject) o ;
				if(ob.get("uuid").toString().matches(vm_id)){
					result = hostname ;
					return result ;
				}
			}
    	}catch(ParseException pe){
    		LOGGER.log(Level.WARNING,"Cannot parse result.");
    	}
    }
    return result;
}
 
开发者ID:FITeagle,项目名称:adapters,代码行数:42,代码来源:OpenstackClient.java


注:本文中的com.woorea.openstack.base.client.OpenStackResponseException类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。