AtlasClient extends AtlasBaseClient { public Referenceable getEntity(String guid) throws AtlasServiceException { JSONObject jsonResponse = callAPIWithBodyAndParams(API.GET_ENTITY, null, guid); try { String entityInstanceDefinition = jsonResponse.getString(AtlasClient.DEFINITION); return InstanceSerialization.fromJsonReferenceable(entityInstanceDefinition, true); } catch (JSONException e) { throw new AtlasServiceException(API.GET_ENTITY, e); } } AtlasClient(String[] baseUrl, String cookieName, String value, String path, String domain);  AtlasClient(String[] baseUrl, Cookie cookie);  AtlasClient(String[] baseUrl, String[] basicAuthUserNamePassword);  AtlasClient(String... baseUrls);  AtlasClient(UserGroupInformation ugi, String doAsUser, String... baseUrls); private  AtlasClient(UserGroupInformation ugi, String[] baseUrls); protected  AtlasClient(); @VisibleForTesting  AtlasClient(Configuration configuration, String[] baseUrl, String[] basicAuthUserNamePassword); @VisibleForTesting  AtlasClient(Configuration configuration, String... baseUrls); @VisibleForTesting  AtlasClient(WebResource service, Configuration configuration); WebResource getResource(); List<String> createType(String typeAsJson); List<String> createType(TypesDef typeDef); List<String> createTraitType(String traitName, ImmutableSet<String> superTraits, AttributeDefinition... attributeDefinitions); List<String> createTraitType(String traitName); List<String> updateType(String typeAsJson); List<String> updateType(TypesDef typeDef); List<String> listTypes(); List<String> listTypes(final DataTypes.TypeCategory category); List<String> listTypes(final DataTypes.TypeCategory category, final String superType,
                                  final String notSupertype); TypesDef getType(String typeName); List<String> createEntity(String... entitiesAsJson); List<String> createEntity(Referenceable... entities); List<String> createEntity(Collection<Referenceable> entities); EntityResult updateEntities(Referenceable... entities); EntityResult updateEntities(Collection<Referenceable> entities); EntityResult updateEntityAttribute(final String guid, final String attribute, String value); EntityResult updateEntity(String guid, Referenceable entity); void addTrait(String guid, Struct traitDefinition); void deleteTrait(String guid, String traitName); EntityResult updateEntity(final String entityType, final String uniqueAttributeName,
                                     final String uniqueAttributeValue,
                                     Referenceable entity); EntityResult deleteEntities(final String ... guids); EntityResult deleteEntity(String entityType, String uniqueAttributeName, String uniqueAttributeValue); Referenceable getEntity(String guid); static String toString(JSONArray jsonArray); Referenceable getEntity(final String entityType, final String attribute, final String value); List<String> listEntities(final String entityType); List<String> listTraits(final String guid); List<Struct> listTraitDefinitions(final String guid); Struct getTraitDefinition(final String guid, final String traitName); List<EntityAuditEvent> getEntityAuditEvents(String entityId, short numResults); List<EntityAuditEvent> getEntityAuditEvents(String entityId, String startKey, short numResults); JSONArray search(final String searchQuery, final int limit, final int offset); JSONArray searchByDSL(final String query, final int limit, final int offset); JSONObject searchByFullText(final String query, final int limit, final int offset); JSONObject getInputGraph(String datasetName); JSONObject getOutputGraph(String datasetName); JSONObject getInputGraphForEntity(String entityId); JSONObject getOutputGraphForEntity(String datasetId); JSONObject getSchemaForEntity(String datasetId); @VisibleForTesting JSONObject callAPIWithResource(API api, WebResource resource); @VisibleForTesting WebResource getResource(API api, String ... params); @VisibleForTesting JSONObject callAPIWithBody(API api, Object requestObject); @VisibleForTesting JSONObject callAPIWithBodyAndParams(API api, Object requestObject, String ... params); @VisibleForTesting JSONObject callAPIWithQueryParams(API api, MultivaluedMap<String, String> queryParams); static final String TYPE; static final String TYPENAME; static final String GUID; static final String ENTITIES; static final String GUID_ASSIGNMENTS; static final String DEFINITION; static final String ERROR; static final String STACKTRACE; static final String REQUEST_ID; static final String RESULTS; static final String COUNT; static final String ROWS; static final String DATATYPE; static final String STATUS; static final String EVENTS; static final String START_KEY; static final String NUM_RESULTS; static final String URI_ENTITY; static final String URI_ENTITY_AUDIT; static final String URI_SEARCH; static final String URI_NAME_LINEAGE; static final String URI_LINEAGE; static final String URI_TRAITS; static final String TRAITS; static final String TRAIT_DEFINITIONS; static final String QUERY; static final String LIMIT; static final String OFFSET; static final String QUERY_TYPE; static final String ATTRIBUTE_NAME; static final String ATTRIBUTE_VALUE; static final String SUPERTYPE; static final String NOT_SUPERTYPE; static final String ASSET_TYPE; static final String NAME; static final String DESCRIPTION; static final String OWNER; static final String INFRASTRUCTURE_SUPER_TYPE; static final String DATA_SET_SUPER_TYPE; static final String PROCESS_SUPER_TYPE; static final String PROCESS_ATTRIBUTE_INPUTS; static final String PROCESS_ATTRIBUTE_OUTPUTS; static final String REFERENCEABLE_SUPER_TYPE; static final String QUALIFIED_NAME; static final String REFERENCEABLE_ATTRIBUTE_NAME; static final String UNKNOWN_STATUS; }
