Search in sources :

Example 1 with Criticality

use of org.finos.waltz.model.Criticality in project waltz by khartec.

the class PhysicalFlowUploadService method validateCommand.

// //////////////////// PRIVATE //////////////////////
// ///////////////////////////////////////////////////
private PhysicalFlowUploadCommandResponse validateCommand(Map<String, Actor> actorsByName, Map<String, Application> applicationsByAssetCode, Map<String, DataType> dataTypeMap, Aliases<TransportKindValue> transportAliases, PhysicalFlowUploadCommand cmd) {
    checkNotNull(cmd, "cmd cannot be null");
    Map<String, String> errors = new HashMap<>();
    // resolve entity refs - source, target, owner
    EntityReference source = getNodeRefByString(actorsByName, applicationsByAssetCode, cmd.source());
    EntityReference target = getNodeRefByString(actorsByName, applicationsByAssetCode, cmd.target());
    EntityReference owner = getNodeRefByString(actorsByName, applicationsByAssetCode, cmd.owner());
    EntityReference dataType = getDataTypeByString(dataTypeMap, cmd.dataType());
    if (source == null) {
        errors.put("source", String.format("%s not found", cmd.source()));
    }
    if (target == null) {
        errors.put("target", String.format("%s not found", cmd.target()));
    }
    if (owner == null) {
        errors.put("owner", String.format("%s not found", cmd.owner()));
    }
    if (dataType == null) {
        errors.put("dataType", String.format("%s not found", cmd.dataType()));
    }
    // resolve enums - format, frequency, transport, criticality
    DataFormatKind format = DataFormatKind.parse(cmd.format(), (s) -> null);
    if (format == null) {
        errors.put("format", String.format("%s is not a recognised value", cmd.format()));
    }
    FrequencyKind frequency = FrequencyKind.parse(cmd.frequency(), (s) -> null);
    if (frequency == null) {
        errors.put("frequency", String.format("%s is not a recognised value", cmd.frequency()));
    }
    TransportKindValue transport = transportAliases.lookup(cmd.transport()).orElseGet(() -> {
        errors.put("transport", String.format("%s is not a recognised value", cmd.transport()));
        return null;
    });
    Criticality criticality = Criticality.parse(cmd.criticality(), (s) -> null);
    if (criticality == null) {
        errors.put("criticality", String.format("%s is not a recognised value", cmd.criticality()));
    }
    // check for nulls or duplicates in other fields
    if (isEmpty(cmd.name())) {
        errors.put("name", "name not provided");
    }
    Integer basisOffset = parseBasisOffset(cmd.basisOffset());
    if (basisOffset == null) {
        errors.put("basisOffset", String.format("%s is not a recognised value, expect this to be a number", cmd.basisOffset()));
    }
    ImmutablePhysicalFlowParsed parsedFlow = ImmutablePhysicalFlowParsed.builder().source(source).target(target).owner(owner).name(cmd.name()).format(format).specDescription(cmd.specDescription()).specExternalId(cmd.specExternalId()).frequency(frequency).transport(transport).criticality(criticality).description(cmd.description()).externalId(cmd.externalId()).basisOffset(basisOffset).dataType(dataType).build();
    return ImmutablePhysicalFlowUploadCommandResponse.builder().parsedFlow(parsedFlow).errors(errors).originalCommand(cmd).outcome(errors.size() > 0 ? CommandOutcome.FAILURE : CommandOutcome.SUCCESS).build();
}
Also used : HashMap(java.util.HashMap) DataFormatKind(org.finos.waltz.model.physical_specification.DataFormatKind) EntityReference(org.finos.waltz.model.EntityReference) Criticality(org.finos.waltz.model.Criticality)

Example 2 with Criticality

use of org.finos.waltz.model.Criticality in project waltz by khartec.

the class ChangeUnitGenerator method mkAttributeChanges.

