@Test( expectedExceptions = InfrastructureException.class, expectedExceptionsMessageRegExp = "Invalid response.*") public void shouldThrowInfrastructureExceptionWhenResponseParsesToNull() throws Exception { when(httpJsonResponse.asString()).thenReturn("{}"); TenantDataCacheKey cacheKey = new TenantDataCacheKey("token", "che"); cacheLoader.load(cacheKey); }
@Override public UserCheTenantData load(final TenantDataCacheKey cacheKey) throws InfrastructureException { final String namespace = cacheKey.getNamespaceType(); final String responseBody; try { responseBody = getResponseBody(fabric8UserServiceEndpoint, cacheKey.getKeycloakToken()); } catch (ApiException | IOException e) { LOG.error(e.getMessage(), e); throw new InfrastructureException("Exception during the user tenant data retrieval", e); } try { final Gson gson = new Gson(); final UserServicesJsonResponse userServicesData = gson.fromJson(responseBody, UserServicesJsonResponse.class); List<Namespace> namespaces = userServicesData.getNamespaces(); for (Namespace ns : namespaces) { if (namespace.equals(ns.getType())) { UserCheTenantData cheTenantData = new UserCheTenantData( ns.getName(), ns.getClusterUrl(), ns.getClusterAppDomain(), ns.isClusterCapacityExhausted()); UserCheTenantDataValidator.validate(cheTenantData); return cheTenantData; } } } catch (ValidationException | JsonSyntaxException | NullPointerException e) { throw new InfrastructureException( "Invalid response from Fabric8 user services:" + responseBody, e); } if ("user".equals(namespace)) { LOG.error("No namespace with type 'user' was found in the user tenant: {}", responseBody); return new UserCheTenantData("", "", "", false); } throw new InfrastructureException( format( "No namespace with type '%s' was found in the user tenant", cacheKey.getNamespaceType())); }
TenantDataCacheLoader extends CacheLoader<TenantDataCacheKey, UserCheTenantData> { @Override public UserCheTenantData load(final TenantDataCacheKey cacheKey) throws InfrastructureException { final String namespace = cacheKey.getNamespaceType(); final String responseBody; try { responseBody = getResponseBody(fabric8UserServiceEndpoint, cacheKey.getKeycloakToken()); } catch (ApiException | IOException e) { LOG.error(e.getMessage(), e); throw new InfrastructureException("Exception during the user tenant data retrieval", e); } try { final Gson gson = new Gson(); final UserServicesJsonResponse userServicesData = gson.fromJson(responseBody, UserServicesJsonResponse.class); List<Namespace> namespaces = userServicesData.getNamespaces(); for (Namespace ns : namespaces) { if (namespace.equals(ns.getType())) { UserCheTenantData cheTenantData = new UserCheTenantData( ns.getName(), ns.getClusterUrl(), ns.getClusterAppDomain(), ns.isClusterCapacityExhausted()); UserCheTenantDataValidator.validate(cheTenantData); return cheTenantData; } } } catch (ValidationException | JsonSyntaxException | NullPointerException e) { throw new InfrastructureException( "Invalid response from Fabric8 user services:" + responseBody, e); } if ("user".equals(namespace)) { LOG.error("No namespace with type 'user' was found in the user tenant: {}", responseBody); return new UserCheTenantData("", "", "", false); } throw new InfrastructureException( format( "No namespace with type '%s' was found in the user tenant", cacheKey.getNamespaceType())); } }
TenantDataCacheLoader extends CacheLoader<TenantDataCacheKey, UserCheTenantData> { @Override public UserCheTenantData load(final TenantDataCacheKey cacheKey) throws InfrastructureException { final String namespace = cacheKey.getNamespaceType(); final String responseBody; try { responseBody = getResponseBody(fabric8UserServiceEndpoint, cacheKey.getKeycloakToken()); } catch (ApiException | IOException e) { LOG.error(e.getMessage(), e); throw new InfrastructureException("Exception during the user tenant data retrieval", e); } try { final Gson gson = new Gson(); final UserServicesJsonResponse userServicesData = gson.fromJson(responseBody, UserServicesJsonResponse.class); List<Namespace> namespaces = userServicesData.getNamespaces(); for (Namespace ns : namespaces) { if (namespace.equals(ns.getType())) { UserCheTenantData cheTenantData = new UserCheTenantData( ns.getName(), ns.getClusterUrl(), ns.getClusterAppDomain(), ns.isClusterCapacityExhausted()); UserCheTenantDataValidator.validate(cheTenantData); return cheTenantData; } } } catch (ValidationException | JsonSyntaxException | NullPointerException e) { throw new InfrastructureException( "Invalid response from Fabric8 user services:" + responseBody, e); } if ("user".equals(namespace)) { LOG.error("No namespace with type 'user' was found in the user tenant: {}", responseBody); return new UserCheTenantData("", "", "", false); } throw new InfrastructureException( format( "No namespace with type '%s' was found in the user tenant", cacheKey.getNamespaceType())); } @Inject  TenantDataCacheLoader(
      HttpJsonRequestFactory httpJsonRequestFactory,
      @Named("che.fabric8.auth.endpoint") String fabric8AuthEndpoint); }