@Test public void shouldVerifyServerIsReady() throws AtlasServiceException { setupRetryParams(); AtlasClient atlasClient = new AtlasClient(service, configuration); WebResource.Builder builder = setupBuilder(AtlasClient.API.VERSION, service); ClientResponse response = mock(ClientResponse.class); when(response.getStatus()).thenReturn(Response.Status.OK.getStatusCode()); when(response.getEntity(String.class)).thenReturn("{\"Version\":\"version-rrelease\",\"Name\":\"apache-atlas\"," + "\"Description\":\"Metadata Management and Data Governance Platform over Hadoop\"}"); when(builder.method(AtlasClient.API.VERSION.getMethod(), ClientResponse.class, null)).thenReturn(response); assertTrue(atlasClient.isServerReady()); }
@Test public void shouldGetAdminStatus() throws AtlasServiceException { setupRetryParams(); AtlasClient atlasClient = new AtlasClient(service, configuration); WebResource.Builder builder = setupBuilder(AtlasClient.API.STATUS, service); ClientResponse response = mock(ClientResponse.class); when(response.getStatus()).thenReturn(Response.Status.OK.getStatusCode()); String activeStatus = "{\"Status\":\"Active\"}"; when(response.getEntity(String.class)).thenReturn(activeStatus); when(response.getLength()).thenReturn(activeStatus.length()); when(builder.method(AtlasClient.API.STATUS.getMethod(), ClientResponse.class, null)).thenReturn(response); String status = atlasClient.getAdminStatus(); assertEquals(status, "Active"); }
@Test public void shouldReturnStatusAsUnknownIfJSONIsInvalid() throws AtlasServiceException { setupRetryParams(); AtlasClient atlasClient = new AtlasClient(service, configuration); WebResource.Builder builder = setupBuilder(AtlasClient.API.STATUS, service); ClientResponse response = mock(ClientResponse.class); when(response.getStatus()).thenReturn(Response.Status.OK.getStatusCode()); when(response.getEntity(String.class)).thenReturn("{\"status\":\"Active\"}"); when(builder.method(AtlasClient.API.STATUS.getMethod(), ClientResponse.class, null)).thenReturn(response); String status = atlasClient.getAdminStatus(); assertEquals(status, AtlasClient.UNKNOWN_STATUS); }
@Test public void shouldSelectActiveAmongMultipleServersIfHAIsEnabled() { setupRetryParams(); when(client.resource(UriBuilder.fromUri("http: when(client.resource(UriBuilder.fromUri("http: WebResource.Builder builder = setupBuilder(AtlasClient.API.STATUS, service); ClientResponse firstResponse = mock(ClientResponse.class); when(firstResponse.getStatus()).thenReturn(Response.Status.OK.getStatusCode()); String passiveStatus = "{\"Status\":\"PASSIVE\"}"; when(firstResponse.getEntity(String.class)).thenReturn(passiveStatus); when(firstResponse.getLength()).thenReturn(passiveStatus.length()); ClientResponse secondResponse = mock(ClientResponse.class); when(secondResponse.getStatus()).thenReturn(Response.Status.OK.getStatusCode()); String activeStatus = "{\"Status\":\"ACTIVE\"}"; when(secondResponse.getEntity(String.class)).thenReturn(activeStatus); when(secondResponse.getLength()).thenReturn(activeStatus.length()); when(builder.method(AtlasClient.API.STATUS.getMethod(), ClientResponse.class, null)). thenReturn(firstResponse).thenReturn(firstResponse).thenReturn(firstResponse). thenReturn(secondResponse); AtlasClient atlasClient = new AtlasClient(service, configuration); String serviceURL = atlasClient.determineActiveServiceURL( new String[]{"http: client); assertEquals(serviceURL, "http: }
@Test public void shouldRetryUntilServiceBecomesActive() { setupRetryParams(); when(client.resource(UriBuilder.fromUri("http: WebResource.Builder builder = setupBuilder(AtlasClient.API.STATUS, service); ClientResponse response = mock(ClientResponse.class); when(response.getStatus()).thenReturn(Response.Status.OK.getStatusCode()); when(response.getEntity(String.class)).thenReturn("{\"Status\":\"BECOMING_ACTIVE\"}"); ClientResponse nextResponse = mock(ClientResponse.class); when(nextResponse.getStatus()).thenReturn(Response.Status.OK.getStatusCode()); String activeStatus = "{\"Status\":\"ACTIVE\"}"; when(response.getEntity(String.class)).thenReturn(activeStatus); when(response.getLength()).thenReturn(activeStatus.length()); when(builder.method(AtlasClient.API.STATUS.getMethod(), ClientResponse.class, null)). thenReturn(response).thenReturn(response).thenReturn(nextResponse); AtlasClient atlasClient = new AtlasClient(service, configuration); String serviceURL = atlasClient.determineActiveServiceURL( new String[] {"http: client); assertEquals(serviceURL, "http: }
@Test public void shouldRetryIfCannotConnectToServiceInitially() { setupRetryParams(); when(client.resource(UriBuilder.fromUri("http: WebResource.Builder builder = setupBuilder(AtlasClient.API.STATUS, service); ClientResponse response = mock(ClientResponse.class); when(response.getStatus()).thenReturn(Response.Status.OK.getStatusCode()); when(response.getEntity(String.class)).thenReturn("{\"Status\":\"BECOMING_ACTIVE\"}"); ClientResponse nextResponse = mock(ClientResponse.class); when(nextResponse.getStatus()).thenReturn(Response.Status.OK.getStatusCode()); String activeStatus = "{\"Status\":\"ACTIVE\"}"; when(response.getEntity(String.class)).thenReturn(activeStatus); when(response.getLength()).thenReturn(activeStatus.length()); when(builder.method(AtlasClient.API.STATUS.getMethod(), ClientResponse.class, null)). thenThrow(new ClientHandlerException("Simulating connection exception")). thenReturn(response). thenReturn(nextResponse); AtlasClient atlasClient = new AtlasClient(service, configuration); atlasClient.setService(service); atlasClient.setConfiguration(configuration); String serviceURL = atlasClient.determineActiveServiceURL( new String[] {"http: client); assertEquals(serviceURL, "http: }
@Test(expectedExceptions = IllegalArgumentException.class) public void shouldThrowExceptionIfActiveServerIsNotFound() { setupRetryParams(); when(client.resource(UriBuilder.fromUri("http: WebResource.Builder builder = setupBuilder(AtlasClient.API.STATUS, service); ClientResponse response = mock(ClientResponse.class); when(response.getStatus()).thenReturn(Response.Status.OK.getStatusCode()); when(response.getEntity(String.class)).thenReturn("{\"Status\":\"BECOMING_ACTIVE\"}"); when(builder.method(AtlasClient.API.STATUS.getMethod(), ClientResponse.class, null)). thenThrow(new ClientHandlerException("Simulating connection exception")). thenReturn(response). thenReturn(response); AtlasClient atlasClient = new AtlasClient(service, configuration); String serviceURL = atlasClient.determineActiveServiceURL( new String[] {"http: client); assertNull(serviceURL); }