protected void storeEntity(EntityType type, String name, String resource) throws Exception { Unmarshaller unmarshaller = type.getUnmarshaller(); ConfigurationStore store = ConfigurationStore.get(); store.remove(type, name); switch (type) { case CLUSTER: Cluster cluster = (Cluster) unmarshaller.unmarshal(this.getClass().getResource(resource)); cluster.setName(name); store.publish(type, cluster); break; case FEED: Feed feed = (Feed) unmarshaller.unmarshal(this.getClass().getResource(resource)); feed.setName(name); store.publish(type, feed); break; case PROCESS: Process process = (Process) unmarshaller.unmarshal(this.getClass().getResource(resource)); process.setName(name); store.publish(type, process); break; default: } }
@Test(dataProvider = "state_and_events") public void testIdempotency(EntityState.STATE state, EntityState.EVENT event) throws Exception { Process mockEntity = new Process(); mockEntity.setName("test"); storeEntity(EntityType.PROCESS, "test"); EntityState entityState = new EntityState(mockEntity).setCurrentState(state); entityState.nextTransition(event); Assert.assertEquals(entityState.getCurrentState(), state); }
protected Entity storeEntity(EntityType type, String name, String resource, String writeEndpoint) throws Exception { Unmarshaller unmarshaller = type.getUnmarshaller(); ConfigurationStore store = ConfigurationStore.get(); switch (type) { case CLUSTER: Cluster cluster = (Cluster) unmarshaller.unmarshal(this.getClass().getResource(resource)); if (name != null) { store.remove(type, name); cluster.setName(name); } store.publish(type, cluster); if (writeEndpoint != null) { ClusterHelper.getInterface(cluster, Interfacetype.WRITE).setEndpoint(writeEndpoint); FileSystem fs = new Path(writeEndpoint).getFileSystem(EmbeddedCluster.newConfiguration()); fs.create( new Path( ClusterHelper.getLocation(cluster, ClusterLocationType.WORKING).getPath(), "libext/FEED/retention/ext.jar")) .close(); fs.create( new Path( ClusterHelper.getLocation(cluster, ClusterLocationType.WORKING).getPath(), "libext/FEED/replication/ext.jar")) .close(); } return cluster; case FEED: Feed feed = (Feed) unmarshaller.unmarshal(this.getClass().getResource(resource)); if (name != null) { store.remove(type, name); feed.setName(name); } store.publish(type, feed); return feed; case PROCESS: Process process = (Process) unmarshaller.unmarshal(this.getClass().getResource(resource)); if (name != null) { store.remove(type, name); process.setName(name); } store.publish(type, process); return process; default: } throw new IllegalArgumentException("Unhandled type: " + type); }
private Entity buildProcess(String name, String username, String tags, String pipelines) { ACL acl = new ACL(); acl.setOwner(username); acl.setGroup("hdfs"); acl.setPermission("*"); Process process = new Process(); process.setName(name); process.setACL(acl); if (!StringUtils.isEmpty(pipelines)) { process.setPipelines(pipelines); } if (!StringUtils.isEmpty(tags)) { process.setTags(tags); } process.setClusters(buildClusters("cluster" + name)); return process; }
// Tests a schedulable entity's lifecycle : Submit -> run -> suspend -> resume @Test public void testLifeCycle() throws Exception { Process mockEntity = new Process(); mockEntity.setName("test"); storeEntity(EntityType.PROCESS, "test"); StateService.get().handleStateChange(mockEntity, EntityState.EVENT.SUBMIT, listener); EntityState entityFromStore = AbstractStateStore.get().getAllEntities().iterator().next(); Mockito.verify(listener).onSubmit(mockEntity); Assert.assertTrue(entityFromStore.getCurrentState().equals(EntityState.STATE.SUBMITTED)); StateService.get().handleStateChange(mockEntity, EntityState.EVENT.SCHEDULE, listener); Mockito.verify(listener).onSchedule(mockEntity); entityFromStore = AbstractStateStore.get().getAllEntities().iterator().next(); Assert.assertTrue(entityFromStore.getCurrentState().equals(EntityState.STATE.SCHEDULED)); StateService.get().handleStateChange(mockEntity, EntityState.EVENT.SUSPEND, listener); Mockito.verify(listener).onSuspend(mockEntity); entityFromStore = AbstractStateStore.get().getAllEntities().iterator().next(); Assert.assertTrue(entityFromStore.getCurrentState().equals(EntityState.STATE.SUSPENDED)); StateService.get().handleStateChange(mockEntity, EntityState.EVENT.RESUME, listener); Mockito.verify(listener).onResume(mockEntity); entityFromStore = AbstractStateStore.get().getAllEntities().iterator().next(); Assert.assertTrue(entityFromStore.getCurrentState().equals(EntityState.STATE.SCHEDULED)); }
private static org.apache.falcon.entity.v0.process.Process bindAttributesInTemplate( final String processTemplate, final Properties extensionProperties, final String extensionName, final String wfPath, final String wfLibPath) throws FalconException { if (StringUtils.isBlank(processTemplate) || extensionProperties == null) { throw new FalconException("Process template or properties cannot be null"); } org.apache.falcon.entity.v0.process.Process process; try { Unmarshaller unmarshaller = EntityType.PROCESS.getUnmarshaller(); // Validation can be skipped for unmarshalling as we want to bind template with the // properties. // Vaildation is handled as part of marshalling unmarshaller.setSchema(null); unmarshaller.setEventHandler( new ValidationEventHandler() { public boolean handleEvent(ValidationEvent validationEvent) { return true; } }); process = (org.apache.falcon.entity.v0.process.Process) unmarshaller.unmarshal(new StringReader(processTemplate)); } catch (Exception e) { throw new FalconException(e); } /* For optional properties user might directly set them in the process xml and might not set it in properties file. Before doing the submission validation is done to confirm process xml doesn't have EXTENSION_VAR_PATTERN */ String processName = extensionProperties.getProperty(ExtensionProperties.JOB_NAME.getName()); if (StringUtils.isNotEmpty(processName)) { process.setName(processName); } // DR process template has only one cluster bindClusterProperties(process.getClusters().getClusters().get(0), extensionProperties); // bind scheduling properties String processFrequency = extensionProperties.getProperty(ExtensionProperties.FREQUENCY.getName()); if (StringUtils.isNotEmpty(processFrequency)) { process.setFrequency(Frequency.fromString(processFrequency)); } String zone = extensionProperties.getProperty(ExtensionProperties.TIMEZONE.getName()); if (StringUtils.isNotBlank(zone)) { process.setTimezone(TimeZone.getTimeZone(zone)); } else { process.setTimezone(TimeZone.getTimeZone("UTC")); } bindWorkflowProperties(process.getWorkflow(), extensionName, wfPath, wfLibPath); bindRetryProperties(process.getRetry(), extensionProperties); bindNotificationProperties(process.getNotification(), extensionProperties); bindACLProperties(process.getACL(), extensionProperties); bindTagsProperties(process, extensionProperties); bindCustomProperties(process.getProperties(), extensionProperties); return process; }