private List<AttributeChangeRecord> mkAttributeChanges(DSLContext dsl, List<PhysicalFlow> physicalFlows) {
    List<ChangeUnit> modifyCUs = dsl.selectFrom(CHANGE_UNIT).where(CHANGE_UNIT.ACTION.eq(ChangeAction.MODIFY.name())).fetch(ChangeUnitDao.TO_DOMAIN_MAPPER);
    List<String> attributes = ListUtilities.asList("criticality", "frequency", "DataType");
    Map<Long, PhysicalFlow> flowsById = MapUtilities.indexBy(f -> f.id().get(), physicalFlows);
    List<AttributeChangeRecord> attributeChanges = modifyCUs.stream().flatMap(cu -> randomlySizedIntStream(1, 2).mapToObj(idx -> randomPick(attributes)).map(attribute -> {
        PhysicalFlow flow = flowsById.get(cu.subjectEntity().id());
        switch(attribute) {
            case "criticality":
                return mkCriticalityChange(dsl, cu, flow, attribute);
            case "frequency":
                return mkFrequencyChange(dsl, cu, flow, attribute);
            case "DataType":
                return mkDataTypeChange(dsl, cu, flow, attribute);
            default:
                throw new UnsupportedOperationException("Attribute change not supported: " + attribute);
        }
    })).collect(toList());
    return attributeChanges;
}
Also used : ChangeUnit(org.finos.waltz.model.change_unit.ChangeUnit) ChangeUnitRecord(org.finos.waltz.schema.tables.records.ChangeUnitRecord) Tables(org.finos.waltz.schema.Tables) EntityKind(org.finos.waltz.model.EntityKind) LocalDateTime(java.time.LocalDateTime) PhysicalFlowDao(org.finos.waltz.data.physical_flow.PhysicalFlowDao) PhysicalFlow(org.finos.waltz.model.physical_flow.PhysicalFlow) DataType(org.finos.waltz.model.datatype.DataType) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Map(java.util.Map) StringUtilities.joinUsing(org.finos.waltz.common.StringUtilities.joinUsing) CHANGE_SET(org.finos.waltz.schema.tables.ChangeSet.CHANGE_SET) DSLContext(org.jooq.DSLContext) ChangeUnitDao(org.finos.waltz.data.change_unit.ChangeUnitDao) AttributeChangeRecord(org.finos.waltz.schema.tables.records.AttributeChangeRecord) StringUtilities(org.finos.waltz.common.StringUtilities) EntityLifecycleStatus(org.finos.waltz.model.EntityLifecycleStatus) MapUtilities(org.finos.waltz.common.MapUtilities) Criticality(org.finos.waltz.model.Criticality) Timestamp(java.sql.Timestamp) ExecutionStatus(org.finos.waltz.model.change_unit.ExecutionStatus) CHANGE_UNIT(org.finos.waltz.schema.tables.ChangeUnit.CHANGE_UNIT) ApplicationContext(org.springframework.context.ApplicationContext) RandomUtilities(org.finos.waltz.common.RandomUtilities) List(java.util.List) Collectors.toList(java.util.stream.Collectors.toList) FrequencyKind(org.finos.waltz.model.physical_flow.FrequencyKind) DateTimeUtilities(org.finos.waltz.common.DateTimeUtilities) ListUtilities(org.finos.waltz.common.ListUtilities) ChangeAction(org.finos.waltz.model.change_unit.ChangeAction) DataTypeDao(org.finos.waltz.data.data_type.DataTypeDao) AttributeChangeRecord(org.finos.waltz.schema.tables.records.AttributeChangeRecord) ChangeUnit(org.finos.waltz.model.change_unit.ChangeUnit) PhysicalFlow(org.finos.waltz.model.physical_flow.PhysicalFlow)

Example 3 with Criticality

use of org.finos.waltz.model.Criticality in project waltz by khartec.

the class PhysicalFlowParticipantGenerator method create.