TenantDataCacheLoader extends CacheLoader<TenantDataCacheKey, UserCheTenantData> { @Override public UserCheTenantData load(final TenantDataCacheKey cacheKey) throws InfrastructureException { final String namespace = cacheKey.getNamespaceType(); final String responseBody; try { responseBody = getResponseBody(fabric8UserServiceEndpoint, cacheKey.getKeycloakToken()); } catch (ApiException | IOException e) { LOG.error(e.getMessage(), e); throw new InfrastructureException("Exception during the user tenant data retrieval", e); } try { final Gson gson = new Gson(); final UserServicesJsonResponse userServicesData = gson.fromJson(responseBody, UserServicesJsonResponse.class); List<Namespace> namespaces = userServicesData.getNamespaces(); for (Namespace ns : namespaces) { if (namespace.equals(ns.getType())) { UserCheTenantData cheTenantData = new UserCheTenantData( ns.getName(), ns.getClusterUrl(), ns.getClusterAppDomain(), ns.isClusterCapacityExhausted()); UserCheTenantDataValidator.validate(cheTenantData); return cheTenantData; } } } catch (ValidationException | JsonSyntaxException | NullPointerException e) { throw new InfrastructureException( "Invalid response from Fabric8 user services:" + responseBody, e); } if ("user".equals(namespace)) { LOG.error("No namespace with type 'user' was found in the user tenant: {}", responseBody); return new UserCheTenantData("", "", "", false); } throw new InfrastructureException( format( "No namespace with type '%s' was found in the user tenant", cacheKey.getNamespaceType())); } @Inject  TenantDataCacheLoader(
      HttpJsonRequestFactory httpJsonRequestFactory,
      @Named("che.fabric8.auth.endpoint") String fabric8AuthEndpoint); @Override UserCheTenantData load(final TenantDataCacheKey cacheKey); }
TenantDataCacheLoader extends CacheLoader<TenantDataCacheKey, UserCheTenantData> { @Override public UserCheTenantData load(final TenantDataCacheKey cacheKey) throws InfrastructureException { final String namespace = cacheKey.getNamespaceType(); final String responseBody; try { responseBody = getResponseBody(fabric8UserServiceEndpoint, cacheKey.getKeycloakToken()); } catch (ApiException | IOException e) { LOG.error(e.getMessage(), e); throw new InfrastructureException("Exception during the user tenant data retrieval", e); } try { final Gson gson = new Gson(); final UserServicesJsonResponse userServicesData = gson.fromJson(responseBody, UserServicesJsonResponse.class); List<Namespace> namespaces = userServicesData.getNamespaces(); for (Namespace ns : namespaces) { if (namespace.equals(ns.getType())) { UserCheTenantData cheTenantData = new UserCheTenantData( ns.getName(), ns.getClusterUrl(), ns.getClusterAppDomain(), ns.isClusterCapacityExhausted()); UserCheTenantDataValidator.validate(cheTenantData); return cheTenantData; } } } catch (ValidationException | JsonSyntaxException | NullPointerException e) { throw new InfrastructureException( "Invalid response from Fabric8 user services:" + responseBody, e); } if ("user".equals(namespace)) { LOG.error("No namespace with type 'user' was found in the user tenant: {}", responseBody); return new UserCheTenantData("", "", "", false); } throw new InfrastructureException( format( "No namespace with type '%s' was found in the user tenant", cacheKey.getNamespaceType())); } @Inject  TenantDataCacheLoader(
      HttpJsonRequestFactory httpJsonRequestFactory,
      @Named("che.fabric8.auth.endpoint") String fabric8AuthEndpoint); @Override UserCheTenantData load(final TenantDataCacheKey cacheKey);  }