@Override
public Map<String, Integer> create(ApplicationContext ctx) {
    DSLContext dsl = getDsl(ctx);
    log("---creating demo records");
    Map<Criticality, Integer> criticalityCompletionProbabilities = newHashMap(Criticality.VERY_HIGH, 80, Criticality.HIGH, 70, Criticality.MEDIUM, 50, Criticality.LOW, 30, Criticality.NONE, 10, Criticality.UNKNOWN, 10);
    Map<Long, List<Long>> serverIdsByAppId = dsl.select(SERVER_USAGE.ENTITY_ID, SERVER_USAGE.SERVER_ID).from(SERVER_USAGE).where(SERVER_USAGE.ENTITY_KIND.eq(EntityKind.APPLICATION.name())).fetch().intoGroups(SERVER_USAGE.ENTITY_ID, SERVER_USAGE.SERVER_ID);
    Collection<Long> allServerIds = SetUtilities.unionAll(serverIdsByAppId.values());
    List<PhysicalFlowParticipantRecord> records = dsl.select(PHYSICAL_FLOW.ID, PHYSICAL_FLOW.CRITICALITY, LOGICAL_FLOW.SOURCE_ENTITY_ID, LOGICAL_FLOW.TARGET_ENTITY_ID).from(PHYSICAL_FLOW).innerJoin(LOGICAL_FLOW).on(LOGICAL_FLOW.ID.eq(PHYSICAL_FLOW.LOGICAL_FLOW_ID)).where(PHYSICAL_FLOW.IS_REMOVED.isFalse()).and(LOGICAL_FLOW.ENTITY_LIFECYCLE_STATUS.ne(EntityLifecycleStatus.REMOVED.name())).fetch().stream().map(r -> tuple(r.get(PHYSICAL_FLOW.ID), Criticality.parse(r.get(PHYSICAL_FLOW.CRITICALITY), x -> Criticality.UNKNOWN), r.get(LOGICAL_FLOW.SOURCE_ENTITY_ID), r.get(LOGICAL_FLOW.TARGET_ENTITY_ID))).filter(// filter based on criticality probability
    t -> criticalityCompletionProbabilities.get(t.v2) > rnd.nextInt(100)).flatMap(t -> // flat map to tuples of (flow_id, source_id/target_id, server_ids, p_kind)
    Stream.of(tuple(t.v1, t.v3, serverIdsByAppId.getOrDefault(t.v3, emptyList()), ParticipationKind.SOURCE), tuple(t.v1, t.v4, serverIdsByAppId.getOrDefault(t.v4, emptyList()), ParticipationKind.TARGET))).filter(// no servers therefore filter
    t -> !t.v3.isEmpty()).filter(// even if we have servers some may not be mapped
    t -> rnd.nextInt(100) < 80).map(t -> t.map3(associatedServerIds -> randomPick(rnd.nextInt(100) < 90 ? // most of the time we'll go with associated servers
    associatedServerIds : // ... but occasionally we'll go with anything to simulate messy data
    allServerIds))).map(t -> {
        PhysicalFlowParticipantRecord r = new PhysicalFlowParticipantRecord();
        r.setPhysicalFlowId(t.v1);
        r.setParticipantEntityId(t.v3);
        r.setParticipantEntityKind(EntityKind.SERVER.name());
        r.setKind(t.v4.name());
        r.setDescription("Test data");
        r.setLastUpdatedAt(nowUtcTimestamp());
        r.setLastUpdatedBy("admin");
        r.setProvenance(SAMPLE_DATA_PROVENANCE);
        return r;
    }).collect(toList());
    log("About to insert %d records", records.size());
    int[] rcs = dsl.batchInsert(records).execute();
    log("Inserted %d records", rcs.length);
    return null;
}
Also used : PHYSICAL_FLOW_PARTICIPANT(org.finos.waltz.schema.tables.PhysicalFlowParticipant.PHYSICAL_FLOW_PARTICIPANT) Criticality(org.finos.waltz.model.Criticality) Collections.emptyList(java.util.Collections.emptyList) EntityKind(org.finos.waltz.model.EntityKind) Collection(java.util.Collection) Random(java.util.Random) MapUtilities.newHashMap(org.finos.waltz.common.MapUtilities.newHashMap) ApplicationContext(org.springframework.context.ApplicationContext) PHYSICAL_FLOW(org.finos.waltz.schema.tables.PhysicalFlow.PHYSICAL_FLOW) RandomUtilities(org.finos.waltz.common.RandomUtilities) LOGICAL_FLOW(org.finos.waltz.schema.tables.LogicalFlow.LOGICAL_FLOW) List(java.util.List) Collectors.toList(java.util.stream.Collectors.toList) DateTimeUtilities.nowUtcTimestamp(org.finos.waltz.common.DateTimeUtilities.nowUtcTimestamp) SERVER_USAGE(org.finos.waltz.schema.tables.ServerUsage.SERVER_USAGE) Stream(java.util.stream.Stream) Tuple.tuple(org.jooq.lambda.tuple.Tuple.tuple) Map(java.util.Map) RandomUtilities.randomPick(org.finos.waltz.common.RandomUtilities.randomPick) SetUtilities(org.finos.waltz.common.SetUtilities) DSLContext(org.jooq.DSLContext) PhysicalFlowParticipantRecord(org.finos.waltz.schema.tables.records.PhysicalFlowParticipantRecord) ParticipationKind(org.finos.waltz.model.physical_flow_participant.ParticipationKind) EntityLifecycleStatus(org.finos.waltz.model.EntityLifecycleStatus) PhysicalFlowParticipantRecord(org.finos.waltz.schema.tables.records.PhysicalFlowParticipantRecord) DSLContext(org.jooq.DSLContext) Collections.emptyList(java.util.Collections.emptyList) List(java.util.List) Collectors.toList(java.util.stream.Collectors.toList) Criticality(org.finos.waltz.model.Criticality)

Example 4 with Criticality

use of org.finos.waltz.model.Criticality in project waltz by khartec.

the class AppGenerator method create.

@Override
public Map<String, Integer> create(ApplicationContext ctx) {
    DSLContext dsl = getDsl(ctx);
    ApplicationService applicationDao = ctx.getBean(ApplicationService.class);
    OrganisationalUnitService ouDao = ctx.getBean(OrganisationalUnitService.class);
    List<String> animals = Unchecked.supplier(() -> readLines(getClass().getResourceAsStream("/app-names.txt"))).get();
    OrganisationalUnit[] organisationalUnits = ouDao.findAll().toArray(new OrganisationalUnit[0]);
    List<AppRegistrationRequest> registrationRequests = new ArrayList<>();
    for (int i = 0; i < NUM_APPS; i++) {
        String animal = randomPick(animals.toArray(new String[0])) + " - " + i;
        OrganisationalUnit organisationalUnit = randomPick(organisationalUnits);
        LifecyclePhase phase = rnd.nextInt(10) > 7 ? randomPick(LifecyclePhase.values()) : LifecyclePhase.PRODUCTION;
        Criticality businessCriticality = rnd.nextInt(10) > 7 ? randomPick(Criticality.values()) : Criticality.HIGH;
        AppRegistrationRequest app = ImmutableAppRegistrationRequest.builder().name(animal).assetCode("wltz-0" + i).description("All about " + animal).applicationKind(randomPick(ApplicationKind.values())).lifecyclePhase(phase).overallRating(randomPick(RagRating.R, RagRating.A, RagRating.A, RagRating.G, RagRating.G)).organisationalUnitId(organisationalUnit.id().get()).businessCriticality(businessCriticality).build();
        registrationRequests.add(app);
    }
    registrationRequests.forEach(a -> applicationDao.registerApp(a, "admin"));
    return null;
}
Also used : OrganisationalUnitService(org.finos.waltz.service.orgunit.OrganisationalUnitService) ArrayList(java.util.ArrayList) DSLContext(org.jooq.DSLContext) OrganisationalUnit(org.finos.waltz.model.orgunit.OrganisationalUnit) LifecyclePhase(org.finos.waltz.model.application.LifecyclePhase) ImmutableAppRegistrationRequest(org.finos.waltz.model.application.ImmutableAppRegistrationRequest) AppRegistrationRequest(org.finos.waltz.model.application.AppRegistrationRequest) ApplicationService(org.finos.waltz.service.application.ApplicationService) Criticality(org.finos.waltz.model.Criticality)

Aggregations

Criticality (org.finos.waltz.model.Criticality)4 DSLContext (org.jooq.DSLContext)3 List (java.util.List)2 Map (java.util.Map)2 Collectors.toList (java.util.stream.Collectors.toList)2 RandomUtilities (org.finos.waltz.common.RandomUtilities)2 EntityKind (org.finos.waltz.model.EntityKind)2 EntityLifecycleStatus (org.finos.waltz.model.EntityLifecycleStatus)2 ApplicationContext (org.springframework.context.ApplicationContext)2 Timestamp (java.sql.Timestamp)1 LocalDateTime (java.time.LocalDateTime)1 ArrayList (java.util.ArrayList)1 Collection (java.util.Collection)1 Collections.emptyList (java.util.Collections.emptyList)1 HashMap (java.util.HashMap)1 Random (java.util.Random)1 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)1 Stream (java.util.stream.Stream)1 DateTimeUtilities (org.finos.waltz.common.DateTimeUtilities)1 DateTimeUtilities.nowUtcTimestamp (org.finos.waltz.common.DateTimeUtilities.nowUtcTimestamp